import{bl as V,bj as I,bk as S,bs as T,m as M,bV as y,w as q,o as A,bm as k,af as m,at as c,ah as n,d as l,am as B,aG as C,E as L,aj as U,an as N,ai as h,V as d,bt as b,u as p,Q as j,cc as R,aq as z}from"./index.be232763.js";import{Q as D}from"./QChip.2457f813.js";import{Q}from"./QToolbar.43a05fe2.js";import{Q as v}from"./QTd.a81b2610.js";import{Q as E}from"./QTable.d3c81ebb.js";import{Q as O}from"./QPage.0cbc0a46.js";import{b as w}from"./route-block.7fdbc26a.js";import"./QSelect.0d341834.js";import"./QMenu.a42a1840.js";import"./rtl.87fd3dfc.js";import"./QLinearProgress.7b5ceadd.js";const G={class:"q-gutter-md"},P={class:"q-pt-lg"},F={class:"q-gutter-md"},H={__name:"[model]",setup(J){V();const u=I(),x=S(),i=T(),a=M({checkArray:[],search:null,selected:[],loading:!1,items:[],model:y(i.params.model),columns:[]});q(()=>i.params.model,()=>{g()}),A(()=>{g()});function g(){a.model=y(i.params.model),f(),_()}async function f(){a.loading=!0;var o={};a.model.fields.map(e=>{e.type=="relationship"&&(o[e.name]=!0)});var t=await k.findMany(i.params.model,{include:{...o}}).catch(()=>[]).then(e=>e);a.items=t,a.loading=!1}function _(){var t;var o=[];o.push({label:"Id",name:"id",align:"left",field:e=>e.id}),(t=a.model.fields)!=null&&t.length&&a.model.fields.map(e=>{if(!e.name.toLowerCase().match(/(permissions|description|admin_access)/)&&!e.type.toLowerCase().match(/(json)/)&&!e.type.toLowerCase().match(/(relationship)/))return e.type=="relationship"&&e.hasMany?o.push({label:(e.label||e.name).toUpperCase(),name:e.name,field:s=>{var r;return s?`${((r=s[e.name])==null?void 0:r.length)||0} Item(s)`:""},align:"left",headerClasses:"text-bold "}):e.type=="relationship"&&!e.hasMany?o.push({label:(e.label||e.name).toUpperCase(),name:e.name,field:s=>s?"1 Item(s)":"",align:"left",headerClasses:"text-bold "}):(e.type=="boolean"&&a.checkArray.push("body-cell-"+e.name),o.push({label:(e.label||e.name).toUpperCase(),name:e.name,field:s=>s[e.name],align:"left",headerClasses:"text-bold "}))}),o.push({name:"actions",label:"ABILITIES"}),a.columns=o}async function $(){u.dialog({message:"Do you want to delete ?",ok:{label:"delete",color:"negative",push:!0},cancel:"Annuler"}).onOk(async()=>{var o=a.selected.map(t=>t.id);u.loading.show(),await k.deleteMany(a.model.slug,{where:{id:{in:o}}}).catch(),f(),u.loading.hide()})}return(o,t)=>(m(),c(O,{padding:""},{default:n(()=>[l(Q,null,{default:n(()=>{var e;return[l(B,{class:"text-capitalize text-bold"},{default:n(()=>[l(D,{outline:""},{default:n(()=>{var s,r;return[l(C,{name:"mdi-chevron-right"}),L(" "+U(((s=a.model)==null?void 0:s.label)||((r=a.model)==null?void 0:r.slug)),1)]}),_:1})]),_:1}),l(N),h("div",G,[a.selected.length?(m(),c(d,{key:0,color:"red",outline:"",onClick:t[0]||(t[0]=s=>$()),"fab-mini":"",icon:"las la-trash"})):b("",!0),l(d,{class:"bg-white text-primary",onClick:t[1]||(t[1]=s=>f()),"fab-mini":"",icon:"las la-sync"}),a.selected.length==1?(m(),c(d,{key:1,class:"bg-white text-primary","fab-mini":"",to:`/espace/settings/permissions/edit/${p(i).params.model}?ref=${(e=a.selected[0])==null?void 0:e.id}`,icon:"las la-pen"},null,8,["to"])):b("",!0),l(d,{to:`/espace/settings/permissions/create/${p(i).params.model}`,"fab-mini":"",color:"secondary",icon:"mdi-plus"},null,8,["to"])])]}),_:1}),l(Q,null,{default:n(()=>[l(j,{dense:"",standout:"",modelValue:a.search,"onUpdate:modelValue":t[2]||(t[2]=e=>a.search=e),label:"Search ...."},null,8,["modelValue"])]),_:1}),h("div",P,[l(E,{onRowClick:t[3]||(t[3]=(e,s)=>p(x).push(`/espace/settings/permissions/edit/${p(i).params.model}?ref=${s==null?void 0:s.id}`)),color:"secondary",selected:a.selected,"onUpdate:selected":t[4]||(t[4]=e=>a.selected=e),selection:"multiple",separator:"cell",dark:"",filter:a.search,"rows-per-page-options":[100,200],class:"box border-2 text-white",columns:a.columns,rows:a.items,loading:a.loading,flat:"",style:{height:"70vh"}},R({"body-cell-actions":n(e=>[l(v,{props:e},{default:n(()=>[h("div",F,[l(d,{outline:"",icon:"las la-tasks"})])]),_:2},1032,["props"])]),_:2},[z(a.checkArray,e=>({name:e,fn:n(s=>[l(v,{props:s},{default:n(()=>[s.value?(m(),c(C,{key:0,size:"md",color:"green",name:"mdi-check-circle"})):b("",!0)]),_:2},1032,["props"])])}))]),1032,["selected","filter","columns","rows","loading"])])]),_:1}))}};typeof w=="function"&&w(H);export{H as default};
