1import{r as u,j as e,L as E}from"./react-vendor-d250d348.js";import{a as m,S as P,E as L,P as V,B as I}from"./AdminShared-5d419368.js";import{D as R}from"./DeletedBadge-160c6c81.js";import{e as p,h as M}from"./index-721397ec.js";import{V as U,F as j,U as b,G as C,bE as $,ag as B,o as T}from"./lucide-1ed530d4.js";import"./UserAvatar-05bf91ea.js";import"./NameBadges-8c10539c.js";import"./dynamicBadgeIcons-e7802c8f.js";import"./utils-f85c62fa.js";import"./adminEntityUrl-6c40272a.js";import"./sentry-5ddef7e0.js";import"./supabase-b5d9a3f8.js";(function(){try{var s=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{};s.SENTRY_RELEASE={id:"72d1b8b3cf2f419b3766a3c986aa32488299d6dc"};var a=new s.Error().stack;a&&(s._sentryDebugIds=s._sentryDebugIds||{},s._sentryDebugIds[a]="147db068-7111-401e-8d5c-cae47618d6ac",s._sentryDebugIdIdentifier="sentry-dbid-147db068-7111-401e-8d5c-cae47618d6ac")}catch{}})();const O="id, username, display_name, avatar_url, is_verified";async function y(s){const a={},o=[...new Set(s.filter(Boolean))];if(!o.length)return a;const{data:l}=await p.from("profiles").select(O).in("id",o);return(l||[]).forEach(r=>{a[r.id]=r}),a}function F(s){const a=s||{};return{username:a.username,displayName:a.display_name,avatarUrl:a.avatar_url,isVerified:!!a.is_verified}}async function q(s,a,o){const{data:l,error:r}=await p.from("post_images").select("id, post_id, image_url, thumbnail_url, video_url, duration, created_at, posts!post_id(id, slug, user_id, caption, is_deleted)").eq("media_type","video").not("video_url","is",null).order("created_at",{ascending:o}).range(s,s+a-1);if(r)throw new Error(`Failed to fetch post videos: ${r.message}`);const n=(l||[]).filter(t=>t.posts),c=await y(n.map(t=>t.posts.user_id));return n.map(t=>({key:`post:${t.id}`,source:"post",userId:t.posts.user_id,...F(c[t.posts.user_id]),videoUrl:t.video_url,posterUrl:t.thumbnail_url||t.image_url||null,durationSeconds:t.duration??null,createdAt:t.created_at,contextLabel:t.posts.caption?t.posts.caption.slice(0,80):"Feed post",contextLink:`/explore/${t.posts.slug||t.post_id}`,isDeleted:!!t.posts.is_deleted}))}async function z(s,a,o){const{data:l,error:r}=await p.from("messages").select("id, conversation_id, sender_id, video_url, video_thumbnail_url, video_duration, created_at, is_deleted").eq("type","video").not("video_url","is",null).order("created_at",{ascending:o}).range(s,s+a-1);if(r)throw new Error(`Failed to fetch message videos: ${r.message}`);const n=l||[],c=await y(n.map(t=>t.sender_id));return n.map(t=>({key:`message:${t.id}`,source:"message",userId:t.sender_id,...F(c[t.sender_id]),videoUrl:t.video_url,posterUrl:t.video_thumbnail_url||null,durationSeconds:t.video_duration??null,createdAt:t.created_at,contextLabel:"Direct message",contextLink:null,isDeleted:!!t.is_deleted}))}async function G(s,a,o){const{data:l,error:r}=await p.from("video_clips").select("id, user_id, source_kind, source_id, video_url, thumbnail_url, duration_ms, length_seconds, tier_at_record, watermarked, created_at, is_deleted").order("created_at",{ascending:o}).range(s,s+a-1);if(r)throw new Error(`Failed to fetch run clips: ${r.message}`);const n=l||[],c=await y(n.map(t=>t.user_id));return n.map(t=>({key:`clip:${t.id}`,source:"clip",userId:t.user_id,...F(c[t.user_id]),videoUrl:t.video_url,posterUrl:t.thumbnail_url||null,durationSeconds:t.length_seconds!=null?Number(t.length_seconds):t.duration_ms!=null?t.duration_ms/1e3:null,createdAt:t.created_at,contextLabel:t.source_kind?`Run clip · ${t.source_kind}`:"Run clip",contextLink:null,isDeleted:!!t.is_deleted}))}const v={post:q,message:z,clip:G};async function H(s="all",a=0,o=24,l="newest"){const r=l==="oldest";if(v[s])return v[s](a,o,r);const n=a+o;return(await Promise.all(Object.values(v).map(d=>d(0,n,r).catch(()=>[])))).flat().sort((d,g)=>{const f=d.createdAt?new Date(d.createdAt).getTime():0,_=g.createdAt?new Date(g.createdAt).getTime():0;return r?f-_:_-f}).slice(a,a+o)}async function Y(){const[s,a,o]=await Promise.all([p.from("post_images").select("id",{count:"exact",head:!0}).eq("media_type","video").not("video_url","is",null),p.from("messages").select("id",{count:"exact",head:!0}).eq("type","video").not("video_url","is",null),p.from("video_clips").select("id",{count:"exact",head:!0}
1)]),l=s.count||0,r=a.count||0,n=o.count||0;return{post:l,message:r,clip:n,total:l+r+n}}async function Z(){const{data:s,error:a}=await p.rpc("get_admin_video_stats");if(a){if(a.code==="PGRST202"||a.code==="42883"||String(a.message||"").includes("get_admin_video_stats"))return null;throw a}return s}const x=24,J=[{value:"all",label:"All Sources"},{value:"post",label:"Feed Posts"},{value:"message",label:"Direct Messages"},{value:"clip",label:"Run Clips"}],k={post:{label:"Post",color:"#A855F7",icon:j},message:{label:"DM",color:"#00FF7F",icon:T},clip:{label:"Run Clip",color:"#3B82F6",icon:C}},K=s=>{if(s==null||Number.isNaN(Number(s)))return null;const a=Math.max(0,Math.round(Number(s))),o=Math.floor(a/60),l=a%60;return`${o}:${String(l).padStart(2,"0")}`},Q=({video:s})=>{const a=k[s.source]||k.post,o=a.icon,l=K(s.durationSeconds),r=s.displayName||s.username||"Unknown user";return e.jsxs("div",{className:"bg-[#1a1a1a] border border-[#2a2a2a] rounded-xl overflow-hidden flex flex-col",children:[e.jsxs("div",{className:"relative aspect-video bg-black",children:[s.videoUrl?e.jsx("video",{src:s.videoUrl,poster:s.posterUrl||void 0,controls:!0,preload:"metadata",playsInline:!0,className:"w-full h-full object-contain bg-black"}):e.jsx("div",{className:"w-full h-full flex items-center justify-center",children:e.jsx(U,{size:28,className:"text-gray-600"})}),l&&e.jsx("span",{className:"absolute bottom-2 right-2 px-1.5 py-0.5 rounded bg-black/75 text-white text-[10px] font-mono tabular-nums pointer-events-none",children:l})]}),e.jsxs("div",{className:"p-3 space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx(I,{color:a.color,children:e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(o,{size:11}),a.label]})}),s.isDeleted&&e.jsx(R,{}),e.jsx("span",{className:"text-gray-600 text-[10px] ml-auto whitespace-nowrap",children:M(s.createdAt)})]}),e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[s.avatarUrl?e.jsx("img",{src:s.avatarUrl,alt:"",className:"w-6 h-6 rounded-full object-cover flex-shrink-0",onError:n=>{n.target.style.display="none"}}):e.jsx("div",{className:"w-6 h-6 rounded-full bg-white/10 flex items-center justify-center text-[10px] font-semibold text-white flex-shrink-0",children:r.charAt(0).toUpperCase()}),s.userId?e.jsx(E,{to:`/admin/users/${s.userId}`,className:"text-white text-xs font-medium truncate hover:text-[#00FF7F] transition-colors",children:r}):e.jsx("span",{className:"text-white text-xs font-medium truncate",children:r})]}),e.jsxs("div",{className:"flex items-center gap-1 min-w-0",children:[e.jsx("p",{className:"text-gray-500 text-[11px] truncate flex-1",children:s.contextLabel}),s.contextLink&&e.jsx(E,{to:s.contextLink,target:"_blank",rel:"noopener noreferrer",className:"text-gray-500 hover:text-[#00FF7F] transition-colors flex-shrink-0",title:"Open source",children:e.jsx(B,{size:13})})]})]})]})},de=()=>{const[s,a]=u.useState("all"),[o,l]=u.useState("newest"),[r,n]=u.useState([]),[c,t]=u.useState(null),[d,g]=u.useState(null),[f,_]=u.useState(0),[A,w]=u.useState(!0),[h,N]=u.useState(0);u.useEffect(()=>{Y().then(t).catch(()=>t(null)),Z().then(g).catch(()=>g(null))},[]);const S=u.useCallback(async()=>{w(!0);try{const i=await H(s,h*x,x,o);n(i),_(i.length===x?(h+2)*x:(h+1)*x)}catch(i){console.error("Videos load error:",i),n([]),_(0)}w(!1)},[s,o,h]);u.useEffect(()=>{N(0)},[s,o]),u.useEffect(()=>{S()},[S]);const D=Math.ceil(f/x);return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2 rounded-lg bg-[#3B82F6]/10",children:e.jsx(U,{size:20,className:"text-[#3B82F6]"})}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold text-white",children:"Videos"}),e.jsxs("p",{className:"text-gray-400 text-sm",children:["Every video stored in the cloud, feed posts, direct messages, and run clips",c?` · ${c.total} total`:""]})]})]}),d&&e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-6 gap-3",children:[e.jsx(m,{icon:j,label:"Video posts",value:d.video_posts_total,color:"#A855F7"}),e.jsx(m,{icon:b,label:"Users posting",value:d.video_posters_total,color:"#00FF7F"}
1),e.jsx(m,{icon:j,label:"Posts · 30d",value:d.video_posts_30d,color:"#A855F7"}),e.jsx(m,{icon:b,label:"Posters · 30d",value:d.video_posters_30d,color:"#00FF7F"}),e.jsx(m,{icon:C,label:"Run clips",value:d.run_clips_total,color:"#3B82F6"}),e.jsx(m,{icon:b,label:"Users recording",value:d.recording_users_total,color:"#3B82F6"})]}),c&&e.jsxs("div",{className:"flex flex-wrap gap-2 text-xs",children:[e.jsxs("span",{className:"px-2.5 py-1 rounded-lg bg-[#A855F7]/10 text-[#A855F7]",children:[c.post," feed posts"]}),e.jsxs("span",{className:"px-2.5 py-1 rounded-lg bg-[#00FF7F]/10 text-[#00FF7F]",children:[c.message," direct messages"]}),e.jsxs("span",{className:"px-2.5 py-1 rounded-lg bg-[#3B82F6]/10 text-[#3B82F6]",children:[c.clip," run clips"]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx($,{size:16,className:"text-gray-400"}),e.jsx("select",{value:s,onChange:i=>a(i.target.value),className:"bg-[#1a1a1a] border border-[#2a2a2a] rounded-lg px-3 py-2 text-gray-300 text-sm focus:outline-none focus:border-[#00FF7F]",children:J.map(i=>e.jsx("option",{value:i.value,children:i.label},i.value))}),e.jsxs("select",{value:o,onChange:i=>l(i.target.value),className:"bg-[#1a1a1a] border border-[#2a2a2a] rounded-lg px-3 py-2 text-gray-300 text-sm focus:outline-none focus:border-[#00FF7F] ml-auto",children:[e.jsx("option",{value:"newest",children:"Newest First"}),e.jsx("option",{value:"oldest",children:"Oldest First"})]})]}),A?e.jsx(P,{}):r.length===0?e.jsx(L,{text:"No videos found for this source"}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4",children:r.map(i=>e.jsx(Q,{video:i},i.key))}),e.jsx(V,{page:h+1,totalPages:D,onPageChange:i=>N(i-1)})]})]})};export{de as default};
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.