import{i as e}from"./rolldown-runtime-Dd_uD5pT.js";import{t}from"./react-BatatxyT.js";import{s as n}from"./utils-BO1RPuol.js";import{r}from"./api-CycUopBp.js";import{t as i}from"./list-table-DNq_Jbx2.js";import{a,i as o,n as s,r as c,t as l}from"./select-WoCJF3KO.js";import{t as u}from"./plus-BEDg_66Y.js";import{t as d}from"./save-D-WHGflg.js";import{Jr as f,Ra as p,Zi as m,aa as h,cr as g,yi as ee,za as _,zr as v}from"./index-CsuVxiRQ.js";import{t as y}from"./page-content-DdXVZwik.js";import{t as b}from"./badge-DLCseWie.js";import{a as x,i as S,n as C,o as w,t as T}from"./dialog-BT7QjyH-.js";import{t as E}from"./record-actions-BJhHCezi.js";import{t as D}from"./list-page-header-BnFKDjpb.js";import{t as O}from"./use-server-pagination-BC4JB9I3.js";import{t as k}from"./auth-status-badge-C6fBtAs6.js";var A=e(t(),1),j=n(),M={name:``,country:``,status:`active`};function N(){let[e,t]=(0,A.useState)(``),[n,N]=(0,A.useState)(!1),[P,F]=(0,A.useState)(null),[I,L]=(0,A.useState)(M),[R,z]=(0,A.useState)(!1),B=O(),V=B.buildParams(e?{search:e}:void 0),{data:H,isLoading:U,refetch:W}=ee(V),G=B.getItems(H),{data:K=[]}=f(),[q,{isLoading:J}]=g(),[Y,{isLoading:X}]=m(),[Z]=v(),Q=()=>{F(null),L(M),z(!1),N(!0)},te=e=>{F(e.id),L({name:e.name,country:e.country||``,status:e.status}),z(!1),N(!0)},ne=e=>{F(e.id),L({name:e.name,country:e.country||``,status:e.status}),z(!0),N(!0)},re=async e=>{e.preventDefault(),P?await Y({id:P,data:I}):await q(I),N(!1)},$=(e,t)=>L(n=>({...n,[e]:t}));return(0,j.jsxs)(y,{children:[(0,j.jsx)(D,{title:`States`,description:`Manage state/province master data`,searchPlaceholder:`Search states...`,searchValue:e,onSearchChange:e=>{t(e),B.setPage(1)},action:(0,j.jsxs)(_,{onClick:Q,size:`sm`,children:[(0,j.jsx)(u,{className:`mr-2 h-4 w-4`}),` Add State`]})}),(0,j.jsx)(i,{data:G,columns:[{key:`code`,label:`Code`,render:e=>(0,j.jsx)(`span`,{className:`font-mono`,children:e.code})},{key:`name`,label:`Name`,render:e=>(0,j.jsx)(`span`,{className:`font-medium`,children:e.name})},{key:`country_name`,label:`Country`,render:e=>e.country_name||`—`},{key:`status`,label:`Status`,render:e=>(0,j.jsx)(b,{variant:e.status===`active`?`default`:`secondary`,children:e.status})},{key:`authorized_status`,label:`Approval Status`,render:e=>(0,j.jsx)(k,{status:e.authorized_status})},{key:`actions`,label:`Actions`,sortable:!1,render:e=>(0,j.jsx)(E,{approval:{entityType:`State`,objectId:e.id,contentTypeId:r.STATE??44,authorizedStatus:e.authorized_status??1,onApprovalChange:()=>W()},onView:()=>ne(e),onEdit:()=>te(e),onDelete:()=>Z(e.id)})}],isLoading:U,rowKey:e=>e.id,emptyMessage:`No states found`,...B.tableProps(H)}),(0,j.jsx)(T,{open:n,onOpenChange:N,children:(0,j.jsxs)(C,{className:`sm:max-w-md`,children:[(0,j.jsx)(x,{children:(0,j.jsx)(w,{children:R?`View State`:P?`Edit State`:`New State`})}),(0,j.jsxs)(`form`,{onSubmit:re,className:`space-y-4`,children:[(0,j.jsxs)(`div`,{className:`space-y-2`,children:[(0,j.jsxs)(h,{htmlFor:`dlg-name`,children:[`State Name `,(0,j.jsx)(`span`,{className:`text-destructive`,children:`*`})]}),(0,j.jsx)(p,{id:`dlg-name`,placeholder:`Enter state name`,value:I.name,onChange:e=>$(`name`,e.target.value),required:!0,disabled:R})]}),(0,j.jsxs)(`div`,{className:`space-y-2`,children:[(0,j.jsxs)(h,{htmlFor:`dlg-country`,children:[`Country `,(0,j.jsx)(`span`,{className:`text-destructive`,children:`*`})]}),(0,j.jsxs)(l,{value:I.country||void 0,onValueChange:e=>$(`country`,e),disabled:R,required:!0,children:[(0,j.jsx)(o,{className:`w-full h-9 text-sm`,children:(0,j.jsx)(a,{placeholder:`Select country`})}),(0,j.jsx)(s,{children:K.map(e=>(0,j.jsx)(c,{value:e.id,children:e.name},e.id))})]})]}),(0,j.jsxs)(`div`,{className:`space-y-2`,children:[(0,j.jsx)(h,{htmlFor:`dlg-status`,children:`Status`}),(0,j.jsxs)(l,{value:I.status,onValueChange:e=>$(`status`,e),disabled:R,children:[(0,j.jsx)(o,{className:`w-full h-9 text-sm`,children:(0,j.jsx)(a,{})}),(0,j.jsxs)(s,{children:[(0,j.jsx)(c,{value:`active`,children:`Active`}),(0,j.jsx)(c,{value:`inactive`,children:`Inactive`})]})]})]}),(0,j.jsxs)(S,{children:[(0,j.jsx)(_,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>N(!1),children:`Cancel`}),!R&&(0,j.jsxs)(_,{type:`submit`,size:`sm`,disabled:J||X,children:[(0,j.jsx)(d,{className:`mr-2 h-4 w-4`}),J||X?`Saving...`:`Save`]})]})]})]})})]})}export{N as default};