1import{bt as B,bi as G,r as o,j as t,L as S,bu as H}from"./index-BZbnK03S.js";import{supabase as f}from"./client-DrdvKyjq.js";import{t as d}from"./index-N4zCLFOf.js";import{l as C}from"./use-editor-utils-C7BTQ5J0.js";import{u as X,t as Y,d as Z,b as ee}from"./use-persisted-filters-DBMdC_lG.js";import{J as te}from"./JwImportDialog-D7U1s1HX.js";import"./tslib.es6-eMSY344_.js";function me(){const{q:l,status:n,categoryId:c,format:u,sortKey:h,sortDir:x}=B.useSearch(),y=G({from:"/admin/videos"}),[v,$]=o.useState(l);o.useEffect(()=>{$(l)},[l]),o.useEffect(()=>{const e=setTimeout(()=>{v!==l&&y({search:s=>({...s,q:v}),replace:!0})},300);return()=>clearTimeout(e)},[v]);const p=e=>y({search:s=>({...s,...e}),replace:!0});X("yh-admin-videos-filters-v1",{q:l,status:n,categoryId:c,format:u,sortKey:h,sortDir:x},{q:"",status:"all",categoryId:"all",format:"all",sortKey:"published_at",sortDir:"desc"},e=>y({search:s=>({...s,...e}),replace:!0}));const[L,V]=o.useState([]),[D,E]=o.useState(!0),[i,m]=o.useState(new Set),[F,O]=o.useState([]),[U,A]=o.useState(!1),b=async()=>{E(!0);let e=f.from("videos").select("id, slug, title, status, format, published_at, updated_at, category_id");if(n!=="all"&&(e=e.eq("status",n)),c!=="all"&&(e=e.eq("category_id",c)),u!=="all"&&(e=e.eq("format",u)),l.trim()){const _=l.trim().replace(/[%,]/g," ");e=e.or(`title.ilike.%${_}%,slug.ilike.%${_}%`)}const s=x==="asc";h==="published_at"?e=e.order("published_at",{ascending:s,nullsFirst:!1}):e=e.order(h,{ascending:s});const{data:g,error:k}=await e.limit(1e3);k&&d.error(k.message),V(g??[]),E(!1)};o.useEffect(()=>{b()},[n,c,u,l,h,x]),o.useEffect(()=>{f.from("categories").select("id, name").order("name").then(({data:e})=>O(e??[]))},[]);const a=L,I=a.length>0&&a.every(e=>i.has(e.id)),J=a.some(e=>i.has(e.id)),r=Array.from(i),P=()=>{const e=new Set(i);I?a.forEach(s=>e.delete(s.id)):a.forEach(s=>e.add(s.id)),m(e)},K=e=>{const s=new Set(i);s.has(e)?s.delete(e):s.add(e),m(s)},N=async e=>{if(r.length===0)return;const s={status:e};e==="published"&&(s.published_at=new Date().toISOString());const{error:g}=await f.from("videos").update(s).in("id",r);if(g)return d.error(g.message);d.success(`Updated ${r.length} video${r.length===1?"":"s"} â ${e}`),C({action:e==="published"?"published":"updated",entity_type:"video",meta:{bulk:!0,count:r.length,status:e}}),m(new Set),b()},M=async()=>{if(r.length!==0&&confirm(`Permanently delete ${r.length} video${r.length===1?"":"s"}? Cannot be undone.`))try{const e=await ee({data:{ids:r}});d.success(`Deleted ${e.deleted} · removed ${e.mediaRemoved} poster${e.mediaRemoved===1?"":"s"}`),C({action:"deleted",entity_type:"video",meta:{bulk:!0,count:r.length,media_removed:e.mediaRemoved}}),m(new Set),b()}catch(e){d.error(e?.message??"Delete failed")}},W=async e=>{const{data:s}=await f.from("videos").select("*").eq("id",e).maybeSingle();if(!s)return d.error("Source not found");const{id:g,search_tsv:k,created_at:_,updated_at:ae,published_at:re,view_count:oe,imported_at:le,legacy_id:de,...z}=s,Q={...z,slug:`${s.slug}-copy-${Math.random().toString(36).slice(2,6)}`,title:`${s.title} (copy)`,status:"draft",published_at:null},{data:R,error:T}=await f.from("videos").insert(Q).select("id, title").single();if(T)return d.error(T.message);d.success("Duplicated as draft"),C({action:"duplicated",entity_type:"video",entity_id:R.id,entity_label:R.title}),b()},j=e=>{p(h===e?{sortDir:x==="asc"?"desc":"asc"}:{sortKey:e,sortDir:"asc"})},w=e=>h===e?x==="asc"?" â":" â":"",q=l!==""||n!=="all"||c!=="all"||u!=="all";return t.jsxs("div",{children:[t.jsxs("div",{className:"flex items-center justify-between flex-wrap gap-3",children:[t.jsxs("div",{children:[t.jsx("h1",{className:"yh-headline text-4xl",children:"Videos"}),t.jsxs("p",{className:"text-sm text-muted-foreground mt-1",children:[a.length,a.length===1e3?"+":""," result",a.length===1?"":"s",D?" · loadingâ¦":"",a.length===1e3?" · narrow filters to see more":""]})]}),t.jsxs("div",{className:"flex items-center gap-2",children:[q&&t.jsx("button",{onClick:()=>{try{localStorage.removeItem("yh-admin-videos-filters-v1")}catch{}y({search:{},replace:!0})},className:"border border-border px-3 py-2 yh-eyebrow text-xs hover:bg-secondary",children:"Reset filters"}),t.jsx("button",{onClick:()=>{const e=Y(a.map(s=>({id:s.id,title:s.title,slug:s.slug,status:s.status,format:s.format,published_at:s.published_at??"",updated_at:s.updated_at})),["id","title","slug","status","format","published_at","updated_at"]);Z(`videos-${new Date().toISOString().slice(0,10)}.csv`,e)},className:"border border-border px-3 py-2 yh-eyebrow text-xs hover:bg-secondary",children:"Export CSV"}),t.jsx("button",{onClick:()=>A(!0),className:"border border-foreground px-3 py-2 yh-eyebrow text-xs hover:bg-secondary",children:"+ Import from JW"}),t.jsx(S,{to:"/admin/videos/$id",params:{id:"new"},className:"bg-cobalt text-cobalt-foreground px-4 py-2 yh-eyebrow",children:"+ New Video"})]})]}),t.jsxs("div",{className:"mt-6 grid gap-3 md:grid-cols-[1fr_auto_auto_auto] items-end",children:[t.jsxs("div",{children:[t.jsx("label",{className:"yh-eyebrow text-xs text-muted-foreground",children:"Search"}
1),t.jsx("input",{value:v,onChange:e=>$(e.target.value),placeholder:"Title or slugâ¦",className:"w-full border border-border px-3 py-2 text-sm bg-background"})]}),t.jsxs("div",{children:[t.jsx("label",{className:"yh-eyebrow text-xs text-muted-foreground block",children:"Status"}),t.jsx("select",{value:n,onChange:e=>p({status:e.target.value}),className:"border border-border px-3 py-2 text-sm bg-background",children:H.map(e=>t.jsx("option",{value:e,children:e},e))})]}),t.jsxs("div",{children:[t.jsx("label",{className:"yh-eyebrow text-xs text-muted-foreground block",children:"Format"}),t.jsxs("select",{value:u,onChange:e=>p({format:e.target.value}),className:"border border-border px-3 py-2 text-sm bg-background",children:[t.jsx("option",{value:"all",children:"all"}),t.jsx("option",{value:"standard",children:"standard"}),t.jsx("option",{value:"short",children:"short"})]})]}),t.jsxs("div",{children:[t.jsx("label",{className:"yh-eyebrow text-xs text-muted-foreground block",children:"Category"}),t.jsxs("select",{value:c,onChange:e=>p({categoryId:e.target.value}),className:"border border-border px-3 py-2 text-sm bg-background",children:[t.jsx("option",{value:"all",children:"all"}),F.map(e=>t.jsx("option",{value:e.id,children:e.name},e.id))]})]})]}),J&&t.jsxs("div",{className:"mt-4 sticky top-0 z-10 flex items-center gap-2 flex-wrap bg-foreground text-background px-4 py-2.5 border-2 border-foreground",children:[t.jsxs("span",{className:"yh-eyebrow text-xs",children:[r.length," selected"]}),t.jsx("span",{className:"opacity-30",children:"|"}),t.jsx("button",{onClick:()=>N("published"),className:"yh-eyebrow text-xs bg-hotpink text-hotpink-foreground px-2.5 py-1",children:"Publish"}),t.jsx("button",{onClick:()=>N("draft"),className:"yh-eyebrow text-xs bg-background text-foreground px-2.5 py-1",children:"Unpublish"}),t.jsx("button",{onClick:()=>N("archived"),className:"yh-eyebrow text-xs border border-background/50 px-2.5 py-1",children:"Archive"}),t.jsx("button",{onClick:M,className:"yh-eyebrow text-xs bg-red-600 text-white px-2.5 py-1 ml-auto",children:"Delete"}),t.jsx("button",{onClick:()=>m(new Set),className:"yh-eyebrow text-xs underline",children:"Clear"})]}),t.jsx("div",{className:"mt-4 overflow-x-auto border border-border",children:t.jsxs("table",{className:"w-full text-sm",children:[t.jsx("thead",{className:"bg-secondary text-left yh-eyebrow text-xs",children:t.jsxs("tr",{children:[t.jsx("th",{className:"p-2 w-8",children:t.jsx("input",{type:"checkbox",checked:I,onChange:P,"aria-label":"Select all"})}),t.jsxs("th",{className:"p-2 cursor-pointer select-none hover:text-hotpink",onClick:()=>j("title"),children:["Title",w("title")]}),t.jsx("th",{className:"p-2",children:"Format"}),t.jsxs("th",{className:"p-2 cursor-pointer select-none hover:text-hotpink",onClick:()=>j("status"),children:["Status",w("status")]}),t.jsxs("th",{className:"p-2 cursor-pointer select-none hover:text-hotpink",onClick:()=>j("published_at"),children:["Published",w("published_at")]}),t.jsxs("th",{className:"p-2 cursor-pointer select-none hover:text-hotpink",onClick:()=>j("updated_at"),children:["Updated",w("updated_at")]}),t.jsx("th",{className:"p-2"})]})}),t.jsxs("tbody",{children:[a.map(e=>t.jsxs("tr",{className:`border-t border-border ${i.has(e.id)?"bg-hotpink/5":""}`,children:[t.jsx("td",{className:"p-2",children:t.jsx("input",{type:"checkbox",checked:i.has(e.id),onChange:()=>K(e.id),"aria-label":`Select ${e.title}`})}),t.jsxs("td",{className:"p-2",children:[t.jsx(S,{to:"/admin/videos/$id",params:{id:e.id},className:"hover:text-hotpink font-medium",children:e.title}),t.jsxs("div",{className:"text-xs text-muted-foreground truncate max-w-[40ch]",children:["/",e.slug]})]}),t.jsx("td",{className:"p-2 text-muted-foreground",children:t.jsx("span",{className:"yh-eyebrow text-xs",children:e.format})}),t.jsx("td",{className:"p-2",children:t.jsx("span",{className:`yh-eyebrow text-xs px-1.5 py-0.5 ${e.status==="published"?"bg-hotpink text-hotpink-foreground":e.status==="scheduled"?"bg-cobalt text-cobalt-foreground":e.status==="archived"?"bg-muted text-muted-foreground":"bg-foreground text-background"}`,children:e.status})}),t.jsx("td",{className:"p-2 text-muted-foreground whitespace-nowrap",children:e.published_at?new Date(e.published_at).toLocaleDateString():"â"}),t.jsx("td",{className:"p-2 text-muted-foreground whitespace-nowrap",children:new Date(e.updated_at).toLocaleDateString()}),t.jsxs("td",{className:"p-2 text-right whitespace-nowrap",children:[t.jsx("button",{onClick:()=>W(e.id),className:"yh-eyebrow text-xs text-muted-foreground hover:text-foreground mr-3",children:"Duplicate"}),t.jsx(S,{to:"/admin/videos/$id",params:{id:e.id},className:"yh-eyebrow text-hotpink",children:"Edit"})]})]},e.id)),!D&&a.length===0&&t.jsx("tr",{children:t.jsx("td",{colSpan:7,className:"p-6 text-center text-muted-foreground",children:q?"No videos match the current filters.":"No videos yet."})})]})]})}),t.jsx(te,{open:U,onClose:()=>A(!1),onCreated:b})]})}
1export{me 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.