import{a as e,t}from"./react-DK-MTtD8.js";import{s as n}from"./utils-CXcsdpX-.js";import{r}from"./api-DcvYaav1.js";import{t as i}from"./list-table-CQD2C7IB.js";import{a,i as o,n as s,r as c,t as l}from"./select-B6Gfe6WE.js";import{t as u}from"./plus-CuMPbIyn.js";import{t as d}from"./save-DstqMto4.js";import{$o as f,Qo as p,Ra as m,aa as h,ea as g,na as _,ra as v,ta as y,za as b}from"./index-Ct5uU080.js";import{t as x}from"./page-content-Bh5Zxb_Y.js";import{t as S}from"./badge-CL1e8lO_.js";import{a as C,i as w,n as T,o as E,t as D}from"./dialog-DuXDR687.js";import{t as O}from"./record-actions-CTlg0qBJ.js";import{t as k}from"./list-page-header-CePoWpko.js";import{t as A}from"./use-server-pagination-CR_EVf1w.js";import{t as j}from"./auth-status-badge-BlJK5R24.js";var M=e(t(),1),N=n(),P={name:``,status:`active`};function F(){let e=p(),{list:t,loading:n}=f(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(_(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(v({id:z,data:V})):await e(g(V)),R(!1),K()},Z=t=>{e(y(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)(h,{htmlFor:`dlg-name`,children:[`Country Name `,(0,N.jsx)(`span`,{className:`text-destructive`,children:`*`})]}),(0,N.jsx)(m,{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)(h,{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};