import{a as e,t}from"./react-DK-MTtD8.js";import{s as n}from"./utils-CXcsdpX-.js";import{t as r}from"./list-table-CQD2C7IB.js";import{t as i}from"./plus-CuMPbIyn.js";import{t as a}from"./save-DstqMto4.js";import{i as o,o as s,s as c}from"./Helper-CgZLd8U2.js";import{$r as l,Ra as u,aa as d,za as f}from"./index-Ct5uU080.js";import{t as p}from"./page-content-Bh5Zxb_Y.js";import{t as m}from"./badge-CL1e8lO_.js";import{a as h,i as g,n as _,o as v,t as y}from"./dialog-DuXDR687.js";import{t as b}from"./record-actions-CTlg0qBJ.js";import{t as x}from"./list-page-header-CePoWpko.js";import{t as S}from"./use-server-pagination-CR_EVf1w.js";import{t as C}from"./auth-status-badge-BlJK5R24.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(),F=P.buildParams(e?{search:e}:void 0),{data:I,isLoading:L,refetch:R}=l(F),z=P.getItems(I),B=()=>{k(null),j(E),N(!1),D(!0)},V=e=>{k(e.id),j({name:e.name,description:e.description||``,status:e.status}),N(!1),D(!0)},H=e=>{k(e.id),j({name:e.name,description:e.description||``,status:e.status}),N(!0),D(!0)},U=async e=>{e.preventDefault(),O?await o(`/masters/price-basis/${O}/`,A):await s(`/masters/price-basis/`,A),D(!1),R()},W=async e=>{await c(`/masters/price-basis/${e}/`),R()},G=(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)(f,{onClick:B,size:`sm`,children:[(0,T.jsx)(i,{className:`mr-2 h-4 w-4`}),` Add Price Basis`]})}),(0,T.jsx)(r,{data:z,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:()=>H(e),onEdit:()=>V(e),onDelete:()=>W(e.id)})}],isLoading:L,rowKey:e=>e.id,emptyMessage:`No price basis entries found`,...P.tableProps(I)}),(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:U,className:`space-y-4`,children:[(0,T.jsxs)(`div`,{className:`space-y-2`,children:[(0,T.jsxs)(d,{children:[`Name `,(0,T.jsx)(`span`,{className:`text-destructive`,children:`*`})]}),(0,T.jsx)(u,{placeholder:`e.g. Ex-Works, FOR, CIF, FOB`,value:A.name,onChange:e=>G(`name`,e.target.value),required:!0,disabled:M})]}),(0,T.jsxs)(`div`,{className:`space-y-2`,children:[(0,T.jsx)(d,{children:`Description`}),(0,T.jsx)(u,{placeholder:`Description`,value:A.description,onChange:e=>G(`description`,e.target.value),disabled:M})]}),(0,T.jsxs)(`div`,{className:`space-y-2`,children:[(0,T.jsx)(d,{children:`Status`}),(0,T.jsxs)(`select`,{value:A.status,onChange:e=>G(`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)(f,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>D(!1),children:`Cancel`}),!M&&(0,T.jsxs)(f,{type:`submit`,size:`sm`,children:[(0,T.jsx)(a,{className:`mr-2 h-4 w-4`}),`Save`]})]})]})]})})]})}export{D as default};