import{t as e}from"./axios-m7YkukvY.js";import{A as t,L as n,N as r,Q as i,St as a,W as o,_ as s,at as c,c as l,et as u,h as d,l as f,m as p}from"./runtime-core.esm-bundler-Babufkcf.js";import{I as m,c as h,i as g,l as _,n as v,o as y}from"./index-uCtpzrM3.js";import{t as b}from"./QBadge-Bh_ovtt9.js";import{t as x}from"./QChip-Bsee2q-S.js";import{t as S}from"./QTd-mJJNUD6x.js";import{t as C}from"./QForm-C4rccd2O.js";import{t as w}from"./QPage-eKZDij2L.js";var T={class:`row my_radio_less q-pa-sm`},E={class:`col-12`},D={class:`col-12 q-mt-sm`},O={class:`col-12`},k={class:`col-12`},A={class:`col-12`},j={class:`col-12`},M={class:`col-12`},N={__name:`DepartmentsPage`,setup(N){let{proxy:P}=s(),F=u([]),I=u(!1),L=u(!1),R=u(!1),z=()=>({id:null,name:``,manager:``,description:``,active:!0}),B=i(z()),V=u(``),H=[{name:`created_at`,label:`#`,field:`id`,align:`left`},{name:`name`,label:`DepartmentName`,field:`name`,align:`left`,sortable:!0},{name:`manager`,label:`Manager`,field:e=>e.manager||`—`,align:`left`,sortable:!0},{name:`designations_count`,label:`Designations`,field:`designations_count`,align:`center`,sortable:!0},{name:`active`,label:`Status`,field:`active`,align:`center`,sortable:!0},{name:`actions`,label:`Actions`,field:`actions`,align:`right`}],U=H.filter(e=>e.name!==`actions`);async function W(){I.value=!0;try{let{data:t}=await e.get(`/departments`);F.value=t}finally{I.value=!1}}function G(){Object.assign(B,z()),R.value=!0}function K(e){let t=F.value.find(t=>t.id===e);t&&(Object.assign(B,{id:t.id,name:t.name,manager:t.manager||``,description:t.description||``,active:!!t.active}),R.value=!0)}async function q(){L.value=!0;try{let t={name:B.name,manager:B.manager,description:B.description,active:B.active};B.id?await e.put(`/departments/`+B.id,t):await e.post(`/departments`,t),m.create({type:`positive`,position:`bottom`,icon:`cloud_done`,message:P.$t(`Saved`)}),R.value=!1,W()}catch(e){m.create({type:`negative`,message:e?.response?.data?.message||`Save failed`})}finally{L.value=!1}}function J(e){P.$delete(`departments/`+e,W)}return t(W),(e,t)=>{let i=n(`m-header`),s=n(`table-stats`),u=n(`action-bar`),m=n(`n-table`),N=n(`m-backgrounds`),P=n(`n-header`),z=n(`n-name`),W=n(`n-submit`),Y=n(`m-modal`);return r(),f(w,null,{default:o(()=>[d(N,null,{default:o(()=>[l(`div`,T,[l(`div`,E,[d(i,{icon:`apartment`,controlRoomButton:`false`,class:`q-mt-xs`},{default:o(()=>[p(a(e.$t(`Departments`)),1)]),_:1})]),l(`div`,D,[d(s,{rows:F.value,"total-label":e.$t(`TotalDepartments`),"total-icon":`apartment`,breakdown:{field:`active`,labels:{true:`Active`,false:`Inactive`},icons:{true:`check_circle`,false:`do_not_disturb_on`}},sums:{field:`designations_count`,label:`Designations`,icon:`badge`}},null,8,[`rows`,`total-label`])]),d(u,{rows:F.value,columns:c(U),filename:`departments`,"create-perm":`department-create`,onAdd:G,"onUpdate:filtered":()=>{}},null,8,[`rows`,`columns`]),l(`div`,O,[d(m,{"config-key":`page.departments`,loading:I.value,data:F.value,columns:H,filter:V.value,"onUpdate:filter":t[0]||=e=>V.value=e,can_edit:`department-edit`,can_delete:`department-delete`,noInfo:!0,onEdit:K,onDel:J},{"body-cell-designations_count":o(e=>[d(S,{props:e,class:`text-center`},{default:o(()=>[d(b,{color:`blue-grey-2`,"text-color":`blue-grey-9`},{default:o(()=>[p(a(e.row.designations_count??0),1)]),_:2},1024)]),_:2},1032,[`props`])]),"body-cell-active":o(t=>[d(S,{props:t,class:`text-center`},{default:o(()=>[d(x,{dense:``,size:`sm`,color:t.row.active?`positive`:`grey`,"text-color":`white`},{default:o(()=>[p(a(t.row.active?e.$t(`Active`):e.$t(`Inactive`)),1)]),_:2},1032,[`color`])]),_:2},1032,[`props`])]),_:1},8,[`loading`,`data`,`filter`])])])]),_:1}),d(Y,{showCM:R.value,"onUpdate:showCM":t[5]||=e=>R.value=e,card_style:`width: 440px`},{default:o(()=>[d(_,{class:`bg-white`},{default:o(()=>[d(P,{icon:`apartment`},{default:o(()=>[p(a(B.id?e.$t(`Edit`):e.$t(`AddNew`))+` — `+a(e.$t(`Department`)),1)]),_:1}),d(y),d(C,{onSubmit:q},{default:o(()=>[d(h,{class:`row q-col-gutter-sm`},{default:o(()=>[l(`div`,k,[d(z,{name:B.name,"onUpdate:name":t[1]||=e=>B.name=e,icon:`apartment`,label:e.$t(`DepartmentName`),autofocus:``},null,8,[`name`,`label`])]),l(`div`,A,[d(z,{name:B.manager,"onUpdate:name":t[2]||=e=>B.manager=e,icon:`person`,label:e.$t(`Manager`),rules:[]},null,8,[`name`,`label`])]),l(`div`,j,[d(g,{outlined:``,dense:``,color:`primary`,type:`textarea`,autogrow:``,modelValue:B.description,"onUpdate:modelValue":t[3]||=e=>B.description=e,label:e.$t(`Description`)},null,8,[`modelValue`,`label`])]),l(`div`,M,[d(v,{modelValue:B.active,"onUpdate:modelValue":t[4]||=e=>B.active=e,label:e.$t(`Active`),color:`primary`},null,8,[`modelValue`,`label`])])]),_:1}),d(y),d(W,{submitting:L.value,label:e.$t(`Save`)},null,8,[`submitting`,`label`])]),_:1})]),_:1})]),_:1},8,[`showCM`])]),_:1})}}};export{N as default};