import { useState } from "react"; import { Plus, Trash2, Layers, X } from "lucide-react"; import type { HumanResourceItem, MaterialItem } from "../lib/api"; interface ResourceSectionInputsProps { humanResources?: HumanResourceItem[]; setHumanResources?: (hrs: HumanResourceItem[]) => void; materials: MaterialItem[]; setMaterials: (mats: MaterialItem[]) => void; } function TagInput({ tags, onChange, placeholder = "افزودن مشخصه...", }: { tags: string[]; onChange: (tags: string[]) => void; placeholder?: string; }) { const [val, setVal] = useState(""); const addTag = () => { const trimmed = val.trim(); if (trimmed && !tags.includes(trimmed)) { onChange([...tags, trimmed]); setVal(""); } }; const removeTag = (index: number) => { onChange(tags.filter((_, i) => i !== index)); }; return (
setVal(e.target.value)} onKeyDown={(e) => { if (e.key === "Enter") { e.preventDefault(); addTag(); } }} placeholder={placeholder} className="h-8 flex-1 rounded-lg border border-slate-300 bg-white px-2.5 text-xs text-slate-800 placeholder:text-slate-400 focus:border-sky-500 focus:outline-none focus:ring-1 focus:ring-sky-200" />
{tags.length > 0 && (
{tags.map((tag, i) => ( {tag} ))}
)}
); } export function ResourceSectionInputs({ materials, setMaterials, }: ResourceSectionInputsProps) { // --- Materials handlers --- const addMaterial = () => { setMaterials([...materials, { name: "", unit: "", specifications: [], count: 1 }]); }; const updateMaterial = (index: number, field: keyof MaterialItem, value: any) => { const next = [...materials]; next[index] = { ...next[index], [field]: value }; setMaterials(next); }; const removeMaterial = (index: number) => { setMaterials(materials.filter((_, i) => i !== index)); }; return (
مصالح و تجهیزات وظیفه {materials.length > 0 && ( {materials.length} قلم )}
{/* --- Materials & Equipment Content --- */}
{materials.length === 0 ? (

هیچ مصالح یا تجهیزاتی تعریف نشده است.

) : ( materials.map((m, i) => (
updateMaterial(i, "name", e.target.value)} placeholder="مثلاً: سیمان تیپ ۲، میلگرد ۱۶، پمپ بتن، تاور کرین" className="h-8 w-full rounded-md border border-slate-300 px-2 text-xs text-slate-800 focus:border-amber-500 focus:outline-none" />
updateMaterial(i, "unit", e.target.value)} placeholder="تن، متر، دستگاه، شاخه" className="h-8 w-full rounded-md border border-slate-300 px-2 text-xs text-slate-800 focus:border-amber-500 focus:outline-none" />
updateMaterial(i, "count", Math.max(0, parseFloat(e.target.value) || 0))} className="h-8 w-full rounded-md border border-slate-300 px-2 text-xs text-slate-800 focus:border-amber-500 focus:outline-none" />
updateMaterial(i, "specifications", tags)} placeholder="مثال: استاندارد A3، عیار ۳۵۰، بوم ۳۶ متری (Enter بزنید)" />
)) )}
); }