import{a as e,t}from"./react-D0JuimcS.js";import{o as n}from"./utils-Dac180Gn.js";import{t as r}from"./list-table-M8Qu8ozW.js";import{t as i}from"./plus-VCCEyniC.js";import{t as a}from"./save-Cm-Rqwuf.js";import{i as o,o as s,s as c}from"./Helper-7k0HBglN.js";import{Br as l,Ki as u,ga as d,ha as f}from"./index-8M5AnKdQ.js";import{t as p}from"./page-content-DDtdeMxM.js";import{t as m}from"./badge-Crg76WQE.js";import{a as h,i as g,n as _,o as v,t as y}from"./dialog-CILF_XUh.js";import{t as b}from"./record-actions-3WNKE8L8.js";import{t as x}from"./list-page-header-DTmo84Zp.js";import{t as S}from"./use-server-pagination-CjwQ90IL.js";import{t as C}from"./auth-status-badge-pVqOsTb5.js";var w=e(t(),1),T=n(),E={name:``,description:``,status:`active`};function D(){let[e,t]=(0,w.useState)(``),[n,D]=(0,w.useState)(!1),[O,k]=(0,w.useState)(null),[A,j]=(0,w.useState)(E),[M,N]=(0,w.useState)(!1),P=S(),{data:F,isLoading:I,refetch:L}=l(P.buildParams(e?{search:e}:void 0)),R=P.getItems(F),z=()=>{k(null),j(E),N(!1),D(!0)},B=e=>{k(e.id),j({name:e.name,description:e.description||``,status:e.status}),N(!1),D(!0)},V=e=>{k(e.id),j({name:e.name,description:e.description||``,status:e.status}),N(!0),D(!0)},H=async e=>{e.preventDefault(),O?await o(`/masters/price-basis/${O}/`,A):await s(`/masters/price-basis/`,A),D(!1),L()},U=async e=>{await c(`/masters/price-basis/${e}/`),L()},W=(e,t)=>j(n=>({...n,[e]:t}));return(0,T.jsxs)(p,{children:[(0,T.jsx)(x,{title:`Price Basis`,description:`Manage price basis options (e.g. Ex-Works, FOR, CIF)`,searchPlaceholder:`Search...`,searchValue:e,onSearchChange:e=>{t(e),P.setPage(1)},action:(0,T.jsxs)(d,{onClick:z,size:`sm`,children:[(0,T.jsx)(i,{className:`mr-2 h-4 w-4`}),` Add Price Basis`]})}),(0,T.jsx)(r,{data:R,columns:[{key:`code`,label:`Code`,render:e=>(0,T.jsx)(`span`,{className:`font-mono`,children:e.code})},{key:`name`,label:`Name`,render:e=>(0,T.jsx)(`span`,{className:`font-medium`,children:e.name})},{key:`status`,label:`Status`,render:e=>(0,T.jsx)(m,{variant:e.status===`active`?`default`:`secondary`,children:e.status})},{key:`authorized_status`,label:`Auth`,render:e=>(0,T.jsx)(C,{status:e.authorized_status??1})},{key:`actions`,label:`Actions`,sortable:!1,render:e=>(0,T.jsx)(b,{onView:()=>V(e),onEdit:()=>B(e),onDelete:()=>U(e.id)})}],isLoading:I,rowKey:e=>e.id,emptyMessage:`No price basis entries found`,...P.tableProps(F)}),(0,T.jsx)(y,{open:n,onOpenChange:D,children:(0,T.jsxs)(_,{className:`sm:max-w-md`,children:[(0,T.jsx)(h,{children:(0,T.jsx)(v,{children:M?`View Price Basis`:O?`Edit Price Basis`:`New Price Basis`})}),(0,T.jsxs)(`form`,{onSubmit:H,className:`space-y-4`,children:[(0,T.jsxs)(`div`,{className:`space-y-2`,children:[(0,T.jsxs)(u,{children:[`Name `,(0,T.jsx)(`span`,{className:`text-destructive`,children:`*`})]}),(0,T.jsx)(f,{placeholder:`e.g. Ex-Works, FOR, CIF, FOB`,value:A.name,onChange:e=>W(`name`,e.target.value),required:!0,disabled:M})]}),(0,T.jsxs)(`div`,{className:`space-y-2`,children:[(0,T.jsx)(u,{children:`Description`}),(0,T.jsx)(f,{placeholder:`Description`,value:A.description,onChange:e=>W(`description`,e.target.value),disabled:M})]}),(0,T.jsxs)(`div`,{className:`space-y-2`,children:[(0,T.jsx)(u,{children:`Status`}),(0,T.jsxs)(`select`,{value:A.status,onChange:e=>W(`status`,e.target.value),className:`w-full border rounded-md px-3 py-2 text-sm h-9`,disabled:M,children:[(0,T.jsx)(`option`,{value:`active`,children:`Active`}),(0,T.jsx)(`option`,{value:`inactive`,children:`Inactive`})]})]}),(0,T.jsxs)(g,{children:[(0,T.jsx)(d,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>D(!1),children:`Cancel`}),!M&&(0,T.jsxs)(d,{type:`submit`,size:`sm`,children:[(0,T.jsx)(a,{className:`mr-2 h-4 w-4`}),`Save`]})]})]})]})})]})}export{D as default};