1import{j as e}from"./vendor-radix-miDeECL4.js";import{r as a}from"./vendor-react-BBjb5hzp.js";import{u as F,D as O,S as P,P as T,I as w,p as U,q as $,r as R,t as B,v as j,U as K,V as H,Y as Z,Z as z,$ as Y,a0 as A,a1 as G,l as J,L as X,f as h,s as L}from"./index-DGrYQ9Ri.js";import{a as ee,b as se,u as te}from"./vendor-query-CnkSJpBn.js";import{V as y}from"./video-ln6vEMOY.js";import{S as re}from"./search-DMV43r0l.js";import{A as ae,a as M}from"./arrow-up-narrow-wide-BRENJ241.js";import{P as le}from"./play-B9kTQTYq.js";import{E as ie}from"./external-link-B4BAZBXP.js";import"./vendor-charts-D_igoWGj.js";import"./vendor-supabase-DwR6CW6F.js";function fe(){const{isAdmin:N}=F(),v=ee(),[l,V]=a.useState(""),[d,D]=a.useState("newest"),[p,E]=a.useState(12),[W,c]=a.useState(!1),[i,k]=a.useState(""),[u,S]=a.useState(""),g=se({mutationFn:async({workshopNum:s,url:t})=>{let r=null,n=null;try{const _=await fetch(`https://vimeo.com/api/oembed.json?url=${encodeURIComponent(t)}`);if(_.ok){const f=await _.json();r=f.thumbnail_url||null,n=f.duration?Math.round(f.duration/60):null}}catch{}const{error:x}=await L.from("videos").insert({title:`The Edge - Workshop #${s}`,video_url:t,thumbnail_url:r,duration_minutes:n,episode_number:s,is_published:!0,published_at:new Date().toISOString()});if(x)throw x;return{workshopNum:s,durationMinutes:n}},onSuccess:s=>{v.invalidateQueries({queryKey:["videos"]}),v.invalidateQueries({queryKey:["admin-videos"]}),c(!1),k(""),S(""),h.success(`Workshop #${s.workshopNum} added (${s.durationMinutes??"?"} min)`)},onError:s=>{h.error(`Failed to add video: ${s.message}`)}}),q=()=>{const s=parseInt(i,10);if(!s||s<=0){h.error("Enter a valid workshop number");return}if(!u.trim()||!u.includes("vimeo.com")){h.error("Enter a valid Vimeo URL");return}g.mutate({workshopNum:s,url:u.trim()})},{data:o,isLoading:b}=te({queryKey:["videos","all"],queryFn:async()=>{const{data:s,error:t}=await L.from("videos").select("*").eq("is_published",!0).order("created_at",{ascending:!1});if(t)throw t;return s},staleTime:5*60*1e3,refetchInterval:60*60*1e3}),m=a.useMemo(()=>{if(!o)return[];let s=o;if(l.trim()){const t=l.toLowerCase().split(/\s+/).filter(Boolean);s=o.filter(r=>{const n=`${r.title} ${r.description||""}`.toLowerCase();return t.every(x=>n.includes(x))})}return[...s].sort((t,r)=>d==="newest"?(r.episode_number||0)-(t.episode_number||0):d==="oldest"?(t.episode_number||0)-(r.episode_number||0):t.title.localeCompare(r.title))},[o,l,d]),C=a.useMemo(()=>m.slice(0,p),[m,p]),I=p<m.length,Q=()=>{E(s=>s+12)};return e.jsxs(O,{children:[e.jsx(P,{title:"Video Library",description:"Watch Weekly Wizdom's trading workshops, market recaps, and educational tutorials. Level up your crypto & stock trading.",canonical:"/videos"}),e.jsxs("div",{className:"p-4 sm:p-6 space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2.5 rounded-xl",style:{background:"rgba(0, 212, 255, 0.08)",border:"1px solid rgba(0, 212, 255, 0.2)"},children:e.jsx(y,{className:"h-6 w-6",style:{color:"#00d4ff"}})}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-xl sm:text-2xl font-bold text-white tracking-wide",children:"The Edge - Video Library"}),e.jsxs("p",{className:"text-sm text-white/50 font-mono tracking-wider",children:[o?.length||0," videos available"]})]})]}),N&&e.jsxs("button",{onClick:()=>c(!0),className:"inline-flex items-center gap-2 px-4 py-2 rounded-lg font-mono text-sm font-semibold text-black tracking-wider transition-all hover:brightness-110 shrink-0",style:{background:"#a855f7"},children:[e.jsx(T,{className:"h-4 w-4"}),"ADD WORKSHOP"]})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row gap-3",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx(re,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-white/50"}),e.jsx(w,{placeholder:"Search videos...",value:l,onChange:s=>V(s.target.value),className:"pl-10"})]}),e.jsxs(U,{value:d,onValueChange:s=>D(s),children:[e.jsx($,{className:"w-full sm:w-40",children:e.jsx(R,{placeholder:"Sort by"})}),e.jsxs(B,{children:[e.jsx(j,{value:"newest",children:e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(ae,{className:"h-4 w-4"}),"Newest"]})}),e.jsx(j,{value:"oldest",children:e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(M,{className:"h-4 w-4"}),"Oldest"]})}),e.jsx(j,{value:"title",children:e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(M,{className:"h-4 w-4"}),"Title A-Z"]})})]})]})]}),b&&e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-4",children:[...Array(8)].map((s,t)=>e.jsx("div",{className:"h-64 animate-pulse rounded-xl",style:{background:"rgba(255, 255, 255, 0.02)",border:"1px solid rgba(255, 255, 255, 0.08)"}},t))}),!b&&C.length>0&&e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-4",children:C.map(s=>e.jsxs("a",{href:s.video_url,target:"_blank",rel:"noopener noreferrer",className:"group block overflow-hidden rounded-xl transition-all duration-300 hover:translate-y-[-2px]",style:{background:"#0a0e18",border:"1px solid rgba(255, 255, 255, 0.08)"},onMouseEnter:t=>{t.currentTarget.style.border="1px solid rgba(0, 212, 255, 0.3)",t.currentTarget.style.boxShadow="0 0 20px rgba(0, 212, 255, 0.05)"},onMouseLeave:t=>{t.currentTarget.style.border="1px solid rgba(255, 255, 255, 0.08)",t.currentTarget.style.boxShadow="none"},children:[e.jsx("div",{className:"h-[2px] w-full",style:{background:"linear-gradient(90deg, #00d4ff 0%, transparent 100%)"}}),e.jsxs("div",{className:"relative aspect-[16/9]",style:{background:"#080c14"},children:[s.thumbnail_url?e.jsx("img",{src:s.thumbnail_url,alt:s.title,className:"w-full h-full object-contain"}):e.jsx("div",{className:"w-full h-full flex items-center justify-center bg-gradient-to-br from-[#00d4ff]/10 to-[#a855f7]/10",children:e.jsx(y,{className:"h-12 w-12 text-white/20"})}),e.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-black/50 opacity-0 group-hover:opacity-100 transition-opacity duration-300",children:e.jsx("div",{className:"w-14 h-14 roun
1ded-lg flex items-center justify-center",style:{background:"rgba(0, 212, 255, 0.15)",border:"1px solid rgba(0, 212, 255, 0.4)"},children:e.jsx(le,{className:"h-6 w-6 ml-0.5",style:{color:"#00d4ff"}})})}),s.duration_minutes!=null&&s.duration_minutes>0&&e.jsxs("div",{className:"absolute bottom-2 right-2 px-2 py-0.5 rounded-lg text-xs font-mono tracking-wider text-white",style:{background:"rgba(0, 0, 0, 0.8)",border:"1px solid rgba(255, 255, 255, 0.1)"},children:[s.duration_minutes," MIN"]})]}),e.jsxs("div",{className:"p-4",children:[e.jsx("h3",{className:"font-semibold text-white group-hover:text-[#00d4ff] transition-colors line-clamp-2",children:s.title}),s.description&&e.jsx("p",{className:"text-sm text-white/50 mt-1 line-clamp-2",children:s.description}),e.jsxs("div",{className:"flex items-center gap-2 mt-3 text-xs text-white/30 font-mono tracking-wider uppercase",children:[e.jsx(ie,{className:"h-3 w-3"}),e.jsx("span",{children:"Watch on Vimeo"})]})]})]},s.id))}),!b&&m.length===0&&e.jsxs("div",{className:"text-center py-16 rounded-xl",style:{background:"#0a0e18",border:"1px solid rgba(255, 255, 255, 0.08)"},children:[e.jsx("div",{className:"h-[2px] w-full -mt-16 mb-14",style:{background:"linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.06), transparent)"}}),e.jsx(y,{className:"h-12 w-12 mx-auto mb-4 text-white/20"}),e.jsx("h3",{className:"text-lg font-semibold text-white mb-2 tracking-wide",children:"No videos found"}),e.jsx("p",{className:"text-white/50 font-mono text-sm tracking-wider",children:l?"Try adjusting your search query":"Check back later for new content"})]}),I&&e.jsx("div",{className:"flex justify-center",children:e.jsx("button",{onClick:Q,className:"px-6 py-2.5 rounded-lg text-sm font-mono uppercase tracking-widest text-white/70 hover:text-white transition-all duration-300 hover:translate-y-[-1px]",style:{background:"rgba(255, 255, 255, 0.03)",border:"1px solid rgba(255, 255, 255, 0.1)"},onMouseEnter:s=>{s.currentTarget.style.border="1px solid rgba(0, 212, 255, 0.3)",s.currentTarget.style.background="rgba(0, 212, 255, 0.05)"},onMouseLeave:s=>{s.currentTarget.style.border="1px solid rgba(255, 255, 255, 0.1)",s.currentTarget.style.background="rgba(255, 255, 255, 0.03)"},children:"Load More"})})]}),N&&e.jsx(K,{open:W,onOpenChange:c,children:e.jsxs(H,{className:"sm:max-w-[420px] p-0",style:{background:"#0a0e18",border:"1px solid rgba(0, 212, 255, 0.20)"},children:[e.jsx("div",{className:"h-[2px] w-full",style:{background:"linear-gradient(90deg, #00d4ff, #a855f7, transparent)"}}),e.jsxs("div",{className:"p-6 space-y-5",children:[e.jsxs(Z,{children:[e.jsx(z,{className:"text-white font-mono tracking-wider",children:"Quick Add Workshop"}),e.jsx(Y,{className:"text-white/50 font-mono text-xs",children:"Auto-generates title, fetches thumbnail & duration from Vimeo"})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs(A,{htmlFor:"workshop-number",className:"text-white/70 font-mono text-xs uppercase tracking-wider",children:["Workshop Number ",e.jsx("span",{style:{color:"#ff2e50"},children:"*"})]}),e.jsx(w,{id:"workshop-number",type:"number",placeholder:"e.g. 112",value:i,onChange:s=>k(s.target.value),className:"bg-[#080c14] border-white/[0.08] text-white placeholder:text-white/30 font-mono focus-visible:ring-[#00d4ff]/40"}),i&&parseInt(i)>0&&e.jsxs("p",{className:"text-xs font-mono",style:{color:"#00d4ff"},children:["Title: The Edge - Workshop #",i]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(A,{htmlFor:"vimeo-url",className:"text-white/70 font-mono text-xs uppercase tracking-wider",children:["Vimeo URL ",e.jsx("span",{style:{color:"#ff2e50"},children:"*"})]}),e.jsx(w,{id:"vimeo-url",placeholder:"https://vimeo.com/123456789",value:u,onChange:s=>S(s.target.value),className:"bg-[#080c14] border-white/[0.08] text-white placeholder:text-white/30 font-mono text-sm focus-visible:ring-[#00d4ff]/40"}),e.jsx("p",{className:"text-[10px] text-white/30 font-mono",children:"Thumbnail and duration will be auto-fetched"})]})]}),e.jsxs(G,{className:"gap-2",children:[e.jsx(J,{type:"button",variant:"outline",onClick:()=>c(!1),className:"border-white/[0.08] text-white/50 hover:text-white font-mono text-xs",children:"Cancel"}),e.jsx("button",{onClick:q,disabled:g.isPending,className:"inline-flex items-center gap-2 px-4 py-2 font-mono text-sm font-semibold text-black tracking-wider transition-all hover:brightness-110 disabled:opacity-50 disabled:cursor-not-allowed",style:{background:"#a855f7"},children:g.isPending?e.jsxs(e.Fragment,{children:[e.jsx(X,{className:"h-4 w-4 animate-spin"}),"Adding..."]}):e.jsxs(e.Fragment,{children:[e.jsx(T,{className:"h-4 w-4"}),"Add & Publish"]})})]})]})]})})]})}export{fe 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.