import{$ as e,A as t,E as n,J as r,O as i,R as a,_ as o,c as s,d as c,f as l,h as u,m as d,p as f,rt as p,v as m,y as h}from"./vue.runtime.esm-bundler-CjdjpSmT.js";import{mt as g,n as _}from"./http-D9STgMoF.js";import{c as v,l as y}from"./ripple-CpIKAP0g.js";import{a as b}from"./index-DMZetZXm.js";import{t as x}from"./button-BF7S0BMD.js";import{t as S}from"./message-ByS0PJCC.js";import{i as C,t as w}from"./checkbox-9KQXWdTC.js";import{t as T}from"./datepicker-DdxqacGM.js";var E={class:`max-w-4xl`},D={class:`text-2xl font-bold mb-2`},O={class:`text-sm text-gray-600 mb-4`},k={class:`bg-white p-6 rounded-lg shadow space-y-4`},A={class:`grid grid-cols-2 gap-4`},j={class:`flex flex-col gap-1`},M={class:`flex flex-col gap-1`},N={class:`grid grid-cols-2 gap-4`},P={class:`font-semibold capitalize text-sm mb-2`},F={class:`space-y-1`},I=[`for`],L={key:0,class:`text-xs ms-1 opacity-60`},R={class:`flex gap-2 justify-end pt-4`},z=h({__name:`Modules`,setup(h){let{locale:z}=g(),B=v(),V=y(),H=b(),U=r([]),W=r(null),G=r([]),K=r(null),q=r(null),J=r(!1),Y=r(null),X=c(()=>{let e={};return U.value.forEach(t=>{(e[t.group]??=[]).push(t)}),e});function Z(e){return z.value===`ar`?e.name_ar:e.name_en}n(async()=>{let e=B.params.id,[t,n]=await Promise.all([_.get(`/api/admin/modules-catalog`),_.get(`/api/admin/tenants/${e}`)]);U.value=t.data.data,W.value=n.data,G.value=n.data.enabled_modules??[],K.value=n.data.seat_limit??null,q.value=n.data.license_expires_at?new Date(n.data.license_expires_at):null});async function Q(){J.value=!0,Y.value=null;try{let e=B.params.id;await _.put(`/api/admin/tenants/${e}/modules`,{enabled_modules:G.value}),await _.put(`/api/admin/tenants/${e}/license`,{seat_limit:K.value,license_expires_at:q.value instanceof Date?q.value.toISOString().slice(0,10):null}),H.add({severity:`success`,summary:`Saved`,life:2e3}),V.push({name:`tenants.index`})}catch(e){Y.value=e.response?.data?.message??`Failed`}finally{J.value=!1}}return(n,r)=>(i(),u(`div`,E,[l(`h1`,D,p(W.value?.name??`...`),1),l(`div`,O,p(W.value?.id),1),Y.value?(i(),f(e(S),{key:0,severity:`error`,closable:!1},{default:a(()=>[o(p(Y.value),1)]),_:1})):d(``,!0),l(`div`,k,[r[6]||=l(`h2`,{class:`font-semibold`},`License`,-1),l(`div`,A,[l(`div`,j,[r[4]||=l(`label`,{class:`text-sm`},`Seat Limit`,-1),m(e(C),{modelValue:K.value,"onUpdate:modelValue":r[0]||=e=>K.value=e,useGrouping:!1},null,8,[`modelValue`])]),l(`div`,M,[r[5]||=l(`label`,{class:`text-sm`},`License Expires At`,-1),m(e(T),{modelValue:q.value,"onUpdate:modelValue":r[1]||=e=>q.value=e,dateFormat:`yy-mm-dd`},null,8,[`modelValue`])])]),r[7]||=l(`h2`,{class:`font-semibold pt-4 border-t`},`Enabled Modules`,-1),l(`div`,N,[(i(!0),u(s,null,t(X.value,(n,a)=>(i(),u(`div`,{key:a,class:`border rounded p-3`},[l(`div`,P,p(a),1),l(`div`,F,[(i(!0),u(s,null,t(n,t=>(i(),u(`div`,{key:t.key,class:`flex items-center gap-2 text-sm`},[m(e(w),{modelValue:G.value,"onUpdate:modelValue":r[2]||=e=>G.value=e,inputId:`m-${t.key}`,value:t.key,disabled:t.core},null,8,[`modelValue`,`inputId`,`value`,`disabled`]),l(`label`,{for:`m-${t.key}`},[o(p(Z(t)),1),t.core?(i(),u(`span`,L,`(core)`)):d(``,!0)],8,I)]))),128))])]))),128))]),l(`div`,R,[m(e(x),{label:`Cancel`,severity:`secondary`,onClick:r[3]||=t=>e(V).back()}),m(e(x),{label:`Save`,loading:J.value,onClick:Q},null,8,[`loading`])])])]))}});export{z as default};
//# sourceMappingURL=Modules-CZQlnf1A.js.map