import{bj as F,m as N,o as j,w as p,bm as h,bU as L,af as i,at as k,ah as s,d as t,ak as x,ag as d,bJ as U,B as A,V as c,as as E,bt as Q,am as w,aG as P,E as r,ai as n,aj as u,an as y,Q as G,ap as J,F as C,aq as V,aL as K,aM as g,al as q,au as W,u as S,ar as H}from"./index.be232763.js";import{Q as $}from"./QToolbar.43a05fe2.js";import{Q as X}from"./QChip.2457f813.js";import{Q as B,f as Y,_ as Z}from"./uploadFile.da78306f.js";import{Q as ee}from"./QImg.0dc9cac2.js";import{Q as te}from"./QScrollArea.eee9b08f.js";import{u as ae}from"./use-dialog-plugin-component.030f64f6.js";import{b as I}from"./route-block.7fdbc26a.js";const se=n("br",null,null,-1),le={class:"text-caption"},oe={class:"q-gutter-md"},ie={class:"q-py-sm text-bold"},ne={key:0},de={key:1},re={class:"row justify-start text-center"},ce=["onClick"],ue={class:"text-center q-mx-lg"},me={__name:"modalLibrary",props:{field:{}},setup(M){const b=M,f=F(),{dialogRef:O,onDialogOK:z}=ae(),e=N({loading:!1,search:null,selected:[],files:[],isReady:!1,isOpen:!1});console.log("Field",b.field),j(()=>{m()}),p(()=>e.selected,()=>{!b.field.hasMany&&e.selected.length>1&&e.selected.shift()}),p(()=>e.isOpen,o=>{o?setTimeout(()=>{e.isReady=!0},400):e.isReady=!1}),p(()=>e.search,()=>{m()});async function R(){f.loading.show(),await h.deleteMany("medias",{where:{id:{in:e.selected}}}).catch().then(o=>{e.selected=[]}),m(),f.loading.hide()}async function m(){e.loading=!0;var o={filename:{contains:e.search}};e.files=await h.findMany("medias",{orderBy:{createdAt:"desc"},where:{...L(o)}}).then(a=>a).catch(a=>[]),console.log(e.files),e.loading=!1}function T(){f.dialog({component:Z}).onOk(o=>{o.hasMany?o.data.map(a=>{e.files.unshift(a)}):e.files.unshift(o.data)})}function D(){z(e.selected)}return(o,a)=>(i(),k(H,{class:"",modelValue:e.isOpen,"onUpdate:modelValue":a[6]||(a[6]=l=>e.isOpen=l),maximized:"",position:"right",ref_key:"dialogRef",ref:O,padding:""},{default:s(()=>[t(x,{style:{"min-width":"65vw"},class:"bg-black"},{default:s(()=>[e.isReady?(i(),d("div",{key:0,style:U(`${e.isOpen?`
          margin-left: -6%;
          margin-top: 1.4%;
          z-index: 9999;
          position: fixed;
          top: 0;
          transition: 0.4s;`:"display:none"}`)},[A(t(c,{round:"",color:"white","text-color":"black",icon:"mdi-close"},null,512),[[E]])],4)):Q("",!0),t($,{class:"q-py-md"},{default:s(()=>[t(w,{class:"text-bold"},{default:s(()=>[t(P,{name:"mdi-folder"}),r(" File library "),se,n("span",le,u(e.files.length)+" Item(s) ",1)]),_:1}),t(y),n("div",oe,[e.selected.length?(i(),k(c,{key:0,color:"red",outline:"",onClick:a[0]||(a[0]=l=>R()),flat:"","fab-mini":"",icon:"las la-trash"})):Q("",!0),t(c,{class:"bg-white text-primary",onClick:a[1]||(a[1]=l=>m()),"fab-mini":"",icon:"las la-sync"}),t(c,{onClick:a[2]||(a[2]=l=>D()),"fab-mini":"",color:"secondary",icon:"mdi-check"})])]),_:1}),t($,{class:"q-pt-md"},{default:s(()=>[t(G,{outlined:"",color:"secondary",dense:"",style:{"min-width":"30vw"},modelValue:e.search,"onUpdate:modelValue":a[3]||(a[3]=l=>e.search=l),label:"Search ...."},null,8,["modelValue"]),t(y),t(c,{"text-color":"white",color:"dark",onClick:a[4]||(a[4]=l=>T()),outline:"",label:"New media",icon:"mdi-plus"})]),_:1}),t(J,null,{default:s(()=>[n("div",ie,[t(X,{dark:"",color:"green"},{default:s(()=>[r(u(e.selected.length),1)]),_:1}),r(" Item(s) selected ")]),t(te,{style:{height:"70vh"},class:"scroll rounded-borders"},{default:s(()=>[e.loading?(i(),d("div",ne,[(i(),d(C,null,V(10,l=>t(K,null,{default:s(()=>[t(g,null,{default:s(()=>[t(B,{type:"text"})]),_:1}),t(g,{caption:""},{default:s(()=>[t(B,{type:"text"})]),_:1})]),_:1})),64))])):(i(),d("div",de,[n("div",re,[(i(!0),d(C,null,V(e.files,(l,_)=>(i(),d("div",{class:"col-12 col-sm-6 col-md-4 col-lg-3",key:_},[t(x,{flat:"",style:{height:"250px"},class:"q-ma-xs overflow-hidden relative-position box"},{default:s(()=>[t(q,{class:"q-pa-none q-ma-none"},{default:s(()=>[t(W,{size:"lg",ref_for:!0,ref:"cc",color:"green","unchecked-icon":"mdi-circle-outline","checked-icon":"mdi-check-circle-outline",val:l,modelValue:e.selected,"onUpdate:modelValue":a[5]||(a[5]=v=>e.selected=v)},null,8,["val","modelValue"])]),_:2},1024),n("div",{class:"overflow-hidden cursor-pointer relative-position q-pa-md",style:{"border-radius":"20px"},onClick:v=>o.$refs.cc[_].toggle()},[t(ee,{class:"rounded-borders overflow-hidden",height:"100px","no-spinner":"",width:"100%",fit:"cover",src:S(h).assets(l.filedisk,{transform:!0,q:40})},null,8,["src"])],8,ce),n("div",ue,[t(g,{lines:1},{default:s(()=>[r(u(l.filename),1)]),_:2},1024)]),t(q,{class:"text-bold text-caption text-grey"},{default:s(()=>[t(w,{class:"text-caption"},{default:s(()=>[r(u(l.details.mimeType),1)]),_:2},1024),t(y),r(" "+u(S(Y)(l.details.size,{base:2,standard:"jedec"})),1)]),_:2},1024)]),_:2},1024)]))),128))])]))]),_:1})]),_:1})]),_:1})]),_:1},8,["modelValue"]))}};typeof I=="function"&&I(me);export{me as _};
