import{j as t,C,P as E,T as j,e as m,I as T,B as S,g as y}from"./index-B1H8BCL7.js";import{d as A}from"./Add-DvXlrcIU.js";import{d as I}from"./DeleteOutline-DENqzAfR.js";import{S as R}from"./Stack-BIAbaqpj.js";import{T as k,c as O,b,a as z}from"./TableRow-BfKE_xn9.js";import{T as i}from"./TableCell-D8CotAsC.js";import{A as L}from"./Autocomplete-D8_Y_gp5.js";const D={DRAFT:{bg:"#f1f5f9",fg:"#475569"},CANCELLED:{bg:"#fef2f2",fg:"#b91c1c"},REJECTED:{bg:"#fef2f2",fg:"#b91c1c"},SUBMITTED:{bg:"#fef3c7",fg:"#b45309"},APPROVED:{bg:"#ecfdf5",fg:"#059669"},CONVERTED_TO_PO:{bg:"#eff6ff",fg:"#1d4ed8"},SENT_TO_VENDOR:{bg:"#eff6ff",fg:"#1d4ed8"},PARTIALLY_RECEIVED:{bg:"#fef3c7",fg:"#b45309"},FULLY_RECEIVED:{bg:"#ecfdf5",fg:"#059669"},CLOSED:{bg:"#f1f5f9",fg:"#475569"},RECEIVED:{bg:"#fef3c7",fg:"#b45309"},UNDER_VERIFICATION:{bg:"#fef3c7",fg:"#b45309"},ACCEPTED:{bg:"#ecfdf5",fg:"#059669"},PARTIALLY_ACCEPTED:{bg:"#fef3c7",fg:"#b45309"},POSTED:{bg:"#ecfdf5",fg:"#059669"}},U=({status:r})=>{if(!r)return null;const n=D[r]??{bg:"#f1f5f9",fg:"#475569"};return t.jsx(C,{size:"small",label:r.replaceAll("_"," "),sx:{height:20,fontSize:"0.65rem",fontWeight:700,letterSpacing:"0.03em",backgroundColor:n.bg,color:n.fg,borderRadius:"6px"}})},w=({rows:r,onChange:n,columns:a,emptyRow:d})=>{const s=(e,l,o)=>{const f=r.map((u,h)=>h===e?{...u,[l]:o}:u);n(f)},c=e=>n(r.filter((l,o)=>o!==e)),g=()=>n([...r||[],{...d}]);return t.jsxs(R,{spacing:1.25,children:[t.jsx(E,{variant:"outlined",sx:{borderRadius:2,borderColor:"#e2e8f0",overflow:"auto"},children:t.jsxs(k,{size:"small",sx:{minWidth:640},children:[t.jsx(O,{children:t.jsxs(b,{sx:{backgroundColor:"#f8fafc"},children:[t.jsx(i,{sx:p,children:"#"}),a.map(e=>t.jsxs(i,{sx:{...p,width:e.width},children:[e.label,e.required?" *":""]},e.key)),t.jsx(i,{sx:{...p,width:56,textAlign:"right"},children:"—"})]})}),t.jsx(z,{children:!r||r.length===0?t.jsx(b,{children:t.jsxs(i,{colSpan:a.length+2,sx:{py:4,textAlign:"center",color:"#94a3b8",fontSize:"0.8125rem"},children:["No lines yet — click ",t.jsx("b",{children:"Add line"})," below"]})}):r.map((e,l)=>t.jsxs(b,{hover:!0,children:[t.jsx(i,{sx:x,children:t.jsx(j,{sx:{fontSize:"0.8125rem",color:"#64748b",fontVariantNumeric:"tabular-nums"},children:l+1})}),a.map(o=>t.jsx(i,{sx:x,children:o.type==="autocomplete"?t.jsx(v,{column:o,value:e[o.key],onChange:f=>s(l,o.key,f)}):t.jsx(m,{size:"small",fullWidth:!0,type:o.type==="date"?"date":o.type==="number"?"number":"text",value:e[o.key]??"",onChange:f=>s(l,o.key,o.type==="number"?f.target.value===""?"":Number(f.target.value):f.target.value),inputProps:o.type==="number"?{min:o.min??0,step:o.step??"any"}:void 0,InputLabelProps:o.type==="date"?{shrink:!0}:void 0,sx:{"& .MuiOutlinedInput-root":{fontSize:"0.8125rem",backgroundColor:"#fff"}}})},o.key)),t.jsx(i,{sx:{...x,textAlign:"right"},children:t.jsx(T,{size:"small",onClick:()=>c(l),sx:{color:"#94a3b8","&:hover":{color:"#ef4444",backgroundColor:"#fef2f2"}},children:t.jsx(I,{fontSize:"small"})})})]},l))})]})}),t.jsx(S,{children:t.jsx(y,{size:"small",variant:"outlined",startIcon:t.jsx(A,{sx:{fontSize:16}}),onClick:g,sx:{textTransform:"none",borderRadius:"8px",fontSize:"0.8rem",fontWeight:600,borderColor:"#cbd5e1",color:"#475569","&:hover":{borderColor:"#1d4ed8",color:"#1d4ed8",backgroundColor:"#eff6ff"}},children:"Add line"})})]})},v=({column:r,value:n,onChange:a})=>{const d=r.options||[],s=r.getOptionId||(e=>e==null?void 0:e.id),c=r.getOptionLabel||(e=>e==null?"":String(s(e)??"")),g=n===""||n==null?null:d.find(e=>s(e)===n)??null;return t.jsx(L,{size:"small",fullWidth:!0,options:d,value:g,onChange:(e,l)=>a(l?s(l):""),getOptionLabel:e=>e?c(e):"",isOptionEqualToValue:(e,l)=>s(e)===s(l),renderInput:e=>t.jsx(m,{...e,size:"small",placeholder:r.placeholder||"Search…",sx:{"& .MuiOutlinedInput-root":{fontSize:"0.8125rem",backgroundColor:"#fff"}}})})},p={fontSize:"0.66rem",fontWeight:700,color:"#64748b",textTransform:"uppercase",letterSpacing:"0.05em",py:1,px:1.25,borderBottom:"1px solid #e2e8f0",whiteSpace:"nowrap"},x={py:.75,px:1,borderBottom:"1px solid #f1f5f9",verticalAlign:"top"};export{w as L,U as S};
