import{a as e,t}from"./react-D0JuimcS.js";import{o as n}from"./utils-Dac180Gn.js";import{t as r}from"./list-table-M8Qu8ozW.js";import{t as i}from"./plus-VCCEyniC.js";import{t as a}from"./save-Cm-Rqwuf.js";import{Ki as o,ga as s,ha as c}from"./index-8M5AnKdQ.js";import{t as l}from"./page-content-DDtdeMxM.js";import{t as u}from"./badge-Crg76WQE.js";import{a as d,i as f,n as p,o as m,t as h}from"./dialog-CILF_XUh.js";import{t as g}from"./record-actions-3WNKE8L8.js";import{t as _}from"./list-page-header-DTmo84Zp.js";import{t as v}from"./use-server-pagination-CjwQ90IL.js";import{t as y}from"./auth-status-badge-pVqOsTb5.js";var b=e(t(),1),x=n(),S={name:``,status:`active`};function C({title:e,label:t,placeholder:n,contentTypeId:C,useGetQuery:w,useCreateMutation:T,useUpdateMutation:E,useDeleteMutation:D}){let[O,k]=(0,b.useState)(``),[A,j]=(0,b.useState)(!1),[M,N]=(0,b.useState)(null),[P,F]=(0,b.useState)(S),[I,L]=(0,b.useState)(!1),R=v(),{data:z,isLoading:B,refetch:V}=w(R.buildParams(O?{search:O}:void 0)),H=R.getItems(z),[U,{isLoading:W}]=T(),[G,{isLoading:K}]=E(),[q]=D(),J=()=>{N(null),F(S),L(!1),j(!0)},Y=e=>{N(e.id),F({name:e.name,status:e.status}),L(!1),j(!0)},X=e=>{N(e.id),F({name:e.name,status:e.status}),L(!0),j(!0)},Z=async e=>{e.preventDefault(),M?await G({id:M,data:P}):await U(P),j(!1),V()},Q=(e,t)=>F(n=>({...n,[e]:t}));return(0,x.jsxs)(l,{children:[(0,x.jsx)(_,{title:e,description:`Manage ${e.toLowerCase()} master data`,searchPlaceholder:`Search ${e.toLowerCase()}...`,searchValue:O,onSearchChange:e=>{k(e),R.setPage(1)},action:(0,x.jsxs)(s,{onClick:J,size:`sm`,children:[(0,x.jsx)(i,{className:`mr-2 h-4 w-4`}),` Add `,t]})}),(0,x.jsx)(r,{data:H,columns:[{key:`code`,label:`Code`,render:e=>(0,x.jsx)(`span`,{className:`font-mono`,children:e.code})},{key:`name`,label:`Name`,render:e=>(0,x.jsx)(`span`,{className:`font-medium`,children:e.name})},{key:`status`,label:`Status`,render:e=>(0,x.jsx)(u,{variant:e.status===`active`?`default`:`secondary`,children:e.status})},{key:`authorized_status`,label:`Auth`,render:e=>(0,x.jsx)(y,{status:e.authorized_status})},{key:`actions`,label:`Actions`,sortable:!1,render:e=>(0,x.jsx)(g,{approval:C?{entityType:t,objectId:e.id,contentTypeId:C,authorizedStatus:e.authorized_status??1,onApprovalChange:()=>V()}:void 0,onView:()=>X(e),onEdit:()=>Y(e),onDelete:()=>q(e.id)})}],isLoading:B,rowKey:e=>e.id,emptyMessage:`No ${e.toLowerCase()} found`,...R.tableProps(z)}),(0,x.jsx)(h,{open:A,onOpenChange:j,children:(0,x.jsxs)(p,{className:`sm:max-w-md`,children:[(0,x.jsx)(d,{children:(0,x.jsx)(m,{children:I?`View ${t}`:M?`Edit ${t}`:`New ${t}`})}),(0,x.jsxs)(`form`,{onSubmit:Z,className:`space-y-4`,children:[(0,x.jsxs)(`div`,{className:`space-y-2`,children:[(0,x.jsxs)(o,{children:[t,` Name `,(0,x.jsx)(`span`,{className:`text-destructive`,children:`*`})]}),(0,x.jsx)(c,{placeholder:n,value:P.name,onChange:e=>Q(`name`,e.target.value),required:!0,disabled:I})]}),(0,x.jsxs)(`div`,{className:`space-y-2`,children:[(0,x.jsx)(o,{children:`Status`}),(0,x.jsxs)(`select`,{value:P.status,onChange:e=>Q(`status`,e.target.value),className:`w-full border rounded-md px-3 py-2 text-sm h-9`,disabled:I,children:[(0,x.jsx)(`option`,{value:`active`,children:`Active`}),(0,x.jsx)(`option`,{value:`inactive`,children:`Inactive`})]})]}),(0,x.jsxs)(f,{children:[(0,x.jsx)(s,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>j(!1),children:`Cancel`}),!I&&(0,x.jsxs)(s,{type:`submit`,size:`sm`,disabled:W||K,children:[(0,x.jsx)(a,{className:`mr-2 h-4 w-4`}),W||K?`Saving...`:`Save`]})]})]})]})})]})}export{C as t};