"use client"; import Link from "next/link"; import { StockLevel } from "@/lib/types"; interface Props { levels: StockLevel[]; } /** Current stock per branch at a glance, with anything low or out listed first. */ export default function StockSummaryCard({ levels }: Props) { const totalsByBranch = new Map(); for (const l of levels) { const entry = totalsByBranch.get(l.branchId) ?? { name: l.branchName, units: 0, alerts: 0 }; entry.units += Math.max(l.quantity, 0); if (l.status !== "OK") entry.alerts += 1; totalsByBranch.set(l.branchId, entry); } const alerts = levels.filter((l) => l.status !== "OK").sort((a, b) => a.quantity - b.quantity); return (

Stock on hand

Manage stock
{levels.length === 0 ? (

No stock recorded yet.

) : ( <>
{Array.from(totalsByBranch.entries()).map(([id, b]) => (

{b.name}

{b.units.toLocaleString()} units

{b.alerts > 0 &&

{b.alerts} low/out

}
))}
{alerts.length > 0 && ( )} )}
); }