import{u as $}from"./BZ7f31ti.js";import{u as x}from"./DKzHUNYh.js";import{u as B,q as D,c as o,a as s,t as c,e as N,d as T,n as U,i as y,F,r as L,l as m,o as i,m as z}from"./BKiFavna.js";import{_ as V}from"./DlAUqK2U.js";const j={class:"page-head"},A={class:"page-hdr"},I={class:"btn-primary upload-label"},M={class:"media-grid"},R=["src"],S={key:1,class:"placeholder"},q={class:"media-info"},E={class:"media-name"},H={class:"media-meta"},K=["onClick"],O=["onClick"],P={key:0,class:"empty"},G={__name:"media",setup(J){const{lang:h}=B(),{api:p,baseURL:_,token:g}=$(),b=x(),d=m([]),l=m(""),n=m("success"),f=z(()=>_.replace("/api","")),r=async()=>{try{const t=await p.get("/admin/media",{limit:100});d.value=t.data.media}catch{}},k=async t=>{const e=t.target.files?.[0];if(!e)return;const a=new FormData;a.append("file",e);try{const v=await(await window.fetch(`${_}/admin/media`,{method:"POST",headers:{Authorization:`Bearer ${g.value}`},body:a})).json();v.success?(l.value="Uploaded!",n.value="success",r()):(l.value=v.message,n.value="error")}catch{l.value="Upload failed",n.value="error"}},w=t=>{const e=`${f.value}${t.file_path}`;navigator.clipboard.writeText(e),l.value="Copied: "+e,n.value="success"},C=async t=>{confirm("Delete?")&&(await p.del(`/admin/media/${t.id}`),r(),b.success("Deleted"))};return D(r),(t,e)=>(i(),o("div",null,[s("div",j,[s("h1",A,c(N(h)==="bn"?"মিডিয়া লাইব্রেরি":"Media Library"),1),s("label",I,[e[0]||(e[0]=s("i",{class:"fas fa-upload"},null,-1)),e[1]||(e[1]=T(" Upload ",-1)),s("input",{type:"file",onChange:k,accept:"image/*,video/*",style:{display:"none"}},null,32)])]),l.value?(i(),o("p",{key:0,class:U(["msg",n.value])},c(l.value),3)):y("",!0),s("div",M,[(i(!0),o(F,null,L(d.value,a=>(i(),o("div",{key:a.id,class:"media-item"},[a.file_type==="image"?(i(),o("img",{key:0,src:`${f.value}${a.file_path}`},null,8,R)):(i(),o("div",S,[...e[2]||(e[2]=[s("i",{class:"fas fa-file"},null,-1)])])),s("div",q,[s("div",E,c(a.original_name),1),s("div",H,c((a.file_size/1024).toFixed(1))+" KB",1),s("button",{onClick:u=>w(a),class:"btn-sm"},"Copy URL",8,K),s("button",{onClick:u=>C(a),class:"btn-sm danger"},"Delete",8,O)])]))),128)),d.value.length?y("",!0):(i(),o("p",P,"No media files yet"))])]))}},Z=V(G,[["__scopeId","data-v-305a80d2"]]);export{Z as default};
