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{Ra as f,aa as p,ea as m,na as h,ns as g,ra as _,ta as v,ts as y,za as b}from"./index-CsuVxiRQ.js";import{t as x}from"./page-content-DdXVZwik.js";import{t as S}from"./badge-DLCseWie.js";import{a as C,i as w,n as T,o as E,t as D}from"./dialog-BT7QjyH-.js";import{t as O}from"./record-actions-BJhHCezi.js";import{t as k}from"./list-page-header-BnFKDjpb.js";import{t as A}from"./use-server-pagination-BC4JB9I3.js";import{t as j}from"./auth-status-badge-C6fBtAs6.js";var M=e(t(),1),N=n(),P={name:``,status:`active`};function F(){let e=y(),{list:t,loading:n}=g(e=>e.countries),[F,I]=(0,M.useState)(``),[L,R]=(0,M.useState)(!1),[z,B]=(0,M.useState)(null),[V,H]=(0,M.useState)(P),[U,W]=(0,M.useState)(!1),G=A(),K=()=>{let t={};F&&(t.search=F),e(h(G.buildParams(Object.keys(t).length?t:void 0)))};(0,M.useEffect)(()=>{K()},[]);let q=()=>{B(null),H(P),W(!1),R(!0)},J=e=>{B(e.id),H({name:e.name,status:e.status}),W(!1),R(!0)},Y=e=>{B(e.id),H({name:e.name,status:e.status}),W(!0),R(!0)},X=async t=>{t.preventDefault(),z?await e(_({id:z,data:V})):await e(m(V)),R(!1),K()},Z=t=>{e(v(t)).then(()=>K())},Q=(e,t)=>H(n=>({...n,[e]:t}));return(0,N.jsxs)(x,{children:[(0,N.jsx)(k,{title:`Countries`,description:`Manage country master data`,searchPlaceholder:`Search countries...`,searchValue:F,onSearchChange:e=>{I(e),G.setPage(1)},action:(0,N.jsxs)(b,{onClick:q,size:`sm`,children:[(0,N.jsx)(u,{className:`mr-2 h-4 w-4`}),` Add Country`]})}),(0,N.jsx)(i,{data:t,columns:[{key:`code`,label:`Code`,render:e=>(0,N.jsx)(`span`,{className:`font-mono`,children:e.code})},{key:`name`,label:`Name`,render:e=>(0,N.jsx)(`span`,{className:`font-medium`,children:e.name})},{key:`status`,label:`Status`,render:e=>(0,N.jsx)(S,{variant:e.status===`active`?`default`:`secondary`,children:e.status})},{key:`authorized_status`,label:`Approval Status`,render:e=>(0,N.jsx)(j,{status:e.authorized_status})},{key:`actions`,label:`Actions`,sortable:!1,render:e=>(0,N.jsx)(O,{approval:{entityType:`Country`,objectId:e.id,contentTypeId:r.COUNTRY,authorizedStatus:e.authorized_status,onApprovalChange:()=>K()},onView:()=>Y(e),onEdit:()=>J(e),onDelete:()=>Z(e.id)})}],isLoading:n,rowKey:e=>e.id,emptyMessage:`No countries found`,...G.tableProps({results:t,count:t.length})}),(0,N.jsx)(D,{open:L,onOpenChange:R,children:(0,N.jsxs)(T,{className:`sm:max-w-md`,children:[(0,N.jsx)(C,{children:(0,N.jsx)(E,{children:U?`View Country`:z?`Edit Country`:`New Country`})}),(0,N.jsxs)(`form`,{onSubmit:X,className:`space-y-4`,children:[(0,N.jsxs)(`div`,{className:`space-y-2`,children:[(0,N.jsxs)(p,{htmlFor:`dlg-name`,children:[`Country Name `,(0,N.jsx)(`span`,{className:`text-destructive`,children:`*`})]}),(0,N.jsx)(f,{id:`dlg-name`,placeholder:`Enter country name`,value:V.name,onChange:e=>Q(`name`,e.target.value),required:!0,disabled:U})]}),(0,N.jsxs)(`div`,{className:`space-y-2`,children:[(0,N.jsx)(p,{htmlFor:`dlg-status`,children:`Status`}),(0,N.jsxs)(l,{value:V.status,onValueChange:e=>Q(`status`,e),disabled:U,children:[(0,N.jsx)(o,{className:`w-full h-9 text-sm`,children:(0,N.jsx)(a,{})}),(0,N.jsxs)(s,{children:[(0,N.jsx)(c,{value:`active`,children:`Active`}),(0,N.jsx)(c,{value:`inactive`,children:`Inactive`})]})]})]}),(0,N.jsxs)(w,{children:[(0,N.jsx)(b,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>R(!1),children:`Cancel`}),!U&&(0,N.jsxs)(b,{type:`submit`,size:`sm`,disabled:n,children:[(0,N.jsx)(d,{className:`mr-2 h-4 w-4`}),n?`Saving...`:`Save`]})]})]})]})})]})}export{F as default};