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-dcNbCPvq.js";import{t as a}from"./plus-VCCEyniC.js";import{t as o}from"./save-Cm-Rqwuf.js";import{Dn as s,Ki as c,Lr as l,ga as u,gi as d,ha as f,ir as p}from"./index-BP3TYB4i.js";import{t as m}from"./page-content-DDtdeMxM.js";import{t as h}from"./badge-Crg76WQE.js";import{a as g,i as _,n as v,o as y,t as b}from"./dialog-BeOPOVZK.js";import{t as x}from"./record-actions-DSw1sDLk.js";import{t as S}from"./list-page-header-48VsPegf.js";import{t as C}from"./use-server-pagination-CjwQ90IL.js";import{t as w}from"./auth-status-badge-pVqOsTb5.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(),{data:I,isLoading:L,refetch:R}=l(F.buildParams(e?{search:e}:void 0)),z=F.getItems(I),[B,{isLoading:V}]=s(),[H,{isLoading:U}]=d(),[W]=p(),G=()=>{A(null),M(D),P(!1),O(!0)},K=e=>{A(e.id),M({name:e.name,status:e.status}),P(!1),O(!0)},q=e=>{A(e.id),M({name:e.name,status:e.status}),P(!0),O(!0)},J=async e=>{e.preventDefault(),k?await H({id:k,data:j}):await B(j),O(!1)},Y=(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)(u,{onClick:G,size:`sm`,children:[(0,E.jsx)(a,{className:`mr-2 h-4 w-4`}),` Add Designation`]})}),(0,E.jsx)(i,{data:z,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:()=>R()},onView:()=>q(e),onEdit:()=>K(e),onDelete:()=>W(e.id)})}],isLoading:L,rowKey:e=>e.id,emptyMessage:`No designations found`,...F.tableProps(I)}),(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:J,className:`space-y-4`,children:[(0,E.jsxs)(`div`,{className:`space-y-2`,children:[(0,E.jsxs)(c,{children:[`Designation Name `,(0,E.jsx)(`span`,{className:`text-destructive`,children:`*`})]}),(0,E.jsx)(f,{placeholder:`e.g. Manager`,value:j.name,onChange:e=>Y(`name`,e.target.value),required:!0,disabled:N})]}),(0,E.jsxs)(`div`,{className:`space-y-2`,children:[(0,E.jsx)(c,{children:`Status`}),(0,E.jsxs)(`select`,{value:j.status,onChange:e=>Y(`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)(u,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>O(!1),children:`Cancel`}),!N&&(0,E.jsxs)(u,{type:`submit`,size:`sm`,disabled:V||U,children:[(0,E.jsx)(o,{className:`mr-2 h-4 w-4`}),V||U?`Saving...`:`Save`]})]})]})]})})]})}export{O as default};