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{In as f,Ra as p,Ti as m,Ur as h,aa as g,pr as ee,yi as _,za 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:``,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(),V=B.buildParams(e?{search:e}:void 0),{data:H,isLoading:U,refetch:W}=h(V),G=B.getItems(H),{data:K=[]}=_(),[q,{isLoading:J}]=f(),[Y,{isLoading:X}]=m(),[Z]=ee(),Q=()=>{F(null),L(M),z(!1),N(!0)},te=e=>{F(e.id),L({name:e.name,state:e.state||``,status:e.status}),z(!1),N(!0)},ne=e=>{F(e.id),L({name:e.name,state:e.state||``,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:`Cities`,description:`Manage city master data`,searchPlaceholder:`Search cities...`,searchValue:e,onSearchChange:e=>{t(e),B.setPage(1)},action:(0,j.jsxs)(v,{onClick:Q,size:`sm`,children:[(0,j.jsx)(u,{className:`mr-2 h-4 w-4`}),` Add City`]})}),(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:`state_name`,label:`State`,render:e=>e.state_name||`—`},{key:`status`,label:`Status`,render:e=>(0,j.jsx)(b,{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:()=>W()},onView:()=>ne(e),onEdit:()=>te(e),onDelete:()=>Z(e.id)})}],isLoading:U,rowKey:e=>e.id,emptyMessage:`No cities 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 City`:P?`Edit City`:`New City`})}),(0,j.jsxs)(`form`,{onSubmit:re,className:`space-y-4`,children:[(0,j.jsxs)(`div`,{className:`space-y-2`,children:[(0,j.jsxs)(g,{htmlFor:`dlg-name`,children:[`City Name `,(0,j.jsx)(`span`,{className:`text-destructive`,children:`*`})]}),(0,j.jsx)(p,{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)(g,{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: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)(g,{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)(v,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>N(!1),children:`Cancel`}),!R&&(0,j.jsxs)(v,{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};