import{m as F,bV as j,bW as E,o as H,w as N,bm as P,bn as R,af as p,at as S,ah as o,d as l,ak as b,bJ as W,al as w,V as m,X,E as f,aj as g,am as A,an as v,ag as k,B as y,as as C,Q as Y,bS as J,ap as x,ai as V,ar as M,bE as K,F as G,aq as Z,aN as ee,aL as q,aM as ae,C as le,bX as te}from"./index.03f6cb25.js";import{Q as se}from"./QTd.99c7ac73.js";import{Q as oe}from"./QTable.8088f316.js";import{h as T}from"./moment.ec5cec00.js";import{u as ne}from"./use-dialog-plugin-component.4505e51a.js";const ie={key:0,class:"q-gutter-md"},re={key:1,class:"q-gutter-md"},de={class:"row"},he={__name:"select",props:{field:{type:Object,default:{}},readOnly:{type:Boolean,default:!1},selected:{type:Array,default:[]}},setup($){var Q;const d=$,{dialogRef:O,onDialogOK:B}=ne(),e=F({pagination:{rowsPerPage:100},showSelect:!1,expand:!1,columns:[],model:j((Q=d.field)==null?void 0:Q.relationTo),loading:!1,search:null,includes:[],checkArray:[],colors:[],selected:[],items:[],rws:[]});U(),E(n=>!1),H(async()=>{var n;await _(),(n=d.selected)!=null&&n.length&&(e.showSelect=!0)}),N(()=>e.showSelect,n=>{D(n)});async function D(n){if(e.loading=!0,e.items=[],n)for await(var s of e.rws)for await(var i of d.selected)i==s.id&&e.items.push(s);else e.items=[...e.rws];e.loading=!1}function L(n,s){var t,u;var i=te((t=d.field)==null?void 0:t.relationTo,n)||"";return i=((u=i==null?void 0:i.admin)==null?void 0:u.label)||(i==null?void 0:i.name)||null,i||(i=n),i}function U(){var i,t,u;var n=[];if((i=e.model.fields)!=null&&i.length&&(e.model.fields.map(a=>{var h,c;if(!a.type.toLowerCase().match(/(json|media|map|relationship)/))return a.type.toLowerCase().match(/(select)/)?n.push({label:(((h=a==null?void 0:a.admin)==null?void 0:h.label)||a.name).toUpperCase(),name:a.name,field:r=>{if(a.hasMany)return r[a.name].map(I=>I+`
,`);r[a.name]},align:"center",headerClasses:" ",classes:r=>(r[a.name],"")}):(a.type=="colour"&&e.colors.push("body-cell-"+a.name),a.type=="boolean"&&e.checkArray.push("body-cell-"+a.name),n.push({label:(((c=a==null?void 0:a.admin)==null?void 0:c.label)||a.name).toUpperCase(),name:a.name,field:r=>r[a.name],align:(a.type=="boolean","center"),headerClasses:a.type=="boolean"?"text-center":"",sortable:!0}))}),e.model.timestamps)){var s=(u=(t=e.model)==null?void 0:t.admin)!=null&&u.timestampsFormat?e.model.admin.timestampsFormat:"YY-MM-DD ,HH:mm:ss a";n.push({label:"CreatedAt",name:"createdAt",field:a=>T(a.createdAt).format(s),align:"left",headerClasses:" ",sortable:!0,style:{}}),n.push({label:"UpdatedAt",name:"updatedAt",field:a=>T(a.updatedAt).format(s),align:"left",headerClasses:" ",sortable:!0,style:{}})}e.columns=n}async function _(){e.loading=!0,e.selected=[];var n={};e.model.fields.map(a=>{a.type=="relationship"&&(n[a.name]=!0)});var s=await P.findMany(e.model.slug,{include:n}).then(a=>a).catch(a=>[]),i=[];e.model.fields.map(a=>{(a.type=="relationship"||a.hasMany)&&(i.push(a.name),i.push(a.name+"Ids"),i.push(a.name+"Id"))}),e.rws=e.items=s;for await(var t of e.items)for await(var u of d.selected)u==t.id&&e.selected.push(t);e.loading=!1}function z(){B(e.selected)}return(n,s)=>{const i=R("q-smart-reactif");return p(),S(M,{maximized:"","full-height":"",position:"right",ref_key:"dialogRef",ref:O},{default:o(()=>[l(b,{class:"q-pa-md bg-black",style:W({minWidth:e.expand?"80vw":"50vw",maxWidth:"75vw",width:"auto"})},{default:o(()=>[l(w,{class:"q-pa-none"},{default:o(()=>[l(m,{flat:"",round:"",outline:"",onClick:s[0]||(s[0]=t=>e.expand=!e.expand),icon:e.expand?"las la-expand":"las la-expand-arrows-alt"},{default:o(()=>[l(X,null,{default:o(()=>[f(g(e.expand?"minimize":"Maximize"),1)]),_:1})]),_:1},8,["icon"]),l(A,{class:"text-capitalize text-bold"},{default:o(()=>[f(g(d.field.label||d.field.name),1)]),_:1}),l(v),d.readOnly?(p(),k("div",re,[l(m,{to:`/espace/collections/${e.model.slug}`,label:"Manage",outline:"",icon:"las la-external-link-alt"},null,8,["to"]),y(l(m,{flat:"",icon:"mdi-close"},null,512),[[C]])])):(p(),k("div",ie,[l(m,{outline:"",onClick:s[1]||(s[1]=t=>_()),round:"",icon:"mdi-sync"}),y(l(m,{outline:"",round:"",icon:"mdi-close"},null,512),[[C]]),l(m,{onClick:s[2]||(s[2]=t=>z()),color:"green",round:"",icon:"mdi-check"})]))]),_:1}),l(w,null,{default:o(()=>[l(Y,{dense:"",standout:"",style:{"min-width":"400px"},modelValue:e.search,"onUpdate:modelValue":s[3]||(s[3]=t=>e.search=t),type:"text",color:"secondary",clearable:"",label:"Search...."},null,8,["modelValue"]),l(v),l(J,{color:"secondary",modelValue:e.showSelect,"onUpdate:modelValue":s[4]||(s[4]=t=>e.showSelect=t),label:"Selected Only"},null,8,["modelValue"])]),_:1}),l(x,{class:"scroll q-pa-xs",style:{height:"83vh"}},{default:o(()=>[l(b,{flat:""},{default:o(()=>[l(oe,{dark:"",class:"border-2 shadow-lg bg-dark text-white table-ui",color:"green",selected:e.selected,"onUpdate:selected":s[5]||(s[5]=t=>e.selected=t),selection:d.field.hasMany?"multiple":"single",separator:"cell","rows-per-page-options":[100,200],filter:e.search,"row-key":"id","virtual-scroll":"",pagination:e.pagination,"onUpdate:pagination":s[6]||(s[6]=t=>e.pagination=t),"virtual-scroll-slice-size":200,columns:e.columns,rows:e.items||[],loading:e.loading,style:{height:"80vh"}},{"body-cell-actions":o(t=>[l(se,{props:t},{default:o(()=>[V("div",null,[V("div",de,[l(i,null,{default:o(({active:u,toggle:a,close:h})=>[l(m,{onClick:c=>a(),color:"primary",round:"",dense:"",icon:"mdi-information-variant"},null,8,["onClick"]),l(M,{onHide:h,"model-value":u},{default:o(()=>[l(b,null,{default:o(()=>[l(w,{class:"q-mx-sm"},{default:o(()=>[l(A,{shrink:""},{default:o(()=>[f(" All d\xE9tails ")]),_:1}),l(v),y(l(m,{round:"",flat:"",icon:"mdi-close"},null,512),[[C]])]),_:1}),l(x,null,{default:o(()=>[l(K,{separator:""},{default:o(()=>[(p(!0),k(G,null,Z(Object.keys(t.row),(c,r)=>y((p(),S(ee,{key:r},{default:o(()=>[l(q,{side:""},{default:o(()=>[l(ae,{class:"text-bold text-black"},{default:o(()=>[f(g(L(c,t.row[c]))+" : ",1)]),_:2},1024)]),_:2},1024),l(q,null,{default:o(()=>[f(g(t.row[c]),1)]),_:2},1024)]),_:2},1024)),[[le,c!=="actions"]])),128))]),_:2},1024)]),_:2},1024),l(x)]),_:2},1024)]),_:2},1032,["onHide","model-value"]),f(" \xA0 \xA0 "),l(m,{onClick:c=>{var r;return n.$router.push(`/espace/collections/edit/${e.model.slug}?ref=${(r=t.row)==null?void 0:r.id}`)},round:"",dense:"",icon:"las la-link"},null,8,["onClick"])]),_:2},1024)])])]),_:2},1032,["props"])]),_:1},8,["selected","selection","filter","pagination","columns","rows","loading"])]),_:1})]),_:1})]),_:1},8,["style"])]),_:1},512)}}};export{he as _};
