1import{r as l,j as e,b as z,a8 as S}from"./index-Cckbwav6.js";import{A as G,E as B,u as D,I as O}from"./AdminLayout-ChfAxdIe.js";import{A as Y,U as Z,n as q,I as J,l as L,u as X,a as H,T as K}from"./media-upload-vMPf5U4n.js";import{c as V,b as W}from"./social-card.functions-CGOGs-13.js";import{R as M}from"./refresh-cw-DXKYstr3.js";import{P as Q}from"./plus-CekQfsuJ.js";import{c as A}from"./log-out-BrN9qcUB.js";import{L as ee,a as te}from"./loader-circle-B0qTeSn7.js";import{T as ae}from"./trash-2-hCkgxQkR.js";import{C as se}from"./circle-check-2sh90J3e.js";const re=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m15 9-6 6",key:"1uzhvr"}],["path",{d:"m9 9 6 6",key:"z0biqf"}]],ne=A("circle-x",re);const le=[["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"}]],oe=A("copy",le);function ie({src:c,alt:u}){const[m,x]=l.useState(!1);return l.useEffect(()=>{x(!1)},[c]),m?e.jsx("div",{className:"grid aspect-[4/3] place-items-center bg-amber-50 p-3 text-center text-[10px] text-amber-900 dark:bg-amber-950/40 dark:text-amber-200",children:e.jsxs("div",{children:[e.jsx(K,{className:"mx-auto mb-1 h-4 w-4"}),e.jsx("div",{className:"font-semibold",children:"Cannot display"}),e.jsx("a",{href:c,target:"_blank",rel:"noreferrer",className:"mt-1 inline-block underline",children:"Open URL"})]})}):e.jsx("img",{src:c,alt:u,onError:()=>x(!0),className:"aspect-[4/3] w-full object-cover"})}const R={file_url:"",alt_text:"",caption:"",credit:"",source:"",licence:"",usage_notes:""};function ye(){const u=l.useRef(null),[m,x]=l.useState([]),[h,v]=l.useState(!0),[p,E]=l.useState(!1),[j,N]=l.useState(!1),[y,g]=l.useState(!1),[s,d]=l.useState(R),[k,i]=l.useState(null),[w,C]=l.useState(null),a=l.useRef(!1),n=l.useRef(0);async function b(t=!1){if(!a.current){a.current=!0,v(!0),i(null);try{const r=await L(100,0,{force:t});x(r.items),N(r.hasMore),n.current=r.items.length}catch(r){i(r instanceof Error&&r.message.toLowerCase().includes("too many")?"Media library is temporarily busy. Please wait a moment and try again.":r instanceof Error?r.message:"Could not load media library.")}finally{a.current=!1,v(!1)}}}async function P(){if(!(a.current||p||!j)){E(!0),i(null);try{const t=await L(100,n.current);x(r=>{const f=new Set(r.map(_=>_.id));return[...r,...t.items.filter(_=>!f.has(_.id))]}),N(t.hasMore),n.current+=t.items.length}catch(t){i(t instanceof Error?t.message:"Could not load older media.")}finally{E(!1)}}}l.useEffect(()=>{b()},[]);function U(){return{alt_text:s.alt_text,caption:s.caption,credit:s.credit,source:s.source,licence:s.licence,usage_notes:s.usage_notes}}async function I(t){if(t){g(!0),i(null);try{const r=await X(t,U());await b(!0),d(R),u.current&&(u.current.value="")}catch(r){i(r instanceof Error?r.message:"Upload failed.")}finally{g(!1)}}}async function $(){g(!0),i(null);try{const t=await H(s.file_url,U());await b(!0),d(R)}catch(t){i(t instanceof Error?t.message:"Could not add image URL.")}finally{g(!1)}}async function T(t){if(!window.confirm("Delete this media record? The image file may remain in Supabase Storage."))return;const{error:r}=await z.from("media").delete().eq("id",t);r?i(r.message):(x(f=>f.filter(_=>_.id!==t)),j&&(n.current=Math.max(0,n.current-1)))}async function F(t,r){await navigator.clipboard?.writeText(t),C(r),window.setTimeout(()=>C(null),1800)}return e.jsxs(G,{title:"Media library",children:[k&&e.jsx("div",{className:"mb-4 border border-breaking bg-breaking/5 p-2.5 text-xs text-breaking",children:k}),e.jsxs("div",{className:"mb-4 border-l-4 border-amber-500 bg-amber-50 p-3 text-xs text-amber-900 dark:bg-amber-950/40 dark:text-amber-200",children:[e.jsx("strong",{children:"Only upload images you are licensed to use."})," Always record the source and licence (e.g. own work, Unsplash, AP via licence X, Creative Commons BY 4.0). Unlicensed images can lead to copyright claims against the publication."]}),e.jsx(de,{}),e.jsxs("div",{className:"mb-6 border border-border bg-background p-4",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-[10px] font-semibold uppercase tracking-wider text-muted-foreground",children:"Upload image"}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:"Upload JPG, PNG, WebP or GIF images from your computer, then use them as article thumbnails or author profile pictures."})]}),e.jsxs("button",{onClick:()=>{b(!0)},disabled:h||y,className:"inline-flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground disabled:opacity-50",children:[e.jsx(M,{className:"h-3.5 w-3.5"})," Refresh"]})]}),e.jsxs("div",{className:"mt-4 grid gap-2 md:grid-cols-2",children:[e.jsx("input",{placeholder:"Alt text",value:s.alt_text,onChange:t=>d({...s,alt_text:t.target.value}),className:"border border-border bg-background px-2 py-1.5 text-sm"}),e.jsx("input",{placeholder:"Caption",value:s.caption,onChange:t=>d({...s,caption:t.target.value}),className:"border border-border bg-background px-2 py-1.5 text-sm"}),e.jsx("input",{placeholder:"Credit",value:s.credit,onChange:t=>d({...s,credit:t.target.value}),className:"border border-border bg-background px-2 py-1.5 text-sm"}),e.jsx("input",{placeholder:"Source (e.g. own work, agency, Unsplash)",value:s.source,onCh
1ange:t=>d({...s,source:t.target.value}),className:"border border-border bg-background px-2 py-1.5 text-sm"}),e.jsx("input",{placeholder:"Licence (e.g. CC BY 4.0, paid licence)",value:s.licence,onChange:t=>d({...s,licence:t.target.value}),className:"border border-border bg-background px-2 py-1.5 text-sm"}),e.jsx("input",{placeholder:"Usage notes (territory, expiry, restrictions)",value:s.usage_notes,onChange:t=>d({...s,usage_notes:t.target.value}),className:"border border-border bg-background px-2 py-1.5 text-sm"})]}),e.jsxs("div",{className:"mt-4 flex flex-wrap gap-2",children:[e.jsx("input",{ref:u,type:"file",accept:Y.join(","),onChange:t=>{I(t.target.files?.[0])},className:"hidden"}),e.jsxs("button",{onClick:()=>u.current?.click(),disabled:y,className:"inline-flex items-center gap-1 bg-foreground px-3 py-2 text-xs font-bold uppercase tracking-wider text-background hover:bg-breaking disabled:opacity-50",children:[e.jsx(Z,{className:"h-3.5 w-3.5"})," ",y?"Uploadingâ¦":"Choose file from computer"]})]}),e.jsxs("div",{className:"mt-5 border-t border-border pt-4",children:[e.jsx("div",{className:"text-[10px] font-semibold uppercase tracking-wider text-muted-foreground",children:"Or add image by URL"}),e.jsxs("div",{className:"mt-2 grid gap-2 md:grid-cols-[1fr_auto]",children:[e.jsx("input",{placeholder:"https://images.example.com/â¦",value:s.file_url,onChange:t=>d({...s,file_url:t.target.value}),className:"border border-border bg-background px-2 py-1.5 text-sm"}),e.jsxs("button",{onClick:()=>{$()},disabled:y||!s.file_url.trim(),className:"inline-flex items-center gap-1 border border-border px-3 py-1.5 text-xs font-bold uppercase tracking-wider hover:border-foreground disabled:opacity-50",children:[e.jsx(Q,{className:"h-3.5 w-3.5"})," Add URL"]})]})]})]}),h?e.jsx("div",{className:"meta",children:"Loadingâ¦"}):m.length===0?e.jsx(B,{title:"No media yet"}):e.jsx("div",{className:"grid grid-cols-2 gap-3 md:grid-cols-3 lg:grid-cols-4",children:m.map(t=>{const r=q(t.file_url,t.storage_path),f=r.display_url||r.file_url||t.file_url;return e.jsxs("figure",{className:"border border-border bg-background",children:[e.jsx(ie,{src:f,alt:t.alt_text??""}),e.jsxs("figcaption",{className:"p-2.5 text-xs",children:[e.jsx("div",{className:"truncate font-mono text-[10px] text-muted-foreground",children:t.file_name??t.file_url}),t.alt_text&&e.jsxs("div",{className:"mt-1 truncate text-muted-foreground",children:["Alt: ",t.alt_text]}),t.caption&&e.jsx("div",{className:"mt-1 line-clamp-2 text-muted-foreground",children:t.caption}),t.credit&&e.jsxs("div",{className:"text-[10px] text-muted-foreground",children:["© ",t.credit]}),t.source&&e.jsxs("div",{className:"text-[10px] text-muted-foreground",children:["Source: ",t.source]}),t.licence&&e.jsxs("div",{className:"text-[10px] text-muted-foreground",children:["Licence: ",t.licence]}),t.usage_notes&&e.jsxs("div",{className:"text-[10px] text-muted-foreground",children:["Notes: ",t.usage_notes]}),e.jsxs("div",{className:"mt-2 flex gap-3 text-[11px]",children:[e.jsxs("button",{onClick:()=>{F(f,t.id)},className:"inline-flex items-center gap-1 text-muted-foreground hover:text-foreground",children:[w===t.id?e.jsx(oe,{className:"h-3 w-3"}):e.jsx(ee,{className:"h-3 w-3"})," ",w===t.id?"Copied":"Copy URL"]}),e.jsx("a",{href:f,target:"_blank",rel:"noreferrer",className:"inline-flex items-center gap-1 text-muted-foreground hover:text-foreground",children:"Open"}),e.jsx("button",{onClick:()=>{T(t.id)},className:"ml-auto inline-flex items-center gap-1 text-breaking hover:underline",children:e.jsx(ae,{className:"h-3 w-3"})})]})]})]},t.id)})}),!h&&m.length>0&&e.jsxs("div",{className:"mt-6 flex flex-wrap items-center justify-between gap-3 border border-border bg-secondary/40 p-3 text-xs text-muted-foreground",children:[e.jsxs("span",{children:["Showing ",m.length," media item",m.length===1?"":"s",!j&&" â all media loaded"]}),j&&e.jsxs("button",{type:"button",onClick:()=>{P()},disabled:p,className:"inline-flex items-center gap-1 border border-border bg-background px-3 py-1.5 text-xs font-semibold text-foreground hover:border-foreground disabled:opacity-50",children:[p&&e.jsx(te,{className:"h-3.5 w-3.5 animate-spin"}
1),p?"Loading older mediaâ¦":"Load older media"]})]}),e.jsxs("div",{className:"mt-6 border border-border bg-secondary/40 p-3 text-xs text-muted-foreground",children:[e.jsx(J,{className:"mr-1 inline h-3.5 w-3.5"})," Images uploaded here become available inside the article editor and author editor."]})]})}function de(){const c=D(),u=W,m=V,[x,h]=l.useState(null),[v,p]=l.useState([]),[E,j]=l.useState(null),[N,y]=l.useState(null),[g,s]=l.useState(!1),[d,k]=l.useState(!1),i=c.isAdmin||c.roles.includes("editor_in_chief")||c.roles.includes("editor")||c.roles.includes("media_manager");async function w(){k(!0);try{const a=await m();h(a.remaining)}catch(a){S.error(a instanceof Error?a.message:"Failed to load count")}finally{k(!1)}}l.useEffect(()=>{i&&w()},[i]);async function C(a=!1){s(!0),p([]);try{const n=await u({limit:25,force:a});y(n.attempted),j(n.processed),h(n.remaining),p(n.results);const b=n.failed;n.attempted===0?S.success(a?"No published articles with images found.":"No articles needed processing."):b===0?S.success(`${a?"Force regenerated":"Processed"} ${n.processed} article${n.processed===1?"":"s"}. ${n.remaining} remaining.`):S.warning(`${a?"Force regenerated":"Processed"} ${n.processed}/${n.attempted}. ${b} failed. ${n.remaining} remaining.`)}catch(n){S.error(n instanceof Error?n.message:"Backfill failed")}finally{s(!1)}}return i?e.jsxs("div",{className:"mb-6 border border-border bg-background p-4",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2 text-[10px] font-semibold uppercase tracking-wider text-muted-foreground",children:[e.jsx(O,{className:"h-3.5 w-3.5"})," Maintenance â Social cards"]}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:"Pre-generates 1200Ã630 JPG share cards for published articles that don't have a fresh one yet. Force regenerate ignores the count and rewrites the latest batch of published articles with images."}),e.jsxs("div",{className:"mt-2 flex flex-wrap gap-x-4 gap-y-1 text-xs",children:[e.jsxs("span",{children:["Remaining missing/stale prepared card:"," ",e.jsx("strong",{className:"text-foreground",children:d&&x===null?"â¦":x??"â"})]}),N!==null&&e.jsxs("span",{className:"text-muted-foreground",children:["Last run: processed ",E,"/",N]})]})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[e.jsxs("button",{type:"button",onClick:()=>{w()},disabled:d||g,className:"inline-flex items-center gap-1 border border-border px-2 py-1 text-xs hover:border-foreground disabled:opacity-50",children:[e.jsx(M,{className:"h-3.5 w-3.5"})," Refresh"]}),e.jsx("button",{type:"button",onClick:()=>{C(!1)},disabled:g,className:"inline-flex items-center gap-1 border border-foreground bg-foreground px-3 py-1 text-xs text-background hover:opacity-90 disabled:opacity-50",children:g?"Runningâ¦":"Run Social Card Backfill"}),e.jsx("button",{type:"button",onClick:()=>{C(!0)},disabled:g,className:"inline-flex items-center gap-1 border border-breaking px-3 py-1 text-xs font-semibold text-breaking hover:bg-breaking hover:text-background disabled:opacity-50",children:"Force Regenerate"})]})]}),v.length>0&&e.jsxs("div",{className:"mt-4 border-t border-border pt-4",children:[e.jsx("div",{className:"mb-2 text-[10px] font-semibold uppercase tracking-wider text-muted-foreground",children:"Detailed results"}),e.jsx("div",{className:"max-h-96 space-y-2 overflow-y-auto border border-border bg-secondary/20 p-2 text-[11px]",children:v.map(a=>e.jsxs("details",{className:"border border-border bg-background p-2",open:!a.ok,children:[e.jsxs("summary",{className:"cursor-pointer",children:[e.jsxs("span",{className:a.ok?"text-emerald-600 dark:text-emerald-400":"text-breaking",children:[a.ok?e.jsx(se,{className:"mr-1 inline h-3 w-3"}):e.jsx(ne,{className:"mr-1 inline h-3 w-3"}),a.ok?"OK":"Failed"]})," ",e.jsx("span",{className:"font-medium",children:a.title??"Untitled"}),e.jsxs("span",{className:"ml-1 text-muted-foreground",children:["(",a.slug??a.id,")"]})]}),e.jsxs("dl",{className:"mt-2 grid gap-1 font-mono text-[10px] text-muted-foreground",children:[e.jsx(o,{label:"article id",value:a.id}),e.jsx(o,{label:"selected source type",value:a.sourceType}),e.jsx(o,{label:"selected source URL",value:a.sourceUrl??"none"}),e.jsx(o,{label:"fetch mode",value:a.fetchMode}),e.jsx(o,{label:"fetch URL",value:a.sourceFetchUrl??"none"}),e.jsx(o,{label:"fetch status",value:String(a.fetchStatus??"not reached")}),e.jsx(o,{label:"fetch content-type",value:a.fetchContentType??"not reached"}),e.jsx(o,{label:"content-length",value:String(a.fetchContentLength??"not supplied")}),e.jsx(o,{label:"decode step",value:a.decodeStepResult}),e.jsx(o,{label:"resize step",value:a.resizeStepResult}),e.jsx(o,{label:"upload step",value:a.uploadStepResult}),e.jsx(o,{label:"database update",value:a.databaseUpdateResult}),e.jsx(o,{label:"generated path",value:a.path??"none"}),e.jsx(o,{label:"dimensions",value:a.width&&a.height?`${a.width}Ã${a.height}`:"not generated"}),e.jsx(o,{label:"file size",value:a.bytes?`${a.bytes} bytes`:"not generated"}),e.jsx(o,{label:"exact error",value:a.exactError??"none"})]})]},a.id))})]})]}):null}function o({label:c,value:u}){return e.jsxs("div",{className:"grid gap-1 sm:grid-cols-[140px_1fr]",children:[e.jsx("dt",{className:"uppercase tracking-wider",children:c}),e.jsx("dd",{className:"break-all text-foreground",children:u})]})}
1export{ye 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.