// Deterministic mock data for the design-system showcase (Kenyan pharmacy, amounts in KES).
// Everything derives from a seeded PRNG and a fixed "today", so server and client render
// identical output (no hydration mismatch) and nothing changes between builds.

export const TODAY = "2026-10-20";

function mulberry32(seed: number) {
  let a = seed >>> 0;
  return () => {
    a = (a + 0x6d2b79f5) >>> 0;
    let t = a;
    t = Math.imul(t ^ (t >>> 15), t | 1);
    t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
    return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
  };
}
const rand = mulberry32(20261020);
const int = (min: number, max: number) => Math.floor(rand() * (max - min + 1)) + min;
const pick = <T,>(xs: readonly T[]): T => xs[Math.floor(rand() * xs.length)];

// ---- formatting ------------------------------------------------------------

// The helpers live in lib/format.ts (no demo data, safe for live pages); re-exported here for the demos.
import { addDays, daysBetween, stockStatus, type StockStatus } from "./format";
export { addDays, daysBetween, formatDate, formatKES, initials, localToday, stockStatus, type StockStatus } from "./format";

// ---- branches and staff ----------------------------------------------------

export type Branch = { id: number; name: string; town: string };
export const branches: Branch[] = [
  { id: 1, name: "Westlands Main", town: "Nairobi" },
  { id: 2, name: "Kilimani", town: "Nairobi" },
  { id: 3, name: "Nyali", town: "Mombasa" },
  { id: 4, name: "Milimani", town: "Kisumu" },
];

export type Role = "Admin" | "Pharmacist" | "Cashier";
export type StaffUser = {
  id: number;
  name: string;
  email: string;
  phone: string;
  role: Role;
  branchId: number;
  status: "Active" | "Invited" | "Suspended";
  lastActive: string;
};
export const staff: StaffUser[] = [
  { id: 1, name: "Wanjiru Kamau", email: "wanjiru.kamau@medora.example", phone: "0712 345 678", role: "Admin", branchId: 1, status: "Active", lastActive: "2026-10-20" },
  { id: 2, name: "Brian Otieno", email: "brian.otieno@medora.example", phone: "0723 456 789", role: "Pharmacist", branchId: 1, status: "Active", lastActive: "2026-10-20" },
  { id: 3, name: "Achieng Odhiambo", email: "achieng.odhiambo@medora.example", phone: "0734 567 890", role: "Pharmacist", branchId: 2, status: "Active", lastActive: "2026-10-19" },
  { id: 4, name: "Kevin Mutua", email: "kevin.mutua@medora.example", phone: "0745 678 901", role: "Cashier", branchId: 1, status: "Active", lastActive: "2026-10-20" },
  { id: 5, name: "Fatuma Hassan", email: "fatuma.hassan@medora.example", phone: "0756 789 012", role: "Cashier", branchId: 3, status: "Active", lastActive: "2026-10-20" },
  { id: 6, name: "Peter Njoroge", email: "peter.njoroge@medora.example", phone: "0767 890 123", role: "Cashier", branchId: 2, status: "Suspended", lastActive: "2026-09-30" },
  { id: 7, name: "Mercy Chebet", email: "mercy.chebet@medora.example", phone: "0778 901 234", role: "Pharmacist", branchId: 4, status: "Invited", lastActive: "2026-10-18" },
];

export const currentUser = staff[1];

// ---- suppliers -------------------------------------------------------------

export type Supplier = { id: number; name: string; contact: string; phone: string; town: string; balanceOwed: number; leadDays: number };
export const suppliers: Supplier[] = [
  { id: 1, name: "Kenya Medical Supplies Authority", contact: "Samuel Kiprop", phone: "0711 220 330", town: "Nairobi", balanceOwed: 184500, leadDays: 5 },
  { id: 2, name: "Mission for Essential Drugs", contact: "Grace Wambui", phone: "0722 331 441", town: "Nairobi", balanceOwed: 92300, leadDays: 4 },
  { id: 3, name: "Dawa Distributors Ltd", contact: "Joseph Maina", phone: "0733 442 552", town: "Thika", balanceOwed: 0, leadDays: 2 },
  { id: 4, name: "Cosmos Pharmaceuticals", contact: "Anita Shah", phone: "0744 553 663", town: "Nairobi", balanceOwed: 47800, leadDays: 3 },
  { id: 5, name: "Lords Healthcare", contact: "Daniel Mwangi", phone: "0755 664 774", town: "Mombasa", balanceOwed: 126900, leadDays: 6 },
  { id: 6, name: "Universal Corporation", contact: "Esther Njeri", phone: "0766 775 885", town: "Kikuyu", balanceOwed: 0, leadDays: 3 },
];

// ---- products and batches --------------------------------------------------

export type Category = "Analgesics" | "Antibiotics" | "Antidiabetics" | "Cardiovascular" | "Antimalarials" | "Respiratory" | "Gastro-intestinal" | "Vitamins" | "Dermatology" | "Consumables";

export type Product = {
  id: number;
  name: string;
  generic: string;
  strength: string;
  form: string;
  category: Category;
  barcode: string;
  costPrice: number;
  price: number;
  stock: number;
  minStock: number;
  requiresRx: boolean;
  supplierId: number;
  shelf: string;
  type: "Product" | "Service";
};

type Seed = [name: string, generic: string, strength: string, form: string, category: Category, cost: number, price: number, rx: boolean];

const productSeeds: Seed[] = [
  ["Panadol", "Paracetamol", "500 mg", "Tablet", "Analgesics", 3, 5, false],
  ["Brufen", "Ibuprofen", "400 mg", "Tablet", "Analgesics", 6, 10, false],
  ["Diclofenac Sodium", "Diclofenac", "50 mg", "Tablet", "Analgesics", 4, 8, false],
  ["Tramadol", "Tramadol", "50 mg", "Capsule", "Analgesics", 12, 20, true],
  ["Amoxil", "Amoxicillin", "500 mg", "Capsule", "Antibiotics", 9, 15, true],
  ["Augmentin", "Amoxicillin / Clavulanate", "625 mg", "Tablet", "Antibiotics", 55, 85, true],
  ["Azithromycin", "Azithromycin", "500 mg", "Tablet", "Antibiotics", 70, 120, true],
  ["Ciprofloxacin", "Ciprofloxacin", "500 mg", "Tablet", "Antibiotics", 14, 25, true],
  ["Metronidazole", "Metronidazole", "400 mg", "Tablet", "Antibiotics", 3, 6, true],
  ["Glucophage", "Metformin", "500 mg", "Tablet", "Antidiabetics", 5, 9, true],
  ["Glibenclamide", "Glibenclamide", "5 mg", "Tablet", "Antidiabetics", 4, 7, true],
  ["Lantus SoloStar", "Insulin glargine", "100 IU/ml", "Pen 3 ml", "Antidiabetics", 1850, 2400, true],
  ["Norvasc", "Amlodipine", "5 mg", "Tablet", "Cardiovascular", 6, 12, true],
  ["Lipitor", "Atorvastatin", "20 mg", "Tablet", "Cardiovascular", 18, 32, true],
  ["Losartan", "Losartan potassium", "50 mg", "Tablet", "Cardiovascular", 9, 16, true],
  ["Atenolol", "Atenolol", "50 mg", "Tablet", "Cardiovascular", 4, 8, true],
  ["Coartem", "Artemether / Lumefantrine", "20/120 mg", "Tablet (24)", "Antimalarials", 180, 260, true],
  ["Malarone", "Atovaquone / Proguanil", "250/100 mg", "Tablet", "Antimalarials", 95, 150, true],
  ["Ventolin Inhaler", "Salbutamol", "100 mcg", "Inhaler", "Respiratory", 420, 580, true],
  ["Piriton", "Chlorpheniramine", "4 mg", "Tablet", "Respiratory", 1, 3, false],
  ["Benylin Cough Syrup", "Diphenhydramine", "100 ml", "Syrup", "Respiratory", 210, 320, false],
  ["Loratadine", "Loratadine", "10 mg", "Tablet", "Respiratory", 5, 10, false],
  ["Omeprazole", "Omeprazole", "20 mg", "Capsule", "Gastro-intestinal", 6, 12, false],
  ["ORS Sachets", "Oral rehydration salts", "20.5 g", "Sachet", "Gastro-intestinal", 25, 40, false],
  ["Buscopan", "Hyoscine butylbromide", "10 mg", "Tablet", "Gastro-intestinal", 11, 20, false],
  ["Vitamin C", "Ascorbic acid", "500 mg", "Tablet", "Vitamins", 4, 8, false],
  ["Folic Acid", "Folic acid", "5 mg", "Tablet", "Vitamins", 2, 4, false],
  ["Zinc Sulphate", "Zinc", "20 mg", "Dispersible tablet", "Vitamins", 5, 10, false],
  ["Betamethasone Cream", "Betamethasone", "0.1% 15 g", "Cream", "Dermatology", 130, 210, true],
  ["Clotrimazole Cream", "Clotrimazole", "1% 20 g", "Cream", "Dermatology", 90, 150, false],
  ["Surgical Gloves", "Latex gloves", "Box of 100", "Box", "Consumables", 650, 900, false],
  ["Digital Thermometer", "Thermometer", "Each", "Device", "Consumables", 280, 450, false],
  ["Plasters", "Adhesive strips", "Pack of 20", "Pack", "Consumables", 40, 70, false],
  ["Cetirizine", "Cetirizine", "10 mg", "Tablet", "Respiratory", 4, 9, false],
  ["Doxycycline", "Doxycycline", "100 mg", "Capsule", "Antibiotics", 7, 13, true],
  ["Salbutamol Syrup", "Salbutamol", "2 mg/5 ml", "Syrup", "Respiratory", 120, 190, true],
  ["Enalapril", "Enalapril", "10 mg", "Tablet", "Cardiovascular", 5, 10, true],
  ["Pioglitazone", "Pioglitazone", "30 mg", "Tablet", "Antidiabetics", 16, 28, true],
  ["Multivitamin Syrup", "Multivitamin", "200 ml", "Syrup", "Vitamins", 260, 380, false],
  ["Quinine", "Quinine sulphate", "300 mg", "Tablet", "Antimalarials", 12, 20, true],
  ["Medical Consultation", "Pharmacist consultation", "Per visit", "Service", "Consumables", 0, 500, false],
  ["Blood Pressure Check", "BP screening", "Per visit", "Service", "Consumables", 0, 150, false],
];

export const products: Product[] = productSeeds.map(([name, generic, strength, form, category, cost, price, rx], i) => {
  const isService = form === "Service";
  const cheap = price < 30;
  const minStock = isService ? 0 : cheap ? 200 : price < 400 ? 40 : 10;
  // Roughly one in six sits at or under its reorder level, a few are out entirely.
  const low = i % 6 === 2;
  const out = i % 17 === 5;
  const base = cheap ? int(300, 1400) : price < 400 ? int(60, 240) : int(12, 60);
  const stock = isService ? 0 : out ? 0 : low ? Math.max(1, Math.floor(minStock * (0.2 + rand() * 0.7))) : base;
  return {
    id: i + 1,
    name,
    generic,
    strength,
    form,
    category,
    barcode: isService ? "" : String(6161100000000 + (i + 1) * 137),
    costPrice: cost,
    price,
    stock,
    minStock,
    requiresRx: rx,
    supplierId: suppliers[i % suppliers.length].id,
    shelf: isService ? "" : `${String.fromCharCode(65 + (i % 6))}${(i % 5) + 1}`,
    type: isService ? "Service" : "Product",
  };
});

export type Batch = { id: number; productId: number; batchNo: string; expiryDate: string; received: string; quantity: number; stock: number; costPrice: number };

export const batches: Batch[] = (() => {
  const out: Batch[] = [];
  let id = 1;
  for (const p of products) {
    if (p.type === "Service") continue;
    const count = p.stock === 0 ? 1 : int(1, 3);
    let remaining = p.stock;
    for (let b = 0; b < count; b++) {
      const last = b === count - 1;
      const qty = p.stock === 0 ? int(50, 200) : last ? remaining : Math.max(1, Math.floor(remaining * (0.3 + rand() * 0.3)));
      remaining -= p.stock === 0 ? 0 : qty;
      // Expiry spread: a handful inside 90 days, most 6-30 months away, a couple already expired.
      const offsetBucket = (p.id * 7 + b * 3) % 11;
      const expiryOffset = offsetBucket === 0 ? -int(5, 40) : offsetBucket <= 2 ? int(8, 85) : int(150, 900);
      out.push({
        id: id++,
        productId: p.id,
        batchNo: `${p.name.slice(0, 2).toUpperCase()}${String(24 + (b % 3))}${String(int(100, 999))}`,
        expiryDate: addDays(TODAY, expiryOffset),
        received: addDays(TODAY, -int(20, 300)),
        quantity: qty + int(0, 150),
        stock: p.stock === 0 ? 0 : qty,
        costPrice: Math.max(0, +(p.costPrice * (0.92 + rand() * 0.16)).toFixed(2)),
      });
    }
  }
  return out;
})();


export const lowStock = products.filter((p) => p.type === "Product" && p.stock <= p.minStock).sort((a, b) => a.stock / (a.minStock || 1) - b.stock / (b.minStock || 1));

export type ExpiringBatch = Batch & { productName: string; daysLeft: number };
export const expiring: ExpiringBatch[] = batches
  .filter((b) => b.stock > 0)
  .map((b) => ({ ...b, productName: products.find((p) => p.id === b.productId)!.name, daysLeft: daysBetween(TODAY, b.expiryDate) }))
  .filter((b) => b.daysLeft <= 90)
  .sort((a, b) => a.daysLeft - b.daysLeft);

export const stockValue = batches.reduce((sum, b) => sum + b.stock * b.costPrice, 0);

// ---- customers -------------------------------------------------------------

export type Customer = { id: number; name: string; phone: string; email: string; creditLimit: number; balance: number; lastVisit: string; totalSpend: number; visits: number };
const customerNames = [
  "Mary Wambui", "John Kariuki", "Ann Akinyi", "Samuel Kipchoge", "Esther Nyambura", "David Ochieng", "Lucy Wairimu", "Hassan Abdi",
  "Joyce Moraa", "Moses Kimani", "Catherine Atieno", "Isaac Mwenda", "Ruth Chepkoech", "Paul Omondi", "Nancy Njeri", "Daniel Kiprotich",
  "Rose Adhiambo", "Francis Maina", "Beatrice Wanjiku", "George Onyango", "Faith Mumbi", "Stephen Kiplagat", "Agnes Nduta", "Patrick Waweru",
];
export const customers: Customer[] = customerNames.map((name, i) => {
  const hasCredit = i % 4 === 1;
  const limit = hasCredit ? pick([5000, 10000, 20000]) : 0;
  const slug = name.toLowerCase().replace(/ /g, ".");
  return {
    id: i + 1,
    name,
    phone: `07${String(10 + (i % 80)).padStart(2, "0")} ${String(100 + i * 13).slice(-3)} ${String(200 + i * 29).slice(-3)}`,
    email: `${slug}@mail.example`,
    creditLimit: limit,
    balance: hasCredit ? Math.round(limit * (0.1 + rand() * 0.7) / 50) * 50 : 0,
    lastVisit: addDays(TODAY, -int(0, 60)),
    totalSpend: int(1800, 96000),
    visits: int(2, 48),
  };
});

// ---- sales -----------------------------------------------------------------

export type DailySales = { date: string; revenue: number; transactions: number; cost: number };
const weekdayFactor = [0.82, 1.0, 1.04, 1.02, 1.1, 1.28, 0.9]; // indexed by getUTCDay: Sun..Sat
export const salesByDay: DailySales[] = Array.from({ length: 30 }, (_, i) => {
  const date = addDays(TODAY, i - 29);
  const dow = new Date(date + "T00:00:00Z").getUTCDay();
  const trend = 1 + i * 0.006;
  const tx = Math.round(78 * weekdayFactor[dow] * trend + int(-9, 9));
  const revenue = Math.round(tx * (1180 + int(-140, 160)) / 10) * 10;
  return { date, revenue, transactions: tx, cost: Math.round(revenue * (0.64 + rand() * 0.04)) };
});

export type HourlySales = { hour: number; label: string; revenue: number; transactions: number };
const hourShape = [0, 0, 0, 0, 0, 0, 0.1, 0.35, 0.8, 1.0, 0.95, 0.85, 0.9, 0.78, 0.7, 0.75, 0.88, 1.12, 1.2, 0.9, 0.55, 0.25, 0.05, 0];
export const salesByHour: HourlySales[] = hourShape.map((f, hour) => {
  const transactions = Math.round(f * 14 + (f > 0 ? int(0, 2) : 0));
  return { hour, label: `${String(hour).padStart(2, "0")}:00`, transactions, revenue: transactions * (1150 + int(-200, 250)) };
});

export type PaymentMethod = "Cash" | "M-Pesa" | "Card" | "Credit";
export type SaleStatus = "Completed" | "Held" | "Refunded";
export type Sale = {
  id: number;
  receipt: string;
  createdAt: string;
  time: string;
  cashierId: number;
  branchId: number;
  customerId: number | null;
  items: number;
  subtotal: number;
  vat: number;
  total: number;
  method: PaymentMethod;
  status: SaleStatus;
};
export const recentSales: Sale[] = Array.from({ length: 40 }, (_, i) => {
  const date = addDays(TODAY, -Math.floor(i / 8));
  const items = int(1, 7);
  const subtotal = Math.round((items * int(90, 520)) / 5) * 5;
  const method = i % 9 === 4 ? "Credit" : pick<PaymentMethod>(["Cash", "M-Pesa", "M-Pesa", "Card", "Cash"]);
  const cashiers = staff.filter((s) => s.role === "Cashier" && s.status === "Active");
  const cashier = cashiers[i % cashiers.length];
  return {
    id: 5200 - i,
    receipt: `RCP-${String(5200 - i).padStart(6, "0")}`,
    createdAt: date,
    time: `${String(8 + ((i * 3) % 12)).padStart(2, "0")}:${String((i * 17) % 60).padStart(2, "0")}`,
    cashierId: cashier.id,
    branchId: cashier.branchId,
    customerId: i % 3 === 0 ? customers[(i * 5) % customers.length].id : null,
    items,
    subtotal,
    vat: 0,
    total: subtotal,
    method,
    status: i % 23 === 7 ? "Refunded" : i % 19 === 3 ? "Held" : "Completed",
  };
});

export type TopProduct = { productId: number; name: string; units: number; revenue: number };
export const topProducts: TopProduct[] = products
  .filter((p) => p.type === "Product")
  .map((p) => {
    const units = Math.round((p.price < 30 ? 900 : p.price < 400 ? 220 : 45) * (0.3 + rand() * 1.1));
    return { productId: p.id, name: p.name, units, revenue: units * p.price };
  })
  .sort((a, b) => b.revenue - a.revenue)
  .slice(0, 8);

export const paymentBreakdown: { method: PaymentMethod; amount: number }[] = (() => {
  const total = salesByDay.reduce((s, d) => s + d.revenue, 0);
  return [
    { method: "M-Pesa" as const, amount: Math.round(total * 0.46) },
    { method: "Cash" as const, amount: Math.round(total * 0.34) },
    { method: "Card" as const, amount: Math.round(total * 0.14) },
    { method: "Credit" as const, amount: total - Math.round(total * 0.46) - Math.round(total * 0.34) - Math.round(total * 0.14) },
  ];
})();

export const categoryRevenue: { category: Category; revenue: number }[] = (() => {
  const totals = new Map<Category, number>();
  for (const t of topProducts) {
    const c = products.find((p) => p.id === t.productId)!.category;
    totals.set(c, (totals.get(c) ?? 0) + t.revenue);
  }
  return [...totals.entries()].map(([category, revenue]) => ({ category, revenue })).sort((a, b) => b.revenue - a.revenue);
})();

export const kpis = (() => {
  const today = salesByDay[salesByDay.length - 1];
  const yesterday = salesByDay[salesByDay.length - 2];
  const week = salesByDay.slice(-7).reduce((s, d) => s + d.revenue, 0);
  const prevWeek = salesByDay.slice(-14, -7).reduce((s, d) => s + d.revenue, 0);
  const month = salesByDay.reduce((s, d) => s + d.revenue, 0);
  const cost = salesByDay.reduce((s, d) => s + d.cost, 0);
  return {
    todayRevenue: today.revenue,
    todayChange: (today.revenue - yesterday.revenue) / yesterday.revenue,
    todayTransactions: today.transactions,
    weekRevenue: week,
    weekChange: (week - prevWeek) / prevWeek,
    monthRevenue: month,
    grossProfit: month - cost,
    grossMargin: (month - cost) / month,
    lowStockCount: lowStock.length,
    expiringCount: expiring.length,
    customersOwing: customers.filter((c) => c.balance > 0).length,
    receivables: customers.reduce((s, c) => s + c.balance, 0),
  };
})();

// ---- prescriptions ---------------------------------------------------------

export type PrescriptionStatus = "Pending" | "Verified" | "Dispensed" | "Partially dispensed" | "Rejected";
export type Prescription = {
  id: number;
  ref: string;
  patient: string;
  prescriber: string;
  facility: string;
  date: string;
  items: { productId: number; dose: string; quantity: number }[];
  status: PrescriptionStatus;
  pharmacistId: number | null;
};
const prescribers = [
  ["Dr. Njeri Karanja", "Aga Khan University Hospital"],
  ["Dr. Omar Salim", "Coast General Hospital"],
  ["Dr. Peter Mwangi", "Kenyatta National Hospital"],
  ["Dr. Linet Cheruiyot", "MP Shah Hospital"],
  ["Dr. Allan Ouma", "Jaramogi Oginga Odinga Hospital"],
];
const statuses: PrescriptionStatus[] = ["Pending", "Verified", "Dispensed", "Dispensed", "Dispensed", "Partially dispensed", "Rejected"];
const rxProducts = products.filter((p) => p.requiresRx && p.type === "Product");
export const prescriptions: Prescription[] = Array.from({ length: 24 }, (_, i) => {
  const [prescriber, facility] = prescribers[i % prescribers.length];
  const status = statuses[i % statuses.length];
  const itemCount = (i % 3) + 1;
  return {
    id: i + 1,
    ref: `RX-${String(9100 + i)}`,
    patient: customers[(i * 3) % customers.length].name,
    prescriber,
    facility,
    date: addDays(TODAY, -Math.floor(i / 2)),
    items: Array.from({ length: itemCount }, (_, k) => {
      const p = rxProducts[(i * 5 + k * 3) % rxProducts.length];
      return { productId: p.id, dose: pick(["1 tablet twice daily", "1 capsule three times daily", "2 tablets at night", "As directed"]), quantity: p.price > 100 ? 1 : int(10, 30) };
    }),
    status,
    pharmacistId: status === "Pending" ? null : staff.filter((s) => s.role === "Pharmacist")[i % 2].id,
  };
});

// ---- activity --------------------------------------------------------------

export type Activity = { id: number; at: string; userId: number; action: string; detail: string };
export const recentActivity: Activity[] = [
  { id: 1, at: "2026-10-20 16:42", userId: 4, action: "Sale completed", detail: "RCP-005200, KES 1,840, M-Pesa" },
  { id: 2, at: "2026-10-20 16:20", userId: 2, action: "Prescription dispensed", detail: "RX-9104, 3 items" },
  { id: 3, at: "2026-10-20 15:55", userId: 1, action: "Stock adjusted", detail: "Panadol, +600 units, reason: delivery" },
  { id: 4, at: "2026-10-20 15:31", userId: 5, action: "Sale completed", detail: "RCP-005198, KES 620, Cash" },
  { id: 5, at: "2026-10-20 14:48", userId: 2, action: "Purchase order received", detail: "PO-0412, Dawa Distributors Ltd" },
  { id: 6, at: "2026-10-20 14:12", userId: 4, action: "Sale held", detail: "RCP-005195, 4 items" },
  { id: 7, at: "2026-10-20 13:40", userId: 1, action: "User invited", detail: "mercy.chebet@medora.example, Pharmacist" },
  { id: 8, at: "2026-10-20 12:05", userId: 3, action: "Refund issued", detail: "RCP-005170, KES 450" },
];

// ---- tables for the data-table examples -------------------------------------

export type InventoryRow = Product & { supplier: string; status: StockStatus; nextExpiry: string | null; stockValue: number };
export const inventoryRows: InventoryRow[] = products
  .filter((p) => p.type === "Product")
  .map((p) => {
    const bs = batches.filter((b) => b.productId === p.id && b.stock > 0).sort((a, b) => (a.expiryDate < b.expiryDate ? -1 : 1));
    return {
      ...p,
      supplier: suppliers.find((s) => s.id === p.supplierId)!.name,
      status: stockStatus(p),
      nextExpiry: bs[0]?.expiryDate ?? null,
      stockValue: bs.reduce((s, b) => s + b.stock * b.costPrice, 0),
    };
  });
