import { Clock, CheckCircle2, XCircle, AlertTriangle, ShoppingCart } from "lucide-react";

export const STATUS_MAP = {
	pending: { label: "În așteptare", class: "bg-warning", icon: Clock },
	paid: { label: "Plătită", class: "bg-success", icon: CheckCircle2 },
	processing: { label: "În procesare", class: "bg-info", icon: Clock },
	shipped: { label: "Expediată", class: "bg-primary", icon: ShoppingCart },
	delivered: { label: "Livrată", class: "bg-success", icon: CheckCircle2 },
	cancelled: { label: "Anulată", class: "bg-danger", icon: XCircle },
	refunded: { label: "Returnată", class: "bg-secondary", icon: XCircle },
};

export function getStatusBadge(status) {
	const info = STATUS_MAP[status] || { label: status, class: "bg-secondary", icon: Clock };
	const StatusIcon = info.icon;

	return (
		<span className={`badge ${info.class}`} style={{ display: "inline-flex", alignItems: "center", gap: "0.3rem" }}>
			<StatusIcon size={12} />
			{info.label}
		</span>
	);
}

export const SUPPLIER_STATUS_MAP = {
	ok: { label: "Trimisă la furnizor", class: "bg-success", icon: CheckCircle2 },
	failed: { label: "Eroare furnizor", class: "bg-danger", icon: AlertTriangle },
	pending: { label: "În procesare", class: "bg-secondary", icon: Clock },
	not_applicable: { label: "—", class: "bg-light text-muted", icon: null },
};

export function getSupplierBadge(supplierStatus) {
	const info = SUPPLIER_STATUS_MAP[supplierStatus?.state] || SUPPLIER_STATUS_MAP.not_applicable;
	const Icon = info.icon;
	const title = supplierStatus?.issues?.length
		? supplierStatus.issues.map((i) => `${i.supplier}: ${i.message || "eroare necunoscută"}`).join(" | ")
		: undefined;

	return (
		<span
			className={`badge ${info.class}`}
			title={title}
			style={{ display: "inline-flex", alignItems: "center", gap: "0.3rem", cursor: title ? "help" : "default" }}>
			{Icon && <Icon size={12} />}
			{info.label}
		</span>
	);
}
