import{a as e,t}from"./react-D0JuimcS.js";import{o as n}from"./utils-Dac180Gn.js";import{r}from"./api-NMlTtVre.js";import{t as i}from"./list-table-dcNbCPvq.js";import{a,i as o,n as s,r as c,t as l}from"./select-BLbEjWut.js";import{t as u}from"./plus-VCCEyniC.js";import{t as d}from"./save-Cm-Rqwuf.js";import{Ar as f,Cn as p,Ki as m,er as h,fi as g,ga as _,ha as v,oi as y}from"./index-BP3TYB4i.js";import{t as b}from"./page-content-DDtdeMxM.js";import{t as x}from"./badge-Crg76WQE.js";import{a as S,i as C,n as w,o as ee,t as T}from"./dialog-BeOPOVZK.js";import{t as E}from"./record-actions-DSw1sDLk.js";import{t as D}from"./list-page-header-48VsPegf.js";import{t as O}from"./use-server-pagination-CjwQ90IL.js";import{t as k}from"./auth-status-badge-pVqOsTb5.js";var A=e(t(),1),j=n(),M={name:``,state:``,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(),{data:V,isLoading:H,refetch:U}=f(B.buildParams(e?{search:e}:void 0)),W=B.getItems(V),{data:G=[]}=y(),[K,{isLoading:q}]=p(),[J,{isLoading:Y}]=g(),[X]=h(),Z=()=>{F(null),L(M),z(!1),N(!0)},Q=e=>{F(e.id),L({name:e.name,state:e.state||``,status:e.status}),z(!1),N(!0)},te=e=>{F(e.id),L({name:e.name,state:e.state||``,status:e.status}),z(!0),N(!0)},ne=async e=>{e.preventDefault(),P?await J({id:P,data:I}):await K(I),N(!1)},$=(e,t)=>L(n=>({...n,[e]:t}));return(0,j.jsxs)(b,{children:[(0,j.jsx)(D,{title:`Cities`,description:`Manage city master data`,searchPlaceholder:`Search cities...`,searchValue:e,onSearchChange:e=>{t(e),B.setPage(1)},action:(0,j.jsxs)(_,{onClick:Z,size:`sm`,children:[(0,j.jsx)(u,{className:`mr-2 h-4 w-4`}),` Add City`]})}),(0,j.jsx)(i,{data:W,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:`state_name`,label:`State`,render:e=>e.state_name||`—`},{key:`status`,label:`Status`,render:e=>(0,j.jsx)(x,{variant:e.status===`active`?`default`:`secondary`,children:e.status})},{key:`authorized_status`,label:`Auth`,render:e=>(0,j.jsx)(k,{status:e.authorized_status})},{key:`actions`,label:`Actions`,sortable:!1,render:e=>(0,j.jsx)(E,{approval:{entityType:`City`,objectId:e.id,contentTypeId:r.CITY??45,authorizedStatus:e.authorized_status??1,onApprovalChange:()=>U()},onView:()=>te(e),onEdit:()=>Q(e),onDelete:()=>X(e.id)})}],isLoading:H,rowKey:e=>e.id,emptyMessage:`No cities found`,...B.tableProps(V)}),(0,j.jsx)(T,{open:n,onOpenChange:N,children:(0,j.jsxs)(w,{className:`sm:max-w-md`,children:[(0,j.jsx)(S,{children:(0,j.jsx)(ee,{children:R?`View City`:P?`Edit City`:`New City`})}),(0,j.jsxs)(`form`,{onSubmit:ne,className:`space-y-4`,children:[(0,j.jsxs)(`div`,{className:`space-y-2`,children:[(0,j.jsxs)(m,{htmlFor:`dlg-name`,children:[`City Name `,(0,j.jsx)(`span`,{className:`text-destructive`,children:`*`})]}),(0,j.jsx)(v,{id:`dlg-name`,placeholder:`Enter city 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)(m,{htmlFor:`dlg-state`,children:[`State `,(0,j.jsx)(`span`,{className:`text-destructive`,children:`*`})]}),(0,j.jsxs)(l,{value:I.state||void 0,onValueChange:e=>$(`state`,e),disabled:R,required:!0,children:[(0,j.jsx)(o,{className:`w-full h-9 text-sm`,children:(0,j.jsx)(a,{placeholder:`Select state`})}),(0,j.jsx)(s,{children:G.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)(m,{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)(C,{children:[(0,j.jsx)(_,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>N(!1),children:`Cancel`}),!R&&(0,j.jsxs)(_,{type:`submit`,size:`sm`,disabled:q||Y,children:[(0,j.jsx)(d,{className:`mr-2 h-4 w-4`}),q||Y?`Saving...`:`Save`]})]})]})]})})]})}export{N as default};