import { Link } from "react-router-dom"; import { MapPin, Phone, User, Plus, Timer } from "lucide-react"; import type { Material, Supplier } from "../../lib/types"; import { normalize } from "../../lib/normalize"; import { fmtNum } from "../../lib/formatters"; export function topicCategories(topic: string, materials: Material[], suppliers: Supplier[]): string[] { const out = new Set(); materials .filter((m) => topic && normalize(m.topic) === normalize(topic) && m.category) .forEach((m) => out.add(m.category)); suppliers .filter((s) => topic && normalize(s.topic) === normalize(topic)) .forEach((s) => (s.categories || []).forEach((c) => c && out.add(c))); return [...out].sort((a, b) => a.localeCompare(b, "fa")); } export function suppliersOfCategory(topic: string, cat: string, suppliers: Supplier[]): Supplier[] { return suppliers.filter( (s) => normalize(s.topic) === normalize(topic) && (s.categories || []).some((c) => normalize(c) === normalize(cat)), ); } // کارت تأمین‌کننده همراه با برچسب میانگین زمان تحویل export function SupplierCard({ s, topic, deletable, onDelete, materials = [], avgLeadTime, }: { s: Supplier; topic: string; deletable?: boolean; onDelete?: (id: string) => void; materials?: string[]; avgLeadTime?: number | null; }) { return (
{s.name}
{avgLeadTime != null && ( {fmtNum(avgLeadTime)} روز )} {deletable && onDelete && ( )}
{s.location || "—"} {s.phone || "—"} {s.contact || "—"}
{materials.length > 0 && (
{materials.map((m, i) => ( {m} ))}
)}
پیشنهاد جدید
); }