import{a as e,t}from"./react-DK-MTtD8.js";import{s as n}from"./utils-CXcsdpX-.js";import{r}from"./api-CC_sFP6f.js";import{t as i}from"./list-table-CF_0QrYo.js";import{t as a}from"./plus-CuMPbIyn.js";import{t as o}from"./save-DstqMto4.js";import{Bn as s,Ra as c,Xr as l,_r as u,aa as d,ki as f,za as p}from"./index-CvTTLloU.js";import{t as m}from"./page-content-Bh5Zxb_Y.js";import{t as h}from"./badge-CL1e8lO_.js";import{a as g,i as _,n as v,o as y,t as b}from"./dialog-DrW_2c38.js";import{t as x}from"./record-actions-DCNk_Ak0.js";import{t as S}from"./list-page-header-D6ls_V1f.js";import{t as C}from"./use-server-pagination-CR_EVf1w.js";import{t as w}from"./auth-status-badge-BlJK5R24.js";var T=e(t(),1),E=n(),D={name:``,status:`active`};function O(){let[e,t]=(0,T.useState)(``),[n,O]=(0,T.useState)(!1),[k,A]=(0,T.useState)(null),[j,M]=(0,T.useState)(D),[N,P]=(0,T.useState)(!1),F=C(),I=F.buildParams(e?{search:e}:void 0),{data:L,isLoading:R,refetch:z}=l(I),B=F.getItems(L),[V,{isLoading:H}]=s(),[U,{isLoading:W}]=f(),[G]=u(),K=()=>{A(null),M(D),P(!1),O(!0)},q=e=>{A(e.id),M({name:e.name,status:e.status}),P(!1),O(!0)},J=e=>{A(e.id),M({name:e.name,status:e.status}),P(!0),O(!0)},Y=async e=>{e.preventDefault(),k?await U({id:k,data:j}):await V(j),O(!1)},X=(e,t)=>M(n=>({...n,[e]:t}));return(0,E.jsxs)(m,{children:[(0,E.jsx)(S,{title:`Designations`,description:`Manage designation master data`,searchPlaceholder:`Search designations...`,searchValue:e,onSearchChange:e=>{t(e),F.setPage(1)},action:(0,E.jsxs)(p,{onClick:K,size:`sm`,children:[(0,E.jsx)(a,{className:`mr-2 h-4 w-4`}),` Add Designation`]})}),(0,E.jsx)(i,{data:B,columns:[{key:`code`,label:`Code`,render:e=>(0,E.jsx)(`span`,{className:`font-mono`,children:e.code})},{key:`name`,label:`Name`,render:e=>(0,E.jsx)(`span`,{className:`font-medium`,children:e.name})},{key:`status`,label:`Status`,render:e=>(0,E.jsx)(h,{variant:e.status===`active`?`default`:`secondary`,children:e.status})},{key:`authorized_status`,label:`Auth`,render:e=>(0,E.jsx)(w,{status:e.authorized_status})},{key:`actions`,label:`Actions`,sortable:!1,render:e=>(0,E.jsx)(x,{approval:{entityType:`Designation`,objectId:e.id,contentTypeId:r.DESIGNATION,authorizedStatus:e.authorized_status??1,onApprovalChange:()=>z()},onView:()=>J(e),onEdit:()=>q(e),onDelete:()=>G(e.id)})}],isLoading:R,rowKey:e=>e.id,emptyMessage:`No designations found`,...F.tableProps(L)}),(0,E.jsx)(b,{open:n,onOpenChange:O,children:(0,E.jsxs)(v,{className:`sm:max-w-md`,children:[(0,E.jsx)(g,{children:(0,E.jsx)(y,{children:N?`View Designation`:k?`Edit Designation`:`New Designation`})}),(0,E.jsxs)(`form`,{onSubmit:Y,className:`space-y-4`,children:[(0,E.jsxs)(`div`,{className:`space-y-2`,children:[(0,E.jsxs)(d,{children:[`Designation Name `,(0,E.jsx)(`span`,{className:`text-destructive`,children:`*`})]}),(0,E.jsx)(c,{placeholder:`e.g. Manager`,value:j.name,onChange:e=>X(`name`,e.target.value),required:!0,disabled:N})]}),(0,E.jsxs)(`div`,{className:`space-y-2`,children:[(0,E.jsx)(d,{children:`Status`}),(0,E.jsxs)(`select`,{value:j.status,onChange:e=>X(`status`,e.target.value),className:`w-full border rounded-md px-3 py-2 text-sm h-9`,disabled:N,children:[(0,E.jsx)(`option`,{value:`active`,children:`Active`}),(0,E.jsx)(`option`,{value:`inactive`,children:`Inactive`})]})]}),(0,E.jsxs)(_,{children:[(0,E.jsx)(p,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>O(!1),children:`Cancel`}),!N&&(0,E.jsxs)(p,{type:`submit`,size:`sm`,disabled:H||W,children:[(0,E.jsx)(o,{className:`mr-2 h-4 w-4`}),H||W?`Saving...`:`Save`]})]})]})]})})]})}export{O as default};