import{u as j,j as e,H as N}from"./app-BQEFzdw6.js";import{A as b}from"./AppLayout-kozc03ce.js";import{P as f}from"./PageHeader-Bj1OQnqr.js";import{F as m}from"./FormField-HY4WrCzQ.js";import{F as g}from"./PlusIcon-ElxOOThC.js";import{F as v}from"./TrashIcon-D0d0jw01.js";import"./useThemeColor-qPCpc713.js";function I({projects:d}){const{data:r,setData:i,post:u,processing:o,errors:l}=j({project_id:"",required_by:"",notes:"",items:[{description:"",unit:"",quantity_required:"",estimated_rate:""}]});function p(){i("items",[...r.items,{description:"",unit:"",quantity_required:"",estimated_rate:""}])}function x(t){i("items",r.items.filter((a,s)=>s!==t))}function n(t,a,s){const c=[...r.items];c[t]={...c[t],[a]:s},i("items",c)}function h(t){t.preventDefault(),u(route("procurement.requisitions.store"))}return e.jsxs(b,{children:[e.jsx(N,{title:"New Requisition"}),e.jsx(f,{title:"New Purchase Requisition",back:route("procurement.requisitions.index")}),e.jsx("div",{className:"p-4 sm:p-6 max-w-4xl",children:e.jsxs("form",{onSubmit:h,className:"space-y-4",children:[e.jsxs("div",{className:"card p-6",children:[e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4",children:[e.jsx(m,{label:"Project",error:l.project_id,children:e.jsxs("select",{className:"form-input",value:r.project_id,onChange:t=>i("project_id",t.target.value),children:[e.jsx("option",{value:"",children:"-- No Project --"}),(d??[]).map(t=>e.jsx("option",{value:t.id,children:t.name},t.id))]})}),e.jsx(m,{label:"Required By",error:l.required_by,children:e.jsx("input",{type:"date",className:"form-input",value:r.required_by,onChange:t=>i("required_by",t.target.value)})})]}),e.jsx(m,{label:"Notes",error:l.notes,className:"mt-4",children:e.jsx("textarea",{className:"form-input",rows:2,value:r.notes,onChange:t=>i("notes",t.target.value)})})]}),e.jsxs("div",{className:"card p-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsx("h3",{className:"font-medium text-sm",children:"Items"}),e.jsxs("button",{type:"button",onClick:p,className:"btn text-xs flex items-center gap-1",children:[e.jsx(g,{className:"w-3 h-3"})," Add Item"]})]}),e.jsxs("table",{className:"min-w-full text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"text-xs text-gray-500",children:[e.jsx("th",{className:"text-left pb-2",children:"Description"}),e.jsx("th",{className:"text-left pb-2 w-24",children:"Unit"}),e.jsx("th",{className:"text-left pb-2 w-24",children:"Qty"}),e.jsx("th",{className:"text-left pb-2 w-28",children:"Est. Rate"}),e.jsx("th",{className:"w-8"})]})}),e.jsx("tbody",{className:"space-y-2",children:r.items.map((t,a)=>e.jsxs("tr",{children:[e.jsx("td",{className:"pr-2 pb-2",children:e.jsx("input",{className:"form-input text-sm",value:t.description,onChange:s=>n(a,"description",s.target.value),placeholder:"Description"})}),e.jsx("td",{className:"pr-2 pb-2",children:e.jsx("input",{className:"form-input text-sm",value:t.unit,onChange:s=>n(a,"unit",s.target.value),placeholder:"pcs"})}),e.jsx("td",{className:"pr-2 pb-2",children:e.jsx("input",{type:"number",className:"form-input text-sm",value:t.quantity_required,onChange:s=>n(a,"quantity_required",s.target.value)})}),e.jsx("td",{className:"pr-2 pb-2",children:e.jsx("input",{type:"number",className:"form-input text-sm",value:t.estimated_rate,onChange:s=>n(a,"estimated_rate",s.target.value)})}),e.jsx("td",{className:"pb-2",children:r.items.length>1&&e.jsx("button",{type:"button",onClick:()=>x(a),className:"text-gray-300 hover:text-red-500",children:e.jsx(v,{className:"w-4 h-4"})})})]},a))})]})]}),e.jsxs("div",{className:"flex gap-3",children:[e.jsx("button",{type:"submit",disabled:o,className:"btn btn-primary",children:o?"Submitting…":"Submit Requisition"}),e.jsx("a",{href:route("procurement.requisitions.index"),className:"btn",children:"Cancel"})]})]})})]})}export{I as default};
