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-M8Qu8ozW.js";import{a,i as o,n as s,r as c,t as l}from"./select-788h6o8Z.js";import{t as u}from"./plus-VCCEyniC.js";import{t as d}from"./save-Cm-Rqwuf.js";import{Ao as f,Hi as p,Ki as m,Ui as h,Vi as g,Wi as _,ga as v,ha as y,jo as b}from"./index-8M5AnKdQ.js";import{t as x}from"./page-content-DDtdeMxM.js";import{t as S}from"./badge-Crg76WQE.js";import{a as C,i as w,n as T,o as E,t as D}from"./dialog-CILF_XUh.js";import{t as O}from"./record-actions-3WNKE8L8.js";import{t as k}from"./list-page-header-DTmo84Zp.js";import{t as A}from"./use-server-pagination-CjwQ90IL.js";import{t as j}from"./auth-status-badge-pVqOsTb5.js";var M=e(t(),1),N=n(),P={name:``,status:`active`};function F(){let e=f(),{list:t,loading:n}=b(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(g(V)),R(!1),K()},Z=t=>{e(p(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)(v,{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)(m,{htmlFor:`dlg-name`,children:[`Country Name `,(0,N.jsx)(`span`,{className:`text-destructive`,children:`*`})]}),(0,N.jsx)(y,{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)(m,{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)(v,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>R(!1),children:`Cancel`}),!U&&(0,N.jsxs)(v,{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};