1import{F as M,r as f,j as e,s as y,t as a}from"./index-gDp6BZsQ.js";import{u as o,a as q}from"./useQuery-DqikFouE.js";import{p as C,q as z,r as U}from"./cms.functions-BmuwLtQJ.js";import{B as d}from"./button-e9hwpVEs.js";import{c as g}from"./createLucideIcon-Ddoih0xO.js";import{T as F}from"./trash-2-y9XYJuP8.js";import"./admin-guard-B9FwSDmI.js";import"./index-BHcVkXR_.js";import"./index-LHNt3CwB.js";import"./utils-BQHNewu7.js";const K=[["rect",{width:"14",height:"14",x:"8",y:"8",rx:"2",ry:"2",key:"17jyea"}],["path",{d:"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2",key:"zix9uf"}]],L=g("copy",K);const Q=[["path",{d:"M12 3v12",key:"1x0j5s"}],["path",{d:"m17 8-5-5-5 5",key:"7q97r8"}],["path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4",key:"ih7n3h"}]],R=g("upload",Q);function I(){const l=M(),j=o(C),v=o(z),b=o(U),{data:m,isLoading:u}=q({queryKey:["admin-media"],queryFn:()=>j()}),i=f.useRef(null),[p,x]=f.useState(!1);async function N(t){const s=t.target.files?.[0];if(s){x(!0);try{const r=s.name.split(".").pop()??"bin",c=`${Date.now()}-${Math.random().toString(36).slice(2,8)}.${r}`,n=s.type.startsWith("video/")?"videos":s.type.startsWith("image/")?"media":"documents",{error:h}=await y.storage.from(n).upload(c,s,{upsert:!1,contentType:s.type});if(h)throw h;const{data:_}=y.storage.from(n).getPublicUrl(c);await v({data:{url:_.publicUrl,filename:s.name,mime_type:s.type||"application/octet-stream",size_bytes:s.size,bucket:n,storage_path:c}}
1),a.success("Файл загÑÑжен"),l.invalidateQueries({queryKey:["admin-media"]})}catch(r){a.error(r?.message??"ÐÑибка загÑÑзки")}finally{x(!1),i.current&&(i.current.value="")}}}async function k(t){if(confirm("УдалиÑÑ Ñайл из библиоÑеки и Storage?"))try{await b({data:{id:t}}),a.success("Удалено"),l.invalidateQueries({queryKey:["admin-media"]})}catch(s){a.error(s?.message??"ÐÑибка")}}function w(t){navigator.clipboard.writeText(t),a.success("URL ÑкопиÑован")}return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-end justify-between",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-3xl font-bold tracking-tight",children:"Ðедиа"}),e.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:"ÐиблиоÑека Ñайлов: изобÑажениÑ, видео, докÑменÑÑ."})]}),e.jsxs("div",{children:[e.jsx("input",{ref:i,type:"file",hidden:!0,onChange:N,accept:"image/*,video/*,application/pdf"}),e.jsxs(d,{onClick:()=>i.current?.click(),disabled:p,children:[e.jsx(R,{className:"mr-2 h-4 w-4"}),p?"ÐагÑÑзкаâ¦":"ÐагÑÑзиÑÑ"]})]})]}),u&&e.jsx("div",{className:"py-10 text-center text-muted-foreground",children:"ÐагÑÑзкаâ¦"}),!u&&(m??[]).length===0&&e.jsx("div",{className:"py-10 text-center text-muted-foreground",children:"ÐиблиоÑека пÑÑÑа"}),e.jsx("div",{className:"grid gap-4 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4",children:(m??[]).map(t=>e.jsxs("div",{className:"overflow-hidden rounded-lg border border-border/40 bg-card/40",children:[e.jsx("div",{className:"flex h-40 items-center justify-center bg-background/60",children:t.mime_type?.startsWith("image/")?e.jsx("img",{src:t.url,alt:t.alt_text??t.filename,className:"h-full w-full object-cover"}):t.mime_type?.startsWith("video/")?e.jsx("video",{src:t.url,className:"h-full w-full object-cover",muted:!0}):e.jsx("span",{className:"text-xs text-muted-foreground",children:t.mime_type})}),e.jsxs("div",{className:"p-3",children:[e.jsx("div",{className:"truncate text-sm font-medium",children:t.filename}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:[t.bucket," · ",(t.size_bytes??0/1024/1024).toFixed?.(2)??"â","KB"]}),e.jsxs("div",{className:"mt-2 flex justify-end gap-1",children:[e.jsx(d,{size:"sm",variant:"ghost",onClick:()=>w(t.url),children:e.jsx(L,{className:"h-4 w-4"})}),e.jsx(d,{size:"sm",variant:"ghost",onClick:()=>k(t.id),children:e.jsx(F,{className:"h-4 w-4"})})]})]})]},t.id))})]})}export{I as component};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.