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,c,et as l,h as u,l as d,m as f}from"./runtime-core.esm-bundler-Babufkcf.js";import{I as p,c as m,l as h,n as g,o as _}from"./index-uCtpzrM3.js";import{t as v}from"./QChip-Bsee2q-S.js";import{t as y}from"./QTd-mJJNUD6x.js";import{t as b}from"./QForm-C4rccd2O.js";import{t as x}from"./QPage-eKZDij2L.js";var S={class:`row my_radio_less q-pa-sm`},C={class:`col-12`},w={class:`col-12 q-mt-sm`},T={class:`col-12`},E={class:`col-12 col-sm-6`},D={class:`col-12 col-sm-6`},O={class:`col-12 col-sm-6 flex items-center`},k={class:`col-12`},A={__name:`BranchesPage`,setup(A){let{proxy:j}=s(),M=l([]),N=l(!1),P=l(!1),F=l(!1),I=l(null),L=l(``),R=l([]),z=()=>({name:``,address:``,phone:``,active:!0}),B=i(z()),V=[{name:`created_at`,label:`#`,field:`id`,align:`left`},{name:`name`,label:`Name`,field:`name`,align:`left`,sortable:!0},{name:`address`,label:`Address`,field:`address`,align:`left`},{name:`phone`,label:`Phone`,field:`phone`,align:`left`},{name:`active`,label:`Status`,field:`active`,align:`center`},{name:`actions`,label:`Actions`,field:`actions`,align:`right`}];function H(){Object.assign(B,z())}async function U(){N.value=!0;try{let{data:t}=await e.get(`/branches`);M.value=t}finally{N.value=!1}}function W(){I.value=null,H(),F.value=!0}function G(e){let t=M.value.find(t=>t.id===e);t&&(I.value=e,Object.assign(B,{name:t.name,address:t.address,phone:t.phone,active:!!t.active}),F.value=!0)}async function K(){P.value=!0;try{I.value?await e.put(`/branches/${I.value}`,B):await e.post(`/branches`,B),p.create({type:`positive`,position:`bottom`,icon:`cloud_done`,message:j.$t(`SavedSuccessfully`)}),F.value=!1,U()}catch(e){p.create({type:`negative`,message:e?.response?.data?.message||`Save failed`})}finally{P.value=!1}}function q(e){j.$delete(`branches/${e}`,U)}return t(U),(e,t)=>{let i=n(`m-header`),s=n(`table-stats`),l=n(`action-bar`),p=n(`n-table`),A=n(`m-backgrounds`),j=n(`n-header`),z=n(`n-name`),U=n(`n-submit`),J=n(`m-modal`);return r(),d(x,null,{default:o(()=>[u(A,null,{default:o(()=>[c(`div`,S,[c(`div`,C,[u(i,{icon:`store`,controlRoomButton:`false`,class:`q-mt-xs`},{default:o(()=>[f(a(e.$t(`Branches`)),1)]),_:1})]),c(`div`,w,[u(s,{rows:R.value,"total-label":e.$t(`TotalBranches`),"total-icon":`store`,breakdown:{field:`active`,labels:{true:`Active`,false:`Inactive`},icons:{true:`check_circle`,false:`do_not_disturb_on`}}},null,8,[`rows`,`total-label`])]),u(l,{rows:M.value,columns:V,filename:`branches`,"create-perm":`branch-create`,onAdd:W,"onUpdate:filtered":t[0]||=e=>R.value=e},null,8,[`rows`]),c(`div`,T,[u(p,{"config-key":`page.branches`,loading:N.value,data:R.value,columns:V,filter:L.value,"onUpdate:filter":t[1]||=e=>L.value=e,can_edit:`branch-edit`,can_delete:`branch-delete`,onEdit:G,onDel:q},{"body-cell-active":o(t=>[u(y,{props:t},{default:o(()=>[u(v,{dense:``,color:t.row.active?`positive`:`grey`,"text-color":`white`,label:t.row.active?e.$t(`Active`):e.$t(`Inactive`)},null,8,[`color`,`label`])]),_:2},1032,[`props`])]),_:1},8,[`loading`,`data`,`filter`])])])]),_:1}),u(J,{showCM:F.value,"onUpdate:showCM":t[6]||=e=>F.value=e,card_style:`width: 480px`},{default:o(()=>[u(h,{class:`bg-white`},{default:o(()=>[u(j,{icon:`store`},{default:o(()=>[f(a(I.value?e.$t(`Edit`):e.$t(`AddNew`))+` — `+a(e.$t(`Branch`)),1)]),_:1}),u(_),u(b,{onSubmit:K,onReset:H},{default:o(()=>[u(m,{class:`row q-col-gutter-sm`},{default:o(()=>[c(`div`,E,[u(z,{name:B.name,"onUpdate:name":t[2]||=e=>B.name=e,icon:`store`,label:e.$t(`Name`),autofocus:``},null,8,[`name`,`label`])]),c(`div`,D,[u(z,{name:B.phone,"onUpdate:name":t[3]||=e=>B.phone=e,icon:`phone`,label:e.$t(`Phone`),rules:[]},null,8,[`name`,`label`])]),c(`div`,O,[u(g,{modelValue:B.active,"onUpdate:modelValue":t[4]||=e=>B.active=e,label:e.$t(`Active`),color:`primary`},null,8,[`modelValue`,`label`])]),c(`div`,k,[u(z,{name:B.address,"onUpdate:name":t[5]||=e=>B.address=e,icon:`home`,label:e.$t(`Address`),rules:[]},null,8,[`name`,`label`])])]),_:1}),u(_),u(U,{submitting:P.value,label:e.$t(`Save`)},null,8,[`submitting`,`label`])]),_:1})]),_:1})]),_:1},8,[`showCM`])]),_:1})}}};export{A as default};