PageSourceSearch

https://hour-accelerator-landing.lovable.app/assets/AdminPanel-b2ZPfKld.js

js hour-accelerator-landing.lovable.app collected 2026-10-03 03:29:32 UTC 227,426 bytes, 72 lines download raw bytes

1import{k as Re,r as u,f as S,j as e,a4 as ze,aP as pe,aQ as fe,aR as ge,aS as be,I as q,U as Te,aZ as ss,L as H,Y as he,J as w,d as $t,W as as,X as Rt,a_ as xt,E as Mt,a$ as Cs,ap as rs,a7 as Lt,ar as Ft,R as G,b0 as dt,T as As,m as ne,K as Ce,M as Ae,B as Z,N as ie,C as la,S as At,a2 as oa,aC as ft,aD as gt,aE as te,aG as se,p as Ve,V as Ts,i as Ps,O as Dt,H as it,aI as ca,a as Ds,aj as da,ak as ua,al as ma,am as xa,an as Bt,u as ha,b1 as pa,e as fa,az as ga}from"./index-D6JPuPk8.js";import{P as ye}from"./plus-B8oF21yH.js";import{S as Ue}from"./square-pen-DHDFSmOj.js";import{F as ba}from"./filter-H5vhQ_9k.js";import{E as zt}from"./eye-DKsmm_7B.js";import{C as ms}from"./crown-BLvEavV-.js";import{D as ht}from"./dollar-sign-Coo02nyC.js";import{F as ns}from"./film-w9kopVl2.js";import{D as Ze}from"./download-BayylRQK.js";import{i as Oe,C as Es,T as ja,f as Ie,p as Yt,a as $e,L as Le,g as Fe,b as va,S as ya,A as Os,c as Na,d as Be,e as Is,h as ce,j as wa,k as $s,G as Rs,l as Ms,m as ka,n as kt,w as Et,o as Tt,u as Ls,q as is,r as _a,s as Sa,t as Ca,v as Aa,x as Ta,y as Fs,z as zs,D as Pa,B as Da,E as xs,F as Ea,H as ls,I as Vs,J as os,P as Oa,K as Ia,M as $a,R as Xe,N as et,O as Qt}from"./generateCategoricalChart-CDHRUGtt.js";import{g as Us,C as qs,X as st,Y as at,A as Ra,a as Gt}from"./AreaChart-CMlOQAZV.js";import{M as Bs}from"./message-square-DiRA5T6F.js";import{T as Ma}from"./triangle-alert-CueeVYTl.js";import{C as La}from"./circle-check-big-e6eK1gR6.js";import{C as Fa}from"./circle-x--EUqJzax.js";import{P as za}from"./progress-DlnEeV_E.js";import{W as Va}from"./wand-sparkles-CA6_ZHrW.js";import{I as Ua}from"./image-BXx9pnZ7.js";import{M as cs}from"./mail-D7uA0qJc.js";import{S as qa}from"./share-2-45TMDc8L.js";import{F as Ba}from"./flask-conical-DaTe8_-r.js";import{C as Vt}from"./copy-CEMXPglF.js";import{A as Gs}from"./activity-BLz5HQlA.js";import{C as We}from"./chart-column-MqCwJnxW.js";import{T as Ws}from"./tag-BhEo9p9Z.js";import{A as Ga}from"./archive-CwdZcQdx.js";import{S as Wa}from"./switch-qstjYbsB.js";import{G as Hs}from"./gift-xAxv1Alf.js";import{R as Jt}from"./rotate-ccw-CMrjhBhm.js";import{L as Ha}from"./layers-B3VyL6MA.js";import{L as Ka}from"./lightbulb-D9cFValq.js";import{M as Ya}from"./megaphone-BxlwEO3b.js";/**
2 * @license lucide-react v0.462.0 - ISC
3 *
4 * This source code is licensed under the ISC license.
5 * See the LICENSE file in the root directory of this source tree.
6 */const Qa=Re("ArrowDownRight",[["path",{d:"m7 7 10 10",key:"1fmybs"}],["path",{d:"M17 7v10H7",key:"6fjiku"}]]);/**
7 * @license lucide-react v0.462.0 - ISC
8 *
9 * This source code is licensed under the ISC license.
10 * See the LICENSE file in the root directory of this source tree.
11 */const ds=Re("ArrowUpRight",[["path",{d:"M7 7h10v10",key:"1tivn9"}],["path",{d:"M7 17 17 7",key:"1vkiza"}]]);/**
12 * @license lucide-react v0.462.0 - ISC
13 *
14 * This source code is licensed under the ISC license.
15 * See the LICENSE file in the root directory of this source tree.
16 */const Ks=Re("CalendarDays",[["path",{d:"M8 2v4",key:"1cmpym"}],["path",{d:"M16 2v4",key:"4m81vk"}],["rect",{width:"18",height:"18",x:"3",y:"4",rx:"2",key:"1hopcy"}],["path",{d:"M3 10h18",key:"8toen8"}],["path",{d:"M8 14h.01",key:"6423bh"}],["path",{d:"M12 14h.01",key:"1etili"}],["path",{d:"M16 14h.01",key:"1gbofw"}],["path",{d:"M8 18h.01",key:"lrp35t"}],["path",{d:"M12 18h.01",key:"mhygvu"}],["path",{d:"M16 18h.01",key:"kzsmim"}]]);/**
17 * @license lucide-react v0.462.0 - ISC
18 *
19 * This source code is licensed under the ISC license.
20 * See the LICENSE file in the root directory of this source tree.
21 */const Ys=Re("ClipboardList",[["rect",{width:"8",height:"4",x:"8",y:"2",rx:"1",ry:"1",key:"tgr4d6"}],["path",{d:"M16 4h2a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h2",key:"116196"}],["path",{d:"M12 11h4",key:"1jrz19"}],["path",{d:"M12 16h4",key:"n85exb"}],["path",{d:"M8 11h.01",key:"1dfujw"}],["path",{d:"M8 16h.01",key:"18s6g9"}]]);/**
22 * @license lucide-react v0.462.0 - ISC
23 *
24 * This source code is licensed under the ISC license.
25 * See the LICENSE file in the root directory of this source tree.
26 */const Ja=Re("Ellipsis",[["circle",{cx:"12",cy:"12",r:"1",key:"41hilf"}],["circle",{cx:"19",cy:"12",r:"1",key:"1wjl8i"}],["circle",{cx:"5",cy:"12",r:"1",key:"1pcz8c"}]]);/**
27 * @license lucide-react v0.462.0 - ISC
28 *
29 * This source code is licensed under the ISC license.
30 * See the LICENSE file in the root directory of this source tree.
31 */const Za=Re("Inbox",[["polyline",{points:"22 12 16 12 14 15 10 15 8 12 2 12",key:"o97t9d"}],["path",{d:"M5.45 5.11 2 12v6a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-6l-3.45-6.89A2 2 0 0 0 16.76 4H7.24a2 2 0 0 0-1.79 1.11z",key:"oot6mr"}]]);/**
32 * @license lucide-react v0.462.0 - ISC
33 *
34 * This source code is licensed under the ISC license.
35 * See the LICENSE file in the root directory of this source tree.
36 */const Xa=Re("LayoutDashboard",[["rect",{width:"7",height:"9",x:"3",y:"3",rx:"1",key:"10lvy0"}],["rect",{width:"7",height:"5",x:"14",y:"3",rx:"1",key:"16une8"}],["rect",{width:"7",height:"9",x:"14",y:"12",rx:"1",key:"1hutg5"}],["rect",{width:"7",height:"5",x:"3",y:"16",rx:"1",key:"ldoo1y"}]]);/**
37 * @license lucide-react v0.462.0 - ISC
38 *
39 * This source code is licensed under the ISC license.
40 * See the LICENSE file in the root directory of this source tree.
41 */const Qs=Re("ListMusic",[["path",{d:"M21 15V6",key:"h1cx4g"}],["path",{d:"M18.5 18a2.5 2.5 0 1 0 0-5 2.5 2.5 0 0 0 0 5Z",key:"8saifv"}],["path",{d:"M12 12H3",key:"18klou"}],["path",{d:"M16 6H3",key:"1wxfjs"}],["path",{d:"M12 18H3",key:"11ftsu"}]]);/**
42 * @license lucide-react v0.462.0 - ISC
43 *
44 * This source code is licensed under the ISC license.
45 * See the LICENSE file in the root directory of this source tree.
46 */const Js=Re("Ticket",[["path",{d:"M2 9a3 3 0 0 1 0 6v2a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-2a3 3 0 0 1 0-6V7a2 2 0 0 0-2-2H4a2 2 0 0 0-2 2Z",key:"qn84l0"}],["path",{d:"M13 5v2",key:"dyzc3o"}],["path",{d:"M13 17v2",key:"1ont0d"}],["path",{d:"M13 11v2",key:"1wjjxi"}]]),er=["#7c3aed","#10b981","#3b82f6","#f59e0b","#ef4444","#ec4899","#06b6d4","#8b5cf6","#f97316","#6366f1"],tr=t=>t.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/(^-|-$)/g,""),sr=()=>{const[t,s]=u.useState([]),[n,a]=u.useState(!0),[r,i]=u.useState(null),l=u.useCallback(async()=>{a(!0);const{data:c}=await S.from("channels").select("*").order("sort_order",{ascending:!0});c&&s(c),a(!1)},[]);u.useEffect(()=>{l()},[l]);const m=async c=>{if((c.video_count||0)>0){w.error("Move videos to another channel first");return}if(!confirm(`Delete "${c.name}"?`))return;const{error:x}=await S.from("channels").delete().eq("id",c.id);x?w.error(x.message):(w.success("Deleted"),l())},o=async(c,x)=>{const g=c+x;if(g<0||g>=t.length)return;const h=t[c],b=t[g];await Promise.all([S.from("channels").update({sort_order:g}).eq("id",h.id),S.from("channels").update({sort_order:c}).eq("id",b.id)]),l()};return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-6 flex-wrap gap-3",children:[e.jsx("h2",{className:"text-2xl font-extrabold text-foreground",children:"Channels"}),e.jsxs("button",{onClick:()=>i({mode:"create"}),className:"px-4 py-2 rounded-xl bg-primary text-primary-foreground text-sm font-semibold hover:opacity-90 transition-opacity flex items-center gap-2",children:[e.jsx(ye,{className:"h-4 w-4"})," Create Channel"]})]}),e.jsx("div",{className:"academy-card overflow-hidden",children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b bg-muted/30",children:[e.jsx("th",{className:"w-10 p-3"}),e.jsx("th",{className:"text-left p-3 text-xs font-bold text-muted-foreground uppercase tracking-wider",children:"Color"}),e.jsx("th",{className:"text-left p-3 text-xs font-bold text-muted-foreground uppercase tracking-wider",children:"Name"}),e.jsx("th",{className:"text-left p-3 text-xs font-bold text-muted-foreground uppercase tracking-wider",children:"Slug"}),e.jsx("th",{className:"text-right p-3 text-xs font-bold text-muted-foreground uppercase tracking-wider",children:"Videos"}),e.jsx("th",{className:"text-right p-3 text-xs font-bold text-muted-foreground uppercase tracking-wider",children:"Order"}),e.jsx("th",{className:"text-right p-3 text-xs font-bold text-muted-foreground uppercase tracking-wider",children:"Actions"})]})}),e.jsx("tbody",{children:n?Array.from({length:3}).map((c,x)=>e.jsx("tr",{className:"border-b",children:e.jsx("td",{colSpan:7,className:"p-3",children:e.jsx("div",{className:"h-8 rounded skeleton-shimmer"})})},x)):t.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:7,className:"p-8 text-center text-muted-foreground",children:"No channels yet"})}):t.map((c,x)=>e.jsxs("tr",{className:"border-b hover:bg-muted/20 transition-colors",children:[e.jsx("td",{className:"p-3",children:e.jsxs("div",{className:"flex flex-col gap-0.5",children:[e.jsx("button",{onClick:()=>o(x,-1),disabled:x===0,className:"p-0.5 hover:bg-muted rounded disabled:opacity-20 text-muted-foreground",children:"▲"}),e.jsx("button",{onClick:()=>
46o(x,1),disabled:x===t.length-1,className:"p-0.5 hover:bg-muted rounded disabled:opacity-20 text-muted-foreground",children:"▼"})]})}),e.jsx("td",{className:"p-3",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-6 h-6 rounded-md shrink-0",style:{backgroundColor:c.color}}),e.jsx("span",{className:"text-[10px] font-mono text-muted-foreground",children:c.color})]})}),e.jsx("td",{className:"p-3",children:e.jsxs("div",{className:"flex items-center gap-2",children:[c.icon_url&&e.jsx("span",{className:"text-base",children:c.icon_url}),e.jsx("span",{className:"font-semibold text-foreground text-xs",children:c.name})]})}),e.jsx("td",{className:"p-3 text-xs text-muted-foreground font-mono",children:c.slug}),e.jsx("td",{className:"p-3 text-right text-xs text-muted-foreground",children:c.video_count||0}),e.jsx("td",{className:"p-3 text-right text-xs text-muted-foreground",children:c.sort_order??x}),e.jsx("td",{className:"p-3",children:e.jsxs("div",{className:"flex items-center gap-1 justify-end",children:[e.jsx("button",{onClick:()=>i({mode:"edit",channel:c}),className:"p-1.5 rounded-lg hover:bg-muted transition-colors",children:e.jsx(Ue,{className:"h-3.5 w-3.5 text-muted-foreground"})}),e.jsx("button",{onClick:()=>m(c),className:"p-1.5 rounded-lg hover:bg-destructive/10 transition-colors",children:e.jsx(ze,{className:"h-3.5 w-3.5 text-destructive"})})]})})]},c.id))})]})})}),r&&e.jsx(ar,{mode:r.mode,channel:r.channel,onClose:()=>i(null),onSuccess:l})]})},ar=({mode:t,channel:s,onClose:n,onSuccess:a})=>{const[r,i]=u.useState({name:(s==null?void 0:s.name)||"",slug:(s==null?void 0:s.slug)||"",description:(s==null?void 0:s.description)||"",color:(s==null?void 0:s.color)||"#7c3aed",icon_url:(s==null?void 0:s.icon_url)||"",hero_image_url:(s==null?void 0:s.hero_image_url)||""}),[l,m]=u.useState(!1),[o,c]=u.useState(!1),[x,g]=u.useState(t==="create"),h=f=>{i(d=>({...d,name:f,...x?{slug:tr(f)}:{}}))},b=async f=>{var O;const d=(O=f.target.files)==null?void 0:O[0];if(!d)return;c(!0);const C=d.name.split(".").pop(),E=`channel-heroes/${r.slug||"new"}-${Date.now()}.${C}`,{error:D}=await S.storage.from("academy-art").upload(E,d,{upsert:!0});if(D){w.error(D.message),c(!1);return}const{data:{publicUrl:k}}=S.storage.from("academy-art").getPublicUrl(E);i(T=>({...T,hero_image_url:k})),c(!1)},j=async()=>{if(!r.name||!r.slug){w.error("Name and slug are required");return}m(!0);const f={name:r.name,slug:r.slug,description:r.description||null,color:r.color,icon_url:r.icon_url||null,hero_image_url:r.hero_image_url||null};if(t==="edit"&&s){const{error:d}=await S.from("channels").update(f).eq("id",s.id);d?w.error(d.message):(w.success("Updated"),a(),n())}else{const{error:d}=await S.from("channels").insert({...f,sort_order:999});d?w.error(d.message):(w.success("Created"),a(),n())}m(!1)};return e.jsx(pe,{open:!0,onOpenChange:f=>{f||n()},children:e.jsxs(fe,{className:"max-w-lg",children:[e.jsx(ge,{children:e.jsx(be,{children:t==="create"?"Create Channel":"Edit Channel"})}),e.jsxs("div",{className:"space-y-3 max-h-[60vh] overflow-y-auto pr-1",children:[e.jsxs("div",{className:"rounded-xl p-4 flex items-center gap-3",style:{background:`${r.color}15`},children:[r.icon_url&&e.jsx("span",{className:"text-2xl",children:r.icon_url}),e.jsxs("div",{children:[e.jsx("p",{className:"font-bold text-sm",style:{color:r.color},children:r.name||"Channel Name"}),e.jsx("p",{className:"text-[10px] text-muted-foreground",children:r.slug||"channel-slug"})]})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-xs font-bold text-muted-foreground",children:"Name"}),e.jsx(q,{value:r.name,onChange:f=>h(f.target.value),className:"mt-1"})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-xs font-bold text-muted-foreground",children:"Slug"}),e.jsx(q,{value:r.slug,onChange:f=>{g(!1),i(d=>({...d,slug:f.target.value}))},className:"mt-1 font-mono text-xs"})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-xs font-bold text-muted-foreground",children:"Description"}),e.jsx(Te,{value:r.description,onChange:f=>i(d=>({...d,description:f.target.value})),rows:2,className:"mt-1"})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-xs font-bold text-muted-foreground",children:"Icon Emoji"}
46),e.jsx(q,{value:r.icon_url,onChange:f=>i(d=>({...d,icon_url:f.target.value})),placeholder:"🟣",className:"mt-1"})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-xs font-bold text-muted-foreground",children:"Color"}),e.jsxs("div",{className:"flex items-center gap-2 mt-1 flex-wrap",children:[er.map(f=>e.jsx("button",{onClick:()=>i(d=>({...d,color:f})),className:`w-7 h-7 rounded-lg border-2 transition-all ${r.color===f?"border-foreground scale-110":"border-transparent"}`,style:{backgroundColor:f}},f)),e.jsx(q,{value:r.color,onChange:f=>i(d=>({...d,color:f.target.value})),className:"w-24 text-xs font-mono"})]})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-xs font-bold text-muted-foreground",children:"Hero Image"}),e.jsxs("div",{className:"mt-1",children:[r.hero_image_url&&e.jsx("img",{src:r.hero_image_url,alt:"",className:"w-full h-24 object-cover rounded-lg mb-2"}),e.jsxs("label",{className:"inline-flex items-center gap-2 px-3 py-1.5 rounded-lg bg-muted text-sm font-medium cursor-pointer hover:bg-muted/80 transition-colors",children:[e.jsx(ss,{className:"h-3.5 w-3.5"})," ",o?"Uploading...":"Upload",e.jsx("input",{type:"file",accept:"image/*",onChange:b,className:"hidden"})]})]})]}),e.jsxs("div",{className:"flex gap-2 pt-2",children:[e.jsx("button",{onClick:n,className:"px-4 py-2 rounded-xl text-sm text-muted-foreground hover:text-foreground transition-colors",children:"Cancel"}),e.jsxs("button",{onClick:j,disabled:l,className:"flex-1 py-2.5 rounded-xl bg-primary text-primary-foreground text-sm font-semibold disabled:opacity-50 flex items-center justify-center gap-2",children:[l?e.jsx(H,{className:"h-4 w-4 animate-spin"}):e.jsx(he,{className:"h-4 w-4"}),t==="create"?"Create":"Save"]})]})]})]})})},Zs=["playlist","learning_path","module"],rr=["beginner","intermediate","advanced"],nr=()=>{const[t,s]=u.useState([]),[n,a]=u.useState([]),[r,i]=u.useState(!0),[l,m]=u.useState(""),[o,c]=u.useState(null),x=u.useCallback(async()=>{i(!0);let b=S.from("playlists").select("*, channels(name, color)").order("sort_order");l&&(b=b.eq("type",l));const{data:j}=await b;j&&s(j),i(!1)},[l]);u.useEffect(()=>{x()},[x]),u.useEffect(()=>{S.from("channels").select("id, name, color").order("name").then(({data:b})=>{b&&a(b)})},[]);const g=async b=>{if(!confirm(`Delete "${b.title}"?`))return;await S.from("playlist_videos").delete().eq("playlist_id",b.id);const{error:j}=await S.from("playlists").delete().eq("id",b.id);j?w.error(j.message):(w.success("Deleted"),x())},h=b=>b?`${Math.floor(b/3600)}h ${Math.floor(b%3600/60)}m`:"—";return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-6 flex-wrap gap-3",children:[e.jsx("h2",{className:"text-2xl font-extrabold text-foreground",children:"Playlists"}),e.jsxs("button",{onClick:()=>c("new"),className:"px-4 py-2 rounded-xl bg-primary text-primary-foreground text-sm font-semibold hover:opacity-90 transition-opacity flex items-center gap-2",children:[e.jsx(ye,{className:"h-4 w-4"})," Create Playlist"]})]}),e.jsx("div",{className:"flex gap-2 mb-4",children:["",...Zs].map(b=>e.jsx("button",{onClick:()=>m(b),className:`px-3 py-1.5 rounded-lg text-xs font-semibold capitalize transition-colors ${l===b?"bg-primary text-primary-foreground":"bg-muted text-muted-foreground hover:bg-muted/80"}`,children:b||"All"},b))}),e.jsx("div",{className:"academy-card overflow-hidden",children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b bg-muted/30",children:[e.jsx("th",{className:"text-left p-3 text-xs font-bold text-muted-foreground uppercase tracking-wider",children:"Title"}),e.jsx("th",{className:"text-left p-3 text-xs font-bold text-muted-foreground uppercase tracking-wider",children:"Type"}),e.jsx("th",{className:"text-left p-3 text-xs font-bold text-muted-foreground uppercase tracking-wider",children:"Channel"}),e.jsx("th",{className:"text-right p-3 text-xs font-bold text-muted-foreground uppercase tracking-wider",children:"Videos"}),e.jsx("th",{className:"text-right p-3 text-xs font-bold text-muted-foreground uppercase tracking-wider",children:"Duration"}),e.jsx("th",{className:"text-left p-3 text-xs font-bold text-muted-foreground uppercase tracking-wider",children:"Difficulty"}),e.jsx("th",{className:"text-right p-3 text-xs font-bold text-muted-foreground uppercase tracking-wider",children:"Actions"})]})}),e.jsx("tbody",{children:r?Array.from({length:3}).map((b,j)=>e.jsx("tr",{className:"border-b",children:e.jsx("td",{colSpan:7,className:"p-3",children:e.jsx("div",{className:"h-8 rounded skeleton-shimmer"})})}
46,j)):t.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:7,className:"p-8 text-center text-muted-foreground",children:"No playlists"})}):t.map(b=>e.jsxs("tr",{className:"border-b hover:bg-muted/20 transition-colors",children:[e.jsx("td",{className:"p-3 font-semibold text-foreground text-xs",children:b.title}),e.jsx("td",{className:"p-3",children:e.jsx("span",{className:"text-[10px] font-semibold px-2 py-0.5 rounded-full bg-muted text-muted-foreground capitalize",children:b.type||"playlist"})}),e.jsx("td",{className:"p-3",children:b.channels?e.jsx("span",{className:"text-[11px] font-medium px-2 py-0.5 rounded-full",style:{background:`${b.channels.color}15`,color:b.channels.color},children:b.channels.name}):"—"}),e.jsx("td",{className:"p-3 text-right text-xs text-muted-foreground",children:b.video_count||0}),e.jsx("td",{className:"p-3 text-right text-xs text-muted-foreground",children:h(b.total_duration)}),e.jsx("td",{className:"p-3 text-xs capitalize text-muted-foreground",children:b.difficulty||"—"}),e.jsx("td",{className:"p-3",children:e.jsxs("div",{className:"flex items-center gap-1 justify-end",children:[e.jsx("button",{onClick:()=>c(b),className:"p-1.5 rounded-lg hover:bg-muted transition-colors",children:e.jsx(Ue,{className:"h-3.5 w-3.5 text-muted-foreground"})}),e.jsx("button",{onClick:()=>g(b),className:"p-1.5 rounded-lg hover:bg-destructive/10 transition-colors",children:e.jsx(ze,{className:"h-3.5 w-3.5 text-destructive"})})]})})]},b.id))})]})})}),o&&e.jsx(ir,{playlist:o==="new"?null:o,channels:n,onClose:()=>c(null),onSuccess:x})]})},ir=({playlist:t,channels:s,onClose:n,onSuccess:a})=>
46{const r=!t,[i,l]=u.useState({title:(t==null?void 0:t.title)||"",description:(t==null?void 0:t.description)||"",type:(t==null?void 0:t.type)||"playlist",channelId:(t==null?void 0:t.channel_id)||"",difficulty:(t==null?void 0:t.difficulty)||"intermediate",isFree:(t==null?void 0:t.is_free)??!1,thumbnailUrl:(t==null?void 0:t.thumbnail_url)||""}),[m,o]=u.useState([]),[c,x]=u.useState(""),[g,h]=u.useState([]),[b,j]=u.useState(!1),[f,d]=u.useState(!1),[C,E]=u.useState(!1);u.useEffect(()=>{t&&S.from("playlist_videos").select("id, video_id, position, is_milestone, milestone_label, videos:video_id(id, title, duration_seconds, time_savings_multiplier, channels(name, color))").eq("playlist_id",t.id).order("position").then(({data:N})=>{N&&o(N.map(I=>({id:I.id,video_id:I.video_id,position:I.position,is_milestone:I.is_milestone||!1,milestone_label:I.milestone_label||"",video:I.videos})))})},[t]),u.useEffect(()=>{if(c.length<2){h([]);return}const N=setTimeout(async()=>{j(!0);const{data:I}=await S.from("videos").select("id, title, duration_seconds, time_savings_multiplier, channels(name, color)").ilike("title",`%${c}%`).limit(10);h(I||[]),j(!1)},300);return()=>clearTimeout(N)},[c]);const D=N=>{if(m.some(I=>I.video_id===N.id)){w.error("Already added");return}o(I=>[...I,{video_id:N.id,position:I.length,is_milestone:!1,milestone_label:"",video:N}]),x(""),h([])},k=N=>o(I=>I.filter((z,A)=>A!==N).map((z,A)=>({...z,position:A}))),O=(N,I)=>{const z=N+I;if(z<0||z>=m.length)return;const A=[...m];[A[N],A[z]]=[A[z],A[N]],o(A.map((B,U)=>({...B,position:U})))},T=N=>o(I=>I.map((z,A)=>A===N?{...z,is_milestone:!z.is_milestone}:z)),p=(N,I)=>o(z=>z.map((A,B)=>B===N?{...A,milestone_label:I}:A)),_=m.reduce((N,I)=>{var z;return N+(((z=I.video)==null?void 0:z.duration_seconds)||0)},0),M=m.reduce((N,I)=>{var z;return N+(((z=I.video)==null?void 0:z.time_savings_multiplier)||0)},0),R=async N=>{var U;const I=(U=N.target.files)==null?void 0:U[0];if(!I)return;E(!0);const z=`playlist-thumbnails/${Date.now()}-${I.name}`,{error:A}=await S.storage.from("academy-art").upload(z,I,{upsert:!0});if(A){w.error(A.message),E(!1);return}const{data:{publicUrl:B}}=S.storage.from("academy-art").getPublicUrl(z);l($=>({...$,thumbnailUrl:B})),E(!1)},v=async()=>{if(!i.title){w.error("Title required");return}d(!0);const N={title:i.title,description:i.description||null,type:i.type,channel_id:i.channelId||null,difficulty:i.difficulty,is_free:i.isFree,thumbnail_url:i.thumbnailUrl||null,video_count:m.length,total_duration:_,total_time_savings:M};let I=t==null?void 0:t.id;if(r){const{data:z,error:A}=await S.from("playlists").insert({...N,sort_order:999}).select("id").single();if(A){w.error(A.message),d(!1);return}I=z.id}else{const{error:z}=await S.from("playlists").update(N).eq("id",I);if(z){w.error(z.message),d(!1);return}await S.from("playlist_videos").delete().eq("playlist_id",I)}if(m.length>0){const z=m.map((B,U)=>({playlist_id:I,video_id:B.video_id,position:U,is_milestone:B.is_milestone,milestone_label:B.milestone_label||null})),{error:A}=await S.from("playlist_videos").insert(z);if(A){w.error(A.message),d(!1);return}}d(!1),w.success(r?"Playlist created":"Playlist updated"),a(),n()},P=N=>`${Math.floor(N/60)}:${String(N%60).padStart(2,"0")}`;return e.jsx(pe,{open:!0,onOpenChange:N=>{N||n()},children:e.jsxs(fe,{className:"max-w-2xl max-h-[85vh] overflow-hidden flex flex-col",children:[e.jsx(ge,{children:e.jsx(be,{children:r?"Create Playlist":"Edit Playlist"})}),e.jsxs("div",{className:"flex-1 overflow-y-auto space-y-4 pr-1",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("label",{className:"block col-span-2",children:[e.jsx("span",{className:"text-xs font-bold text-muted-foreground",children:"Title"}),e.jsx(q,{value:i.title,onChange:N=>l(I=>({...I,title:N.target.value})),className:"mt-1"})]}),e.jsxs("label",{className:"block col-span-2",children:[e.jsx("span",{className:"text-xs font-bold text-muted-foreground",children:"Description"}),e.jsx(Te,{value:i.description,onChange:N=>l(I=>({...I,description:N.target.value})),rows:2,className:"mt-1"})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-xs font-bold text-muted-foreground",children:"Type"}
46),e.jsx("select",{value:i.type,onChange:N=>l(I=>({...I,type:N.target.value})),className:"w-full mt-1 px-3 py-2 rounded-xl border bg-background text-sm capitalize",children:Zs.map(N=>e.jsx("option",{value:N,children:N.replace("_"," ")},N))})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-xs font-bold text-muted-foreground",children:"Channel (optional)"}),e.jsxs("select",{value:i.channelId,onChange:N=>l(I=>({...I,channelId:N.target.value})),className:"w-full mt-1 px-3 py-2 rounded-xl border bg-background text-sm",children:[e.jsx("option",{value:"",children:"Cross-channel"}),s.map(N=>e.jsx("option",{value:N.id,children:N.name},N.id))]})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-xs font-bold text-muted-foreground",children:"Difficulty"}),e.jsx("select",{value:i.difficulty,onChange:N=>l(I=>({...I,difficulty:N.target.value})),className:"w-full mt-1 px-3 py-2 rounded-xl border bg-background text-sm capitalize",children:rr.map(N=>e.jsx("option",{value:N,children:N},N))})]}),e.jsxs("label",{className:"flex items-center gap-2 self-end pb-2",children:[e.jsx("input",{type:"checkbox",checked:i.isFree,onChange:N=>l(I=>({...I,isFree:N.target.checked})),className:"rounded"}),e.jsx("span",{className:"text-sm",children:"Free"})]})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-xs font-bold text-muted-foreground",children:"Thumbnail"}),e.jsxs("div",{className:"flex items-center gap-3 mt-1",children:[i.thumbnailUrl&&e.jsx("img",{src:i.thumbnailUrl,alt:"",className:"w-24 h-14 object-cover rounded-lg"}),e.jsxs("label",{className:"inline-flex items-center gap-2 px-3 py-1.5 rounded-lg bg-muted text-sm font-medium cursor-pointer hover:bg-muted/80 transition-colors",children:[e.jsx(ss,{className:"h-3.5 w-3.5"})," ",C?"Uploading...":"Upload",e.jsx("input",{type:"file",accept:"image/*",onChange:R,className:"hidden"})]})]})]}),e.jsxs("div",{className:"flex gap-4 p-3 rounded-xl bg-muted/50 text-xs",children:[e.jsxs("span",{className:"text-muted-foreground",children:[e.jsx("b",{className:"text-foreground",children:m.length})," videos"]}),e.jsxs("span",{className:"text-muted-foreground",children:[e.jsxs("b",{className:"text-foreground",children:[Math.floor(_/3600),"h ",Math.floor(_%3600/60),"m"]})," total"]}),e.jsxs("span",{className:"text-muted-foreground",children:[e.jsxs("b",{className:"text-foreground",children:[M,"x"]})," time savings"]})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-xs font-bold text-muted-foreground",children:"Add Videos"}),e.jsxs("div",{className:"relative mt-1",children:[e.jsx($t,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(q,{placeholder:"Search videos by title...",value:c,onChange:N=>x(N.target.value),className:"pl-9"})]}),g.length>0&&e.jsx("div",{className:"mt-1 border rounded-xl bg-background max-h-40 overflow-y-auto",children:g.map(N=>e.jsxs("button",{onClick:()=>D(N),className:"w-full flex items-center gap-3 p-2.5 hover:bg-muted/50 text-left transition-colors",children:[e.jsx(ye,{className:"h-3.5 w-3.5 text-primary shrink-0"}),e.jsx("span",{className:"text-xs font-medium text-foreground line-clamp-1 flex-1",children:N.title}),N.channels&&e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded-full shrink-0",style:{background:`${N.channels.color}15`,color:N.channels.color},children:N.channels.name}),e.jsx("span",{className:"text-[10px] text-muted-foreground shrink-0",children:P(N.duration_seconds||0)})]},N.id))}),b&&e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"Searching..."})]}),m.length>0&&e.jsxs("div",{className:"space-y-1",children:[e.jsx("span",{className:"text-xs font-bold text-muted-foreground",children:"Playlist Order"}),m.map((N,I)=>{var z,A,B;return e.jsxs("div",{className:"flex items-center gap-2 p-2 rounded-lg bg-muted/30 border border-transparent hover:border-border transition-colors",children:[e.jsxs("div",{className:"flex flex-col gap-0.5 shrink-0",children:[e.jsx("button",{onClick:()=>O(I,-1),disabled:I===0,className:"text-[9px] text-muted-foreground hover:text-foreground disabled:opacity-20",children:"▲"}),e.jsx("button",{onClick:()=>O(I,1),disabled:I===m.length-1,className:"text-[9px] text-muted-foreground hover:text-foreground disabled:opacity-20",children:"▼"})]}),e.jsx("span",{className:"text-xs font-bold text-muted-foreground w-5 text-center shrink-0",children:I+1}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-xs font-semibold text-foreground line-clamp-1",children:((z=N.video)==null?void 0:z.title)||N.video_id}),e.jsxs("div",{className:"flex items-center gap-2 mt-0.5",children:[((A=N.video)==null?void 0:A.channels)&&e.jsx("span",{className:"text-[9px] px-1.5 py-0.5 rounded-full",style:{background:`${N.video.channels.color}15`,color:N.video.channels.color},children:N.video.channels.name}),e.jsx("span",{className:"text-[9px] text-muted-foreground",children:P(((B=N.video)==null?void 0:B.duration_seconds)||0)})]})]}),e.jsx("button",{onClick:()=>T(I),className:`p-1 rounded-md transition-colors ${N.is_milestone?"bg-amber-500/10 text-amber-500":"text-muted-foreground hover:text-foreground"}`,title:"Toggle milestone",children:e.jsx(as,{className:"h-3.5 w-3.5",fill:N.is_milestone?"currentColor":"none"})}),N.is_milestone&&e.jsx(q,{value:N.milestone_label,onChange:U=>p(I,U.target.value),placeholder:"Milestone label",className:"w-28 h-7 text-[10px]"}),e.jsx("button",{onClick:()=>k(I),className:"p-1 rounded-md text-muted-foreground hover:text-destructive transition-colors",children:e.jsx(Rt,{className:"h-3.5 w-3.5"})})]},N.video_id)})]}),e.jsxs("div",{className:"flex gap-2 pt-2",children:[e.jsx("button",{onClick:n,className:"px-4 py-2 rounded-xl text-sm text-muted-foreground hover:text-foreground transition-colors",children:"Cancel"}),e.jsxs("button",{onClick:v,disabled:f,className:"flex-1 py-2.5 rounded-xl bg-primary text-primary-foreground text-sm font-semibold disabled:opacity-50 flex items-center justify-center gap-2",children:[f?e.jsx(H,{className:"h-4 w-4 animate-spin"}):e.jsx(he,{className:"h-4 w-4"}),r?"Create Playlist":"Save Changes"]})]})]})]})})},lr=()=>{const[t,s]=u.useState([]),[n,a]=u.useState([]),[r,i]=u.useState(!0),[l,m]=u.useState(!1),[o,c]=u.useState(null),[x,g]=u.useState(null),[h,b]=u.useState(""),[j,f]=u.useState(""),[d,C]=u.useState("channel"),[E,D]=u.useState(""),[k,O]=u.useState(!1),[T,p]=u.useState("daily"),[_,M]=u.useState(!0),R=u.useCallback(async()=>{i(!0);const[{data:$},{data:X}]=await Promise.all([S.from("youtube_sources").select("*, channels(name, color)").order("created_at",{ascending:!1}),S.from("channels").select("id, name, color").order("name")]);$&&s($),X&&a(X),i(!1)},[]);u.useEffect(()=>{R()},[R]);const v=$=>$.includes("playlist")||$.includes("list=")?"playlist":"channel",P=()=>{c(null),b(""),f(""),C("channel"),D(""),O(!1),p("daily"),M(!0),m(!0)},N=$=>{c($),b($.name),f($.youtube_url),C($.type||"channel"),D($.channel_id||""),O($.auto_approve||!1),p($.sync_frequency||"daily"),M($.is_active!==!1),m(!0)},I=$=>{f($),C(v($))},z=async()=>
46{if(!h.trim()||!j.trim()){w.error("Name and URL are required");return}const $={name:h.trim(),youtube_url:j.trim(),type:d,channel_id:E||null,auto_approve:k,sync_frequency:T,is_active:_};if(o){const{error:X}=await S.from("youtube_sources").update($).eq("id",o.id);if(X){w.error("Failed to update source");return}w.success("Source updated")}else{const{error:X}=await S.from("youtube_sources").insert($);if(X){w.error("Failed to add source");return}w.success("Source added")}m(!1),R()},A=async $=>{confirm("Delete this source?")&&(await S.from("youtube_sources").delete().eq("id",$),w.success("Source deleted"),R())},B=async $=>{g($);try{const{error:X}=await S.functions.invoke("academy-aggregate",{body:{source_id:$}});if(X)throw X;w.success("Sync triggered"),R()}catch{w.error("Sync failed — YouTube API key may not be configured")}finally{g(null)}},U=async()=>{g("all");try{const{error:$}=await S.functions.invoke("academy-aggregate",{body:{}});if($)throw $;w.success("Full sync triggered"),R()}catch{w.error("Sync failed — YouTube API key may not be configured")}finally{g(null)}};return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-6",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-bold text-foreground",children:"YouTube Sources"}),e.jsx("p",{className:"text-sm text-muted-foreground mt-0.5",children:"Manage content sources for Bandit's aggregation engine"})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("button",{onClick:U,disabled:x==="all",className:"flex items-center gap-2 px-4 py-2 rounded-lg bg-muted text-foreground text-sm font-medium hover:bg-muted/80 transition-colors disabled:opacity-50",children:[x==="all"?e.jsx(H,{className:"h-4 w-4 animate-spin"}):e.jsx(xt,{className:"h-4 w-4"}),"Sync All"]}),e.jsxs("button",{onClick:P,className:"flex items-center gap-2 px-4 py-2 rounded-lg bg-primary text-primary-foreground text-sm font-medium hover:bg-primary/90 transition-colors",children:[e.jsx(ye,{className:"h-4 w-4"})," Add Source"]})]})]}),r?e.jsx("div",{className:"flex items-center justify-center py-20",children:e.jsx(H,{className:"h-6 w-6 animate-spin text-primary"})}):e.jsx("div",{className:"border border-border rounded-xl overflow-hidden",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"bg-muted/50 border-b border-border",children:[e.jsx("th",{className:"text-left px-4 py-3 font-semibold text-muted-foreground",children:"Name"}),e.jsx("th",{className:"text-left px-4 py-3 font-semibold text-muted-foreground",children:"Type"}),e.jsx("th",{className:"text-left px-4 py-3 font-semibold text-muted-foreground",children:"Channel"}),e.jsx("th",{className:"text-center px-4 py-3 font-semibold text-muted-foreground",children:"Auto"}),e.jsx("th",{className:"text-center px-4 py-3 font-semibold text-muted-foreground",children:"Freq"}),e.jsx("th",{className:"text-left px-4 py-3 font-semibold text-muted-foreground",children:"Last Synced"}),e.jsx("th",{className:"text-center px-4 py-3 font-semibold text-muted-foreground",children:"Active"}),e.jsx("th",{className:"text-right px-4 py-3 font-semibold text-muted-foreground",children:"Actions"})]})}),e.jsxs("tbody",{children:[t.map($=>e.jsxs("tr",{className:"border-b border-border/50 hover:bg-muted/20 transition-colors",children:[e.jsxs("td",{className:"px-4 py-3",children:[e.jsx("div",{className:"font-medium text-foreground",children:$.name}),e.jsxs("a",{href:$.youtube_url,target:"_blank",rel:"noopener",className:"text-[11px] text-muted-foreground hover:text-primary flex items-center gap-1 mt-0.5",children:[e.jsx(Mt,{className:"h-3 w-3"})," YouTube"]})]}),e.jsx("td",{className:"px-4 py-3",children:e.jsxs("span",{className:"inline-flex items-center gap-1 text-xs font-medium bg-muted px-2 py-0.5 rounded-full text-muted-foreground",children:[$.type==="playlist"?e.jsx(Qs,{className:"h-3 w-3"}):e.jsx(Cs,{className:"h-3 w-3"}),$.type||"channel"]})}),e.jsx("td",{className:"px-4 py-3",children:$.channels?e.jsx("span",{className:"text-xs font-semibold px-2 py-0.5 rounded-full text-white",style:{backgroundColor:$.channels.color},children:$.channels.name}):e.jsx("span",{className:"text-xs text-muted-foreground",children:"—"})}),e.jsx("td",{className:"px-4 py-3 text-center",children:$.auto_approve?e.jsx(he,{className:"h-4 w-4 text-emerald-500 mx-auto"}
46):e.jsx(Rt,{className:"h-4 w-4 text-muted-foreground/40 mx-auto"})}),e.jsx("td",{className:"px-4 py-3 text-center text-xs text-muted-foreground",children:$.sync_frequency||"daily"}),e.jsx("td",{className:"px-4 py-3 text-xs text-muted-foreground",children:$.last_synced_at?new Date($.last_synced_at).toLocaleDateString():"Never"}),e.jsx("td",{className:"px-4 py-3 text-center",children:e.jsx("span",{className:`inline-block h-2 w-2 rounded-full ${$.is_active!==!1?"bg-emerald-500":"bg-muted-foreground/30"}`})}),e.jsx("td",{className:"px-4 py-3 text-right",children:e.jsxs("div",{className:"flex items-center justify-end gap-1",children:[e.jsx("button",{onClick:()=>B($.id),disabled:x===$.id,className:"p-1.5 rounded-md hover:bg-muted text-muted-foreground hover:text-foreground transition-colors",title:"Sync now",children:x===$.id?e.jsx(H,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(xt,{className:"h-3.5 w-3.5"})}),e.jsx("button",{onClick:()=>N($),className:"p-1.5 rounded-md hover:bg-muted text-muted-foreground hover:text-foreground transition-colors",children:e.jsx(Ue,{className:"h-3.5 w-3.5"})}),e.jsx("button",{onClick:()=>A($.id),className:"p-1.5 rounded-md hover:bg-destructive/10 text-muted-foreground hover:text-destructive transition-colors",children:e.jsx(ze,{className:"h-3.5 w-3.5"})})]})})]},$.id)),t.length===0&&e.jsx("tr",{children:e.jsx("td",{colSpan:8,className:"text-center py-12 text-muted-foreground",children:"No sources yet. Add YouTube channels or playlists to start aggregating."})})]})]})}),e.jsx(pe,{open:l,onOpenChange:m,children:e.jsxs(fe,{className:"max-w-md",children:[e.jsx(ge,{children:e.jsx(be,{children:o?"Edit Source":"Add YouTube Source"})}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-medium text-muted-foreground mb-1 block",children:"YouTube URL"}),e.jsx(q,{value:j,onChange:$=>I($.target.value),placeholder:"https://youtube.com/@channel or playlist URL"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-medium text-muted-foreground mb-1 block",children:"Name"}),e.jsx(q,{value:h,onChange:$=>b($.target.value),placeholder:"Source name"})]}),e.jsxs("div",{className:"flex gap-4",children:[e.jsxs("div",{className:"flex-1",children:[e.jsx("label",{className:"text-xs font-medium text-muted-foreground mb-1 block",children:"Type (auto-detected)"}),e.jsxs("select",{value:d,onChange:$=>C($.target.value),className:"w-full h-10 rounded-md border border-input bg-background px-3 text-sm",children:[e.jsx("option",{value:"channel",children:"Channel"}),e.jsx("option",{value:"playlist",children:"Playlist"})]})]}),e.jsxs("div",{className:"flex-1",children:[e.jsx("label",{className:"text-xs font-medium text-muted-foreground mb-1 block",children:"Sync Frequency"}),e.jsxs("select",{value:T,onChange:$=>p($.target.value),className:"w-full h-10 rounded-md border border-input bg-background px-3 text-sm",children:[e.jsx("option",{value:"daily",children:"Daily"}),e.jsx("option",{value:"weekly",children:"Weekly"}),e.jsx("option",{value:"manual",children:"Manual Only"})]})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-medium text-muted-foreground mb-1 block",children:"Assign to Channel"}),e.jsxs("select",{value:E,onChange:$=>D($.target.value),className:"w-full h-10 rounded-md border border-input bg-background px-3 text-sm",children:[e.jsx("option",{value:"",children:"— None —"}),n.map($=>e.jsx("option",{value:$.id,children:$.name},$.id))]})]}),e.jsxs("div",{className:"flex items-center gap-6",children:[e.jsxs("label",{className:"flex items-center gap-2 text-sm",children:[e.jsx("input",{type:"checkbox",checked:k,onChange:$=>O($.target.checked),className:"rounded"}),"Auto-approve (skip review queue)"]}),e.jsxs("label",{className:"flex items-center gap-2 text-sm",children:[e.jsx("input",{type:"checkbox",checked:_,onChange:$=>M($.target.checked),className:"rounded"}),"Active"]})]}),e.jsxs("div",{className:"flex gap-2 pt-2",children:[e.jsx("button",{onClick:()=>m(!1),className:"flex-1 py-2 rounded-lg border border-border text-sm font-medium text-muted-foreground hover:bg-muted transition-colors",children:"Cancel"}),e.jsx("button",{onClick:z,className:"flex-1 py-2 rounded-lg bg-primary text-primary-foreground text-sm font-medium hover:bg-primary/90 transition-colors",children:o?"Save Changes":"Add Source"})]})]})]})})]})},or=["beginner","intermediate","advanced"],cr=()=>{const[t,s]=u.useState([]),[n,a]=u.useState([]),[r,i]=u.useState(!0),[l,m]=u.useState(new Set),[o,c]=u.useState(null),[x,g]=u.useState(""),[h,b]=u.useState("all"),[j,f]=u.useState(""),[d,C]=u.useState("beginner"),[E,D]=u.useState(""),[k,O]=u.useState("1"),T=u.useCallback(async()=>{i(!0);const[{data:A},{data:B}]=await Promise.all([S.from("aggregation_queue").select("*, youtube_sources(name, channel_id, channels(name, color))").eq("status","pen
46ding").order("relevance_score",{ascending:!1}),S.from("channels").select("id, name, color").order("name")]);A&&s(A),B&&a(B),i(!1)},[]);u.useEffect(()=>{T()},[T]);const p=t.filter(A=>{var U,$;if(x&&!(($=(U=A.youtube_sources)==null?void 0:U.name)!=null&&$.toLowerCase().includes(x.toLowerCase())))return!1;const B=A.relevance_score||0;return!(h==="high"&&B<.7||h==="medium"&&(B<.3||B>=.7)||h==="low"&&B>=.3)}),_=A=>{var U;c(A);const B=((U=A.youtube_sources)==null?void 0:U.channel_id)||"";f(B),C("beginner"),D(""),O("1")},M=async()=>{if(!o)return;const{error:A}=await S.from("videos").insert({title:o.title||"Untitled",youtube_id:o.youtube_id,youtube_url:o.youtube_url,thumbnail_url:o.thumbnail_url,duration_seconds:o.duration_seconds,description:o.description,channel_id:j||null,difficulty:d,tags:E?E.split(",").map(B=>B.trim()):[],time_savings_multiplier:parseFloat(k)||1,source:"aggregated",is_free:!0});if(A){w.error("Failed to create video");return}await S.from("aggregation_queue").update({status:"approved",reviewed_at:new Date().toISOString()}).eq("id",o.id),S.functions.invoke("academy-transcript",{body:{video_id:o.id}}).catch(()=>{}),w.success(`Approved: ${o.title}`),c(null),T()},R=async A=>{await S.from("aggregation_queue").update({status:"rejected",reviewed_at:new Date().toISOString()}).eq("id",A),w.success("Rejected"),T()},v=async()=>{var U;if(l.size===0)return;const A=t.filter($=>l.has($.id));let B=0;for(const $ of A){const X=((U=$.youtube_sources)==null?void 0:U.channel_id)||null,{error:lt}=await S.from("videos").insert({title:$.title||"Untitled",youtube_id:$.youtube_id,youtube_url:$.youtube_url,thumbnail_url:$.thumbnail_url,duration_seconds:$.duration_seconds,description:$.description,channel_id:X,difficulty:"beginner",source:"aggregated",is_free:!0});lt||(await S.from("aggregation_queue").update({status:"approved",reviewed_at:new Date().toISOString()}).eq("id",$.id),B++)}w.success(`Approved ${B} videos`),m(new Set),T()},P=A=>{m(B=>{const U=new Set(B);return U.has(A)?U.delete(A):U.add(A),U})},N=()=>{l.size===p.length?m(new Set):m(new Set(p.map(A=>A.id)))},I=A=>A>=.7?"bg-emerald-500":A>=.3?"bg-amber-500":"bg-red-500",z=A=>A?`${Math.floor(A/60)}m`:"";return r?e.jsx("div",{className:"flex items-center justify-center py-20",children:e.jsx(H,{className:"h-6 w-6 animate-spin text-primary"})}):e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-6",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-bold text-foreground",children:"Review Queue"}),e.jsxs("p",{className:"text-sm text-muted-foreground mt-0.5",children:[p.length," videos pending review"]})]}),l.size>0&&e.jsxs("button",{onClick:v,className:"flex items-center gap-2 px-4 py-2 rounded-lg bg-emerald-600 text-white text-sm font-medium hover:bg-emerald-700 transition-colors",children:[e.jsx(he,{className:"h-4 w-4"})," Approve ",l.size," Selected"]})]}),e.jsxs("div",{className:"flex gap-3 mb-4 items-center",children:[e.jsx(ba,{className:"h-4 w-4 text-muted-foreground shrink-0"}),e.jsx(q,{value:x,onChange:A=>g(A.target.value),placeholder:"Filter by source...",className:"max-w-[200px] h-8 text-xs"}),e.jsx("div",{className:"flex gap-1",children:["all","high","medium","low"].map(A=>e.jsx("button",{onClick:()=>b(A),className:`px-2.5 py-1 rounded-md text-xs font-medium transition-colors ${h===A?"bg-primary text-primary-foreground":"bg-muted text-muted-foreground hover:text-foreground"}`,children:A==="all"?"All":A.charAt(0).toUpperCase()+A.slice(1)},A))}),e.jsxs("label",{className:"flex items-center gap-1.5 text-xs text-muted-foreground ml-auto cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:l.size===p.length&&p.length>0,onChange:N,className:"rounded"}),"Select all"]})]}),p.length===0?e.jsxs("div",{className:"text-center py-20",children:[e.jsx("span",{className:"text-5xl block mb-3",children:"🦝"}),e.jsx("p",{className:"text-lg font-semibold text-foreground",children:"All caught up!"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"No new content to review"})]}):e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4",children:p.map(A=>{var $,X;const B=A.relevance_score||0,U=l.has(A.id);return e.jsxs("div",{className:`rounded-xl border overflow-hidden bg-card transition-all ${U?"border-primary ring-2 ring-primary/20":"border-border"}`,children:[e.jsxs("div",{className:"relative aspect-video bg-muted",children:[A.thumbnail_url?e.jsx("img",{src:A.thumbnail_url,alt:"",className:"w-full h-full object-cover"}):e.jsx("div",{className:"w-full h-full flex items-center justify-center text-3xl",children:"🎬"}),A.duration_seconds&&e.jsx("span",{className:"absolute bottom-2 right-2 text-[10px] font-mono bg-black/80 text-white px-1.5 py-0.5 rounded",children:z(A.duration_seconds)}),e.jsx("label",{className:"absolute top-2 left-2 cursor-pointer",children:e.jsx("input",{type:"checkbox",checked:U,onChange:()=>P(A.id),className:"rounded"})})]}),e.jsxs("div",{className:"p-3 space-y-2",children:[e.jsx("h4",{className:"text-sm font-semibold text-foreground line-clamp-2 leading-snug",children:A.title||"Untitled"}),A.description&&e.jsx("p",{className:"text-xs text-muted-foreground line-clamp-3",children:A.description}),(($=A.youtube_sources)==null?void 0:$.name)&&e.jsx("span",{className:"inline-block text-[10px] font-medium bg-muted text-muted-foreground px-2 py-0.5 rounded-full",children:A.youtube_sources.name}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"flex-1 h-1.5 rounded-full bg-muted overflow-hidden",children:e.jsx("div",{className:`h-full rounded-full ${I(B)}`,style:{width:`${B*100}%`}})}),e.jsxs("span",{className:"text-[10px] font-mono text-muted-foreground",children:[(B*100).toFixed(0),"%"]})]}),((X=A.youtube_sources)==null?void 0:X.channels)&&e.jsxs("span",{className:"inline-block text-[10px] font-semibold px-2 py-0.5 rounded-full text-white",style:{backgroundColor:A.youtube_sources.channels.color},children:["→ ",A.youtube_sources.channels.name]}),e.jsxs("div",{className:"flex gap-2 pt-1",children:[e.jsxs("button",{onClick:()=>_(A),className:"flex-1 flex items-center justify-center gap-1.5 py-2 rounded-lg bg-emerald-600 text-white text-xs font-semibold hover:bg-emerald-700 transition-colors",children:[e.jsx(he,{className:"h-3.5 w-3.5"})," Approve"]}),e.jsxs("button",{onClick:()=>R(A.id),className:"flex-1 flex items-center justify-center gap-1.5 py-2 rounded-lg bg-destructive text-destructive-foreground text-xs font-semibold hover:bg-destructive/90 transition-colors",children:[e.jsx(Rt,{className:"h-3.5 w-3.5"})," Reject"]})]})]})]},A.id)})}),e.jsx(pe,{open:!!o,onOpenChange:()=>c(null),children:e.jsxs(fe,{className:"max-w-md",children:[e.jsx(ge,{children:e.jsx(be,{children:"Approve Video"})}),o&&e.jsxs("div",{className:"space-y-4",children:[e.jsx("p",{className:"text-sm font-medium text-foreground",children:o.title}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-medium text-muted-foreground mb-1 block",children:"Channel"}),e.jsxs("select",{value:j,onChange:A=>f(A.target.value),className:"w-full h-10 rounded-md border border-input bg-background px-3 text-sm",children:[e.jsx("option",{value:"",children:"— None —"}),n.map(A=>e.jsx("option",{value:A.id,children:A.name},A.id))]})]}),e.jsxs("div",{className:"flex gap-3",children:[e.jsxs("div",{className:"flex-1",children:[e.jsx("label",{className:"text-xs font-medium text-muted-foreground mb-1 block",children:"Difficulty"}),e.jsx("select",{value:d,onChange:A=>C(A.target.value),className:"w-full h-10 rounded-md border border-input bg-background px-3 text-sm",children:or.map(A=>e.jsx("option",{value:A,children:A},A))})]}),e.jsxs("div",{className:"flex-1",children:[e.jsx("label",{className:"text-xs font-medium text-muted-foreground mb-1 block",children:"Time Savings (x)"}),e.jsx(q,{type:"number",min:"1",max:"100",value:k,onChange:A=>O(A.target.value)})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-medium text-muted-foreground mb-1 block",children:"Tags (comma-separated)"}),e.jsx(q,{value:E,onChange:A=>D(A.target.value),placeholder:"AI, coding, tutorial"})]}),e.jsxs("div",{className:"flex gap-2 pt-2",children:[e.jsx("button",{onClick:()=>c(null),className:"flex-1 py-2 rounded-lg border border-border text-sm font-medium text-muted-foreground hover:bg-muted transition-colors",children:"Cancel"}),e.jsx("button",{onClick:M,className:"flex-1 py-2 rounded-lg bg-emerald-600 text-white text-sm font-medium hover:bg-emerald-700 transition-colors",children:"Approve & Add"})]})]})]})})]})},hs=["page-browse","page-channel","page-tutor","page-paths","action-first-complete","action-5-complete","action-first-bookmark","action-returning","milestone-10x","milestone-50x","milestone-100x","milestone-path-complete","onboarding","general"],dr=[{title:"Welcome to Browse!",content:"Welcome! Start by picking a channel that interests you. I recommend Anthropic or OpenAI for beginners!",category:"page-browse",tool:null,difficulty:"beginner"},{title:"Channel Hub",content:"This is the channel hub! Start with the most popular video or jump into a learning path.",category:"page-channel",tool:null,difficulty:"beginner"},{title:"Meet Nimbus",content:"Nimbus knows everything from every video in our library. Try asking a comparison question!",category:"page-tutor",tool:null,difficulty:"beginner"},{title:"Learning Paths",content:"Learning paths are the fastest way to level up. The AI Zero to Hero path is perfect for getting started.",category:"page-paths",tool:null,difficulty:"beginner"},{title:"First Video!",content:"You just earned your first time-savings points! Keep watching to climb the leaderboard.",category:"action-first-complete",tool:null,difficulty:"beginner"},{title:"On a Roll!",content:"You're on a roll! Pro tip: try a full learning path next.",category:"action-5-complete",tool:null,difficulty:"beginner"},{title:"Smart Bookmark",content:"Smart move saving that one! Find your saved videos anytime in your profile.",category:"action-first-bookmark",tool:null,difficulty:"beginner"},{title:"Welcome Back!",content:"Welcome back! Let's keep your streak going!",category:"action-returning",tool:null,difficulty:"beginner"},{title:"🎉 10x Milestone!",content:"You've hit 10x! You're officially AI Curious. Share your badge?",category:"milestone-10x",tool:null,difficulty:"beginner"},{title:"🚀 50x Milestone!",content:"50x! You're AI Capable now. Most people never get this far.",category:"milestone-50x",tool:null,difficulty:"intermediate"},{title:"💎 100x Milestone!",content:"100x HOURS SAVED! You're officially a Power User. Certificate unlocked!",category:"milestone-100x",tool:null,difficulty:"advanced"},{title:"🏆 Path Complete!",content:"Path complete! Nimbus is proud of you.",category:"milestone-path-complete",tool:null,difficulty:"beginner"}],ur=()=>{const[t,s]=u.useState([]),[n,a]=u.useState(!0),[r,i]=u.useState(!1),[l,m]=u.useState(null),[o,c]=u.useState(null),[x,g]=u.useState(""),[h,b]=u.useState(!1),[j,f]=u.useState({title:"",content:"",category:"general",tool:"",difficulty:"beginner"}),d=u.useCallback(async()=>{a(!0);let p=S.from("agent_tips").select("*").order("created_at",{ascending:!1});x&&(p=p.eq("category",x));const{data:_}=await p;s(_||[]),a(!1)},[x]);u.useEffect(()=>{d()},[d]);const C=()=>{m(null),f({title:"",content:"",category:"general",tool:"",difficulty:"beginner"}),i(!0)},E=p=>{m(p),f({title:p.title,content:p.content,category:p.category||"general",tool:p.tool||"",difficulty:p.difficulty||"beginner"}),i(!0)},D=async()=>
46{if(!j.title||!j.content){w.error("Title and content required");return}const p={title:j.title,content:j.content,category:j.category||null,tool:j.tool||null,difficulty:j.difficulty||null};if(l){const{error:_}=await S.from("agent_tips").update(p).eq("id",l.id);_?w.error(_.message):w.success("Updated")}else{const{error:_}=await S.from("agent_tips").insert(p);_?w.error(_.message):w.success("Created")}i(!1),d()},k=async p=>{if(!confirm("Delete this tip?"))return;const{error:_}=await S.from("agent_tips").delete().eq("id",p);_?w.error(_.message):(w.success("Deleted"),d())},O=async p=>{const{error:_}=await S.from("agent_tips").update({is_published:!p.is_published}).eq("id",p.id);_?w.error(_.message):d()},T=async()=>{b(!0);const p=dr.map(M=>({...M,is_published:!0})),{error:_}=await S.from("agent_tips").insert(p);_?w.error(_.message):(w.success(`Seeded ${p.length} tips`),d()),b(!1)};return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-6",children:[e.jsx("h2",{className:"text-2xl font-extrabold text-foreground",children:"Agent Tips (Fizz)"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("button",{onClick:T,disabled:h,className:"px-3 py-2 rounded-lg bg-muted text-foreground text-xs font-semibold hover:bg-muted/80 transition-colors flex items-center gap-1.5 disabled:opacity-50",children:[h?e.jsx(H,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(rs,{className:"h-3.5 w-3.5"})," Seed Defaults"]}),e.jsxs("button",{onClick:C,className:"px-3 py-2 rounded-lg bg-primary text-primary-foreground text-xs font-semibold hover:opacity-90 transition-opacity flex items-center gap-1.5",children:[e.jsx(ye,{className:"h-3.5 w-3.5"})," Add Tip"]})]})]}),e.jsxs("div",{className:"flex gap-2 mb-4 flex-wrap",children:[e.jsx("button",{onClick:()=>g(""),className:`px-3 py-1 rounded-lg text-xs font-medium ${x?"text-muted-foreground hover:text-foreground":"bg-primary/10 text-primary"}`,children:"All"}),hs.map(p=>e.jsx("button",{onClick:()=>g(p),className:`px-3 py-1 rounded-lg text-xs font-medium ${x===p?"bg-primary/10 text-primary":"text-muted-foreground hover:text-foreground"}`,children:p},p))]}),n?e.jsx("div",{className:"flex justify-center py-10",children:e.jsx(H,{className:"h-5 w-5 animate-spin text-muted-foreground"})}):t.length===0?e.jsxs("div",{className:"text-center py-10",children:[e.jsx("span",{className:"text-4xl mb-3 block",children:"🫧"}),e.jsx("p",{className:"text-muted-foreground text-sm",children:'No tips yet. Click "Seed Defaults" to get started!'})]}):e.jsx("div",{className:"space-y-2",children:t.map(p=>e.jsxs("div",{className:"academy-card p-4 flex items-start gap-3",children:[e.jsx("span",{className:"text-xl shrink-0",children:"🫧"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx("span",{className:"text-sm font-bold text-foreground",children:p.title}),p.category&&e.jsx("span",{className:"text-[10px] px-2 py-0.5 rounded-full bg-muted text-muted-foreground font-medium",children:p.category}),e.jsx("span",{className:`text-[10px] px-2 py-0.5 rounded-full font-medium ${p.is_published?"bg-emerald-500/10 text-emerald-600":"bg-red-500/10 text-red-500"}`,children:p.is_published?"Active":"Draft"})]}),e.jsx("p",{className:"text-xs text-muted-foreground line-clamp-2",children:p.content})]}),e.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[e.jsx("button",{onClick:()=>c(p),className:"p-1.5 rounded-lg hover:bg-muted transition-colors text-muted-foreground",children:e.jsx(zt,{className:"h-3.5 w-3.5"})}),e.jsx("button",{onClick:()=>O(p),className:"p-1.5 rounded-lg hover:bg-muted transition-colors text-muted-foreground text-[10px] font-medium",children:p.is_published?"Hide":"Show"}),e.jsx("button",{onClick:()=>E(p),className:"p-1.5 rounded-lg hover:bg-muted transition-colors text-muted-foreground",children:e.jsx(Ue,{className:"h-3.5 w-3.5"})}),e.jsx("button",{onClick:()=>k(p.id),className:"p-1.5 rounded-lg hover:bg-muted transition-colors text-red-400",children:e.jsx(ze,{className:"h-3.5 w-3.5"})})]})]},p.id))}),e.jsx(pe,{open:r,onOpenChange:i,children:e.jsxs(fe,{children:[e.jsx(ge,{children:e.jsx(be,{children:l?"Edit Tip":"Add Tip"})}),e.jsxs("div",{className:"space-y-3",children:[e.jsx(q,{placeholder:"Title",value:j.title,onChange:p=>f(_=>({..._,title:p.target.value}))}),e.jsx(Te,{placeholder:"Tip content...",value:j.content,onChange:p=>f(_=>({..._,content:p.target.value})),rows:3}),e.jsx("select",{value:j.category,onChange:p=>f(_=>({..._,category:p.target.value})),className:"w-full h-10 rounded-md border border-input bg-background px-3 text-sm",children:hs.map(p=>e.jsx("option",{value:p,children:p},p))}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(q,{placeholder:"Tool (optional)",value:j.tool,onCh
46ange:p=>f(_=>({..._,tool:p.target.value}))}),e.jsxs("select",{value:j.difficulty,onChange:p=>f(_=>({..._,difficulty:p.target.value})),className:"w-full h-10 rounded-md border border-input bg-background px-3 text-sm",children:[e.jsx("option",{value:"beginner",children:"Beginner"}),e.jsx("option",{value:"intermediate",children:"Intermediate"}),e.jsx("option",{value:"advanced",children:"Advanced"})]})]}),e.jsxs("button",{onClick:D,className:"w-full py-2.5 rounded-xl bg-primary text-primary-foreground text-sm font-semibold hover:opacity-90 transition-opacity",children:[l?"Update":"Create"," Tip"]})]})]})}),e.jsx(pe,{open:!!o,onOpenChange:()=>c(null),children:e.jsxs(fe,{className:"max-w-xs",children:[e.jsx(ge,{children:e.jsx(be,{children:"Fizz Preview"})}),o&&e.jsx("div",{className:"bg-card rounded-2xl border border-border/50 p-4",children:e.jsxs("div",{className:"flex items-start gap-2.5",children:[e.jsx("span",{className:"text-2xl shrink-0",children:"🫧"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-bold text-foreground",children:o.title}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1 leading-relaxed",children:o.content})]})]})})]})})]})},mr=["upcoming","active","completed","cancelled"],ps={title:"",description:"",scheduled_at:"",end_time:"",duration_minutes:60,max_participants:20,is_free:!1,status:"upcoming",instructor:"",tags:[],zoom_link:"",location:"",is_virtual:!1,price_cents:49700,includes_premium:!0},xr=()=>{const[t,s]=u.useState([]),[n,a]=u.useState(!0),[r,i]=u.useState(!1),[l,m]=u.useState(null),[o,c]=u.useState(ps),[x,g]=u.useState(!1),[h,b]=u.useState(null),[j,f]=u.useState([]),[d,C]=u.useState(!1),E=u.useCallback(async()=>{a(!0);const{data:v}=await S.from("workshops").select("*").order("scheduled_at",{ascending:!1});s(v||[]),a(!1)},[]);u.useEffect(()=>{E()},[E]);const D=()=>{m(null),c(ps),i(!0)},k=v=>{m(v),c({...v,scheduled_at:v.scheduled_at?new Date(v.scheduled_at).toISOString().slice(0,16):"",end_time:v.end_time?new Date(v.end_time).toISOString().slice(0,16):""}),i(!0)},O=async()=>{var P;if(!((P=o.title)!=null&&P.trim())){w.error("Title required");return}g(!0);const v={title:o.title,description:o.description||null,scheduled_at:o.scheduled_at?new Date(o.scheduled_at).toISOString():null,end_time:o.end_time?new Date(o.end_time).toISOString():null,duration_minutes:o.duration_minutes||60,max_participants:o.max_participants||20,is_free:o.is_free||!1,status:o.status||"upcoming",instructor:o.instructor||null,tags:o.tags||[],zoom_link:o.zoom_link||null,location:o.location||null,is_virtual:o.is_virtual||!1,price_cents:o.is_free?0:o.price_cents||49700,includes_premium:o.includes_premium||!1};if(l){const{error:N}=await S.from("workshops").update(v).eq("id",l.id);N?w.error(N.message):w.success("Workshop updated")}else{const{error:N}=await S.from("workshops").insert(v);N?w.error(N.message):w.success("Workshop created")}g(!1),i(!1),E()},T=async v=>{if(!confirm("Delete this workshop?"))return;const{error:P}=await S.from("workshops").delete().eq("id",v);P?w.error(P.message):(w.success("Deleted"),E())},p=async v=>{b(v),C(!0);const{data:P}=await S.from("workshop_registrations").select("*").eq("workshop_id",v.id).order("registered_at",{ascending:!0});f((P||[]).map(N=>({id:N.id,user_id:N.user_id,status:N.status||"registered",attended:N.attended||!1,registered_at:N.registered_at}))),C(!1)},_=async(v,P)=>{await S.from("workshop_registrations").update({attended:P}).eq("id",v),f(N=>N.map(I=>I.id===v?{...I,attended:P}:I))},M=v=>v?new Date(v).toLocaleDateString():"—",R={upcoming:"bg-blue-500/10 text-blue-600",active:"bg-emerald-500/10 text-emerald-600",completed:"bg-muted text-muted-foreground",cancelled:"bg-red-500/10 text-red-500"};return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-6",children:[e.jsx("h2",{className:"text-2xl font-extrabold text-foreground",children:"Workshops"}),e.jsxs("button",{onClick:D,className:"flex items-center gap-2 px-4 py-2 rounded-xl bg-primary text-primary-foreground text-sm font-semibold hover:opacity-90 transition-opacity",children:[e.jsx(ye,{className:"h-4 w-4"})," Create Workshop"]})]}),n?e.jsx("div",{className:"flex justify-center py-12",children:e.jsx(H,{className:"h-6 w-6 animate-spin text-primary"})}):t.length===0?e.jsxs("div",{className:"academy-card p-12 text-center",children:[e.jsx(Lt,{className:"h-8 w-8 mx-auto text-muted-foreground mb-3"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"No workshops yet. Create your first one!"})]}):e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"hidden md:grid grid-cols-[2fr_1fr_1fr_80px_80px_100px_120px] gap-3 px-4 py-2 text-[10px] font-bold uppercase tracking-wider text-muted-foreground",children:[e.jsx("span",{children:"Title"}),e.jsx("span",{children:"Date"}),e.jsx("span",{children:"Location"}),e.jsx("span",{children:"Capacity"}),e.jsx("span",{children:"Price"}),e.jsx("span",{children:"Status"}),e.jsx("span",{children:"Actions"})]}),t.map(v=>e.jsxs("div",{className:"academy-card grid grid-cols-1 md:grid-cols-[2fr_1fr_1fr_80px_80px_100px_120px] gap-3 items-center p-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-semibold text-foreground",children:v.title}),v.instructor&&e.jsx("p",{className:"text-[10px] text-muted-foreground",children:v.instructor})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:M(v.scheduled_at)}),e.jsx("p",{className:"text-xs text-muted-foreground truncate",children:v.is_virtual?"Virtual":v.location||"—"}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[v.current_participants||0,"/",v.max_participants||"∞"]}),e.jsx("p",{className:"text-xs font-semibold text-foreground",children:v.is_free?"Free":`$${(v.price_cents||0)/100}`}),e.jsx("span",{className:`text-[10px] font-bold uppercase px-2 py-0.5 rounded-full text-center ${R[v.status||"upcoming"]}`,children:v.status}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("button",{onClick:()=>k(v),className:"p-1.5 rounded-lg hover:bg-muted transition-colors",title:"Edit",children:e.jsx(Ue,{className:"h-3.5 w-3.5 text-muted-foreground"})}),e.jsx("button",{onClick:()=>p(v),className:"p-1.5 rounded-lg hover:bg-muted transition-colors",title:"View registrations",children:e.jsx(Ft,{className:"h-3.5 w-3.5 text-muted-foreground"})}),e.jsx("button",{onClick:()=>T(v.id),className:"p-1.5 rounded-lg hover:bg-red-50 transition-colors",title:"Delete",children:e.jsx(ze,{className:"h-3.5 w-3.5 text-red-500"})})]})]},v.id))]}),e.jsx(pe,{open:r,onOpenChange:i,children:e.jsxs(fe,{className:"sm:max-w-lg max-h-[90vh] overflow-y-auto",children:[e.jsx(ge,{children:e.jsx(be,{children:l?"Edit Workshop":"Create Workshop"})}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-bold text-muted-foreground uppercase",children:"Title"}),e.jsx(q,{value:o.title||"",onChange:v=>c(P=>({...P,title:v.target.value}))})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-bold text-muted-foreground uppercase",children:"Description"}),e.jsx(Te,{value:o.description||"",onChange:v=>c(P=>({...P,description:v.target.value})),rows:3})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-bold text-muted-foreground uppercase",children:"Start Date/Time"}),e.jsx(q,{type:"datetime-local",value:o.scheduled_at||"",onChange:v=>c(P=>({...P,scheduled_at:v.target.value}))})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-bold text-muted-foreground uppercase",children:"End Date/Time"}),e.jsx(q,{type:"datetime-local",value:o.end_time||"",onChange:v=>c(P=>({...P,end_time:v.target.value}))})]})]}),e.jsx("div",{className:"flex items-center gap-3",children:e.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:o.is_virtual||!1,onChange:v=>c(P=>({...P,is_virtual:v.target.checked})),className:"rounded"}),e.jsx("span",{className:"text-sm font-medium text-foreground",children:"Virtual Workshop"})]})}),o.is_virtual?e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-bold text-muted-foreground uppercase",children:"Meeting Link"}),e.jsx(q,{value:o.zoom_link||"",onChange:v=>c(P=>({...P,zoom_link:v.target.value})),placeholder:"https://zoom.us/j/..."})]}):e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-bold text-muted-foreground uppercase",children:"Location"}),e.jsx(q,{value:o.location||"",onChange:v=>c(P=>({...P,location:v.target.value})),placeholder:"123 Main St, City"})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-bold text-muted-foreground uppercase",children:"Capacity"}),e.jsx(q,{type:"number",value:o.max_participants||"",onChange:v=>c(P=>({...P,max_participants:parseInt(v.target.value)||20}))})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-bold text-muted-foreground uppercase",children:"Instructor"}),e.jsx(q,{value:o.instructor||"",onChange:v=>c(P=>({...P,instructor:v.target.value}))})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-bold text-muted-foreground uppercase",children:"Status"}
46),e.jsx("select",{value:o.status||"upcoming",onChange:v=>c(P=>({...P,status:v.target.value})),className:"w-full rounded-lg border border-border bg-background px-3 py-2 text-sm",children:mr.map(v=>e.jsx("option",{value:v,children:v},v))})]})]}),e.jsx("div",{className:"flex items-center gap-3",children:e.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:o.is_free||!1,onChange:v=>c(P=>({...P,is_free:v.target.checked})),className:"rounded"}),e.jsx("span",{className:"text-sm font-medium text-foreground",children:"Free Workshop"})]})}),!o.is_free&&e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-bold text-muted-foreground uppercase",children:"Price (USD)"}),e.jsx(q,{type:"number",value:(o.price_cents||0)/100,onChange:v=>c(P=>({...P,price_cents:Math.round(parseFloat(v.target.value)*100)})),step:"0.01"})]}),e.jsx("div",{className:"flex items-end",children:e.jsxs("label",{className:"flex items-center gap-2 cursor-pointer pb-2",children:[e.jsx("input",{type:"checkbox",checked:o.includes_premium||!1,onChange:v=>c(P=>({...P,includes_premium:v.target.checked})),className:"rounded"}),e.jsx("span",{className:"text-sm font-medium text-foreground",children:"Includes Premium"})]})})]}),e.jsx("button",{onClick:O,disabled:x,className:"w-full py-2.5 rounded-xl bg-primary text-primary-foreground font-semibold text-sm disabled:opacity-50",children:x?"Saving...":l?"Update Workshop":"Create Workshop"})]})]})}),e.jsx(pe,{open:!!h,onOpenChange:v=>!v&&b(null),children:e.jsxs(fe,{className:"sm:max-w-lg",children:[e.jsx(ge,{children:e.jsxs(be,{children:["Registrations — ",h==null?void 0:h.title]})}),d?e.jsx("div",{className:"flex justify-center py-8",children:e.jsx(H,{className:"h-6 w-6 animate-spin text-primary"})}):j.length===0?e.jsx("p",{className:"text-sm text-muted-foreground text-center py-8",children:"No registrations yet"}):e.jsx("div",{className:"space-y-2 max-h-[400px] overflow-y-auto",children:j.map(v=>e.jsxs("div",{className:"flex items-center justify-between p-3 rounded-xl bg-muted/50",children:[e.jsxs("div",{children:[e.jsxs("p",{className:"text-sm font-medium text-foreground",children:[v.user_id.slice(0,8),"..."]}),e.jsxs("p",{className:"text-[10px] text-muted-foreground",children:[v.status," · ",new Date(v.registered_at).toLocaleDateString()]})]}),e.jsx("button",{onClick:()=>_(v.id,!v.attended),className:`flex items-center gap-1 px-3 py-1.5 rounded-lg text-xs font-semibold transition-colors ${v.attended?"bg-emerald-500/10 text-emerald-600":"bg-muted text-muted-foreground hover:bg-muted/80"}`,children:v.attended?e.jsxs(e.Fragment,{children:[e.jsx(he,{className:"h-3 w-3"})," Attended"]}):"Mark Attended"})]},v.id))})]})})]})};var Pt;function rt(t){"@babel/helpers - typeof";return rt=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(s){return typeof s}:function(s){return s&&typeof Symbol=="function"&&s.constructor===Symbol&&s!==Symbol.prototype?"symbol":typeof s},rt(t)}function tt(){return tt=Object.assign?Object.assign.bind():function(t){for(var s=1;s<arguments.length;s++){var n=arguments[s];for(var a in n)Object.prototype.hasOwnProperty.call(n,a)&&(t[a]=n[a])}return t},tt.apply(this,arguments)}function fs(t,s){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(t);s&&(a=a.filter(function(r){return Object.getOwnPropertyDescriptor(t,r).enumerable})),n.push.apply(n,a)}return n}function Q(t){for(var s=1;s<arguments.length;s++){var n=arguments[s]!=null?arguments[s]:{};s%2?fs(Object(n),!0).forEach(function(a){ve(t,a,n[a])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):fs(Object(n)).forEach(function(a){Object.defineProperty(t,a,Object.getOwnPropertyDescriptor(n,a))})}return t}function hr(t,s){if(!(t instanceof s))throw new TypeError("Cannot call a class as a function")}function gs(t,s){for(var n=0;n<s.length;n++){var a=s[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(t,ea(a.key),a)}}function pr(t,s,n){return s&&gs(t.prototype,s),n&&gs(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t}function fr(t,s,n){return s=Ot(s),gr(t,Xs()?Reflect.construct(s,n||[],Ot(t).constructor):s.apply(t,n))}function gr(t,s){if(s&&(rt(s)==="object"||typeof s=="function"))return s;if(s!==void 0)throw new TypeError("Derived constructors may only return object or undefined");return br(t)}function br(t){if(t===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function Xs(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch{}return(Xs=function(){return!!t})()}function Ot(t){return Ot=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(n){return n.__proto__||Object.getPrototypeOf(n)},Ot(t)}function jr(t,s){if(typeof s!="function"&&s!==null)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(s&&s.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),s&&Zt(t,s)}function Zt(t,s){return Zt=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(a,r){return a.__proto__=r,a},Zt(t,s)}function ve(t,s,n){return s=ea(s),s in t?Object.defineProperty(t,s,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[s]=n,t}function ea(t){var s=vr(t,"string");return rt(s)=="symbol"?s:s+""}function vr(t,s){if(rt(t)!="object"||!t)return t;var n=t[Symbol.toPrimitive];if(n!==void 0){var a=n.call(t,s||"default");if(rt(a)!="object")return a;throw new TypeError("@@toPrimitive must return a primitive value.")}return(s==="string"?String:Number)(t)}var Pe=function(t){function s(n){var a;return hr(this,s),a=fr(this,s,[n]),ve(a,"pieRef",null),ve(a,"sectorRefs",[]),ve(a,"id",Ls("recharts-pie-")),ve(a,"handleAnimationEnd",function(){var r=a.props.onAnimationEnd;a.setState({isAnimationFinished:!0}),Oe(r)&&r()}),ve(a,"handleAnimationStart",function(){var r=a.props.onAnimationStart;a.setState({isAnimationFinished:!1}),Oe(r)&&r()}),a.state={isAnimationFinished:!n.isAnimationActive,prevIsAnimationActive:n.isAnimationActive,prevAnimationId:n.animationId,sectorToFocus:0},a}return jr(s,t),pr(s,[{key:"isActiveIndex",value:function(a){var r=this.props.activeIndex;return Array.isArray(r)?r.indexOf(a)!==-1:a===r}},{key:"hasActiveIndex",value:function(){var a=this.props.activeIndex;return Array.isArray(a)?a.length!==0:a||a===0}},{key:"renderLabels",value:function(a){var r=this.props.isAnimationActive;if(r&&!this.state.isAnimationFinished)return null;var i=this.props,l=i.label,m=i.labelLine,o=i.dataKey,c=i.valueKey,x=Ie(this.props,!1),g=Ie(l,!1),h=Ie(m,!1),b=l&&l.offsetRadius||20,j=a.map(function(f,d){var C=(f.startAngle+f.endAngle)/2,E=Yt(f.cx,f.cy,f.outerRadius+b,C),D=Q(Q(Q(Q({},x),f),{},{stroke:"none"},g),{},{index:d,textAnchor:s.getTextAnchor(E.x,f.cx)},E),k=Q(Q(Q(Q({},x),f),{},{fill:"none",stroke:f.fill},h),{},{index:d,points:[Yt(f.cx,f.cy,f.outerRadius,C),E]}),O=o;return $e(o)&&$e(c)?O="value":$e(o)&&(O=c),G.createElement(Le,{key:"label-".concat(f.startAngle,"-").concat(f.endAngle,"-").concat(f.midAngle,"-").concat(d)},m&&s.renderLabelLineItem(m,k,"line"),s.renderLabelItem(l,D,Fe(f,O)))});return G.createElement(Le,{className:"recharts-pie-labels"},j)}},{key:"renderSectorsStatically",value:function(a){var r=this,i=this.props,l=i.activeShape,m=i.blendStroke,o=i.inactiveShape;return a.map(function(c,x){if((c==null?void 0:c.startAngle)===0&&(c==null?void 0:c.endAngle)===0&&a.length!==1)return null;var g=r.isActiveIndex(x),h=o&&r.hasActiveIndex()?o:null,b=g?l:h,j=Q(Q({},c),{},{stroke:m?c.fill:c.stroke,tabIndex:-1});return G.createElement(Le,tt({ref:function(d){d&&!r.sectorRefs.includes(d)&&r.sectorRefs.push(d)}
vendor: 5,116 bytes, line 46
46,tabIndex:-1,className:"recharts-pie-sector"},va(r.props,c,x),{key:"sector-".concat(c==null?void 0:c.startAngle,"-").concat(c==null?void 0:c.endAngle,"-").concat(c.midAngle,"-").concat(x)}),G.createElement(ya,tt({option:b,isActive:g,shapeType:"sector"},j)))})}},{key:"renderSectorsWithAnimation",value:function(){var a=this,r=this.props,i=r.sectors,l=r.isAnimationActive,m=r.animationBegin,o=r.animationDuration,c=r.animationEasing,x=r.animationId,g=this.state,h=g.prevSectors,b=g.prevIsAnimationActive;return G.createElement(Os,{begin:m,duration:o,isActive:l,easing:c,from:{t:0},to:{t:1},key:"pie-".concat(x,"-").concat(b),onAnimationStart:this.handleAnimationStart,onAnimationEnd:this.handleAnimationEnd},function(j){var f=j.t,d=[],C=i&&i[0],E=C.startAngle;return i.forEach(function(D,k){var O=h&&h[k],T=k>0?Na(D,"paddingAngle",0):0;if(O){var p=Be(O.endAngle-O.startAngle,D.endAngle-D.startAngle),_=Q(Q({},D),{},{startAngle:E+T,endAngle:E+p(f)+T});d.push(_),E=_.endAngle}else{var M=D.endAngle,R=D.startAngle,v=Be(0,M-R),P=v(f),N=Q(Q({},D),{},{startAngle:E+T,endAngle:E+P+T});d.push(N),E=N.endAngle}}),G.createElement(Le,null,a.renderSectorsStatically(d))})}},{key:"attachKeyboardHandlers",value:function(a){var r=this;a.onkeydown=function(i){if(!i.altKey)switch(i.key){case"ArrowLeft":{var l=++r.state.sectorToFocus%r.sectorRefs.length;r.sectorRefs[l].focus(),r.setState({sectorToFocus:l});break}case"ArrowRight":{var m=--r.state.sectorToFocus<0?r.sectorRefs.length-1:r.state.sectorToFocus%r.sectorRefs.length;r.sectorRefs[m].focus(),r.setState({sectorToFocus:m});break}case"Escape":{r.sectorRefs[r.state.sectorToFocus].blur(),r.setState({sectorToFocus:0});break}}}}},{key:"renderSectors",value:function(){var a=this.props,r=a.sectors,i=a.isAnimationActive,l=this.state.prevSectors;return i&&r&&r.length&&(!l||!Is(l,r))?this.renderSectorsWithAnimation():this.renderSectorsStatically(r)}},{key:"componentDidMount",value:function(){this.pieRef&&this.attachKeyboardHandlers(this.pieRef)}},{key:"render",value:function(){var a=this,r=this.props,i=r.hide,l=r.sectors,m=r.className,o=r.label,c=r.cx,x=r.cy,g=r.innerRadius,h=r.outerRadius,b=r.isAnimationActive,j=this.state.isAnimationFinished;if(i||!l||!l.length||!ce(c)||!ce(x)||!ce(g)||!ce(h))return null;var f=dt("recharts-pie",m);return G.createElement(Le,{tabIndex:this.props.rootTabIndex,className:f,ref:function(C){a.pieRef=C}},this.renderSectors(),o&&this.renderLabels(l),wa.renderCallByParent(this.props,null,!1),(!b||j)&&$s.renderCallByParent(this.props,l,!1))}}],[{key:"getDerivedStateFromProps",value:function(a,r){return r.prevIsAnimationActive!==a.isAnimationActive?{prevIsAnimationActive:a.isAnimationActive,prevAnimationId:a.animationId,curSectors:a.sectors,prevSectors:[],isAnimationFinished:!0}:a.isAnimationActive&&a.animationId!==r.prevAnimationId?{prevAnimationId:a.animationId,curSectors:a.sectors,prevSectors:r.curSectors,isAnimationFinished:!0}:a.sectors!==r.curSectors?{curSectors:a.sectors,isAnimationFinished:!0}:null}},{key:"getTextAnchor",value:function(a,r){return a>r?"start":a<r?"end":"middle"}},{key:"renderLabelLineItem",value:function(a,r,i){if(G.isValidElement(a))return G.cloneElement(a,r);if(Oe(a))return a(r);var l=dt("recharts-pie-label-line",typeof a!="boolean"?a.className:"");return G.createElement(Es,tt({},r,{key:i,type:"linear",className:l}))}},{key:"renderLabelItem",value:function(a,r,i){if(G.isValidElement(a))return G.cloneElement(a,r);var l=i;if(Oe(a)&&(l=a(r),G.isValidElement(l)))return l;var m=dt("recharts-pie-label-text",typeof a!="boolean"&&!Oe(a)?a.className:"");return G.createElement(ja,tt({},r,{alignmentBaseline:"middle",className:m}),l)}}])}(u.PureComponent);Pt=Pe;ve(Pe,"displayName","Pie");ve(Pe,"defaultProps",{stroke:"#fff",fill:"#808080",legendType:"rect",cx:"50%",cy:"50%",startAngle:0,endAngle:360,innerRadius:0,outerRadius:"80%",paddingAngle:0,labelLine:!0,hide:!1,minAngle:0,isAnimationActive:!Rs.isSsr,animationBegin:400,animationDuration:1500,animationEasing:"ease",nameKey:"name",blendStroke:!1,rootTabIndex:0});ve(Pe,"parseDeltaAngle",function(t,s){var n=Tt(s-t),a=Math.min(Math.abs(s-t),360);return n*a});ve(Pe,"getRealPieData",function(t){var s=t.data,n=t.children,a=Ie(t,!1),r=Ms(n,is);return s&&s.length?s.map(function(i,l){return Q(Q(Q({payload:i},a),i),r&&r[l]&&r[l].props)}):r&&r.length?r.map(function(i){return Q(Q({},a),i.props)}):[]});ve(Pe,"parseCoordinateOfPie",function(t,s){var n=s.top,a=s.left,r=s.width,i=s.height,l=ka(r,i),m=a+kt(t.cx,r,r/2),o=n+kt(t.cy,i,i/2),c=kt(t.innerRadius,l,0),x=kt(t.outerRadius,l,l*.8),g=t.maxRadius||Math.sqrt(r*r+i*i)/2;return{cx:m,cy:o,innerRadius:c,outerRadius:x,maxRadius:g}});ve(Pe,"getComposedData",function(t){var s=t.item,n=t.offset,a=s.type.defaultProps!==void 0?Q(Q({},s.type.defaultProps),s.props):s.props,r=Pt.getRealPieData(a);if(!r||!r.length)return null;var i=a.cornerRadius,l=a.startAngle,m=a.endAngle,o=a.paddingAngle,c=a.dataKey,x=a.nameKey,g=a.valueKey,h=a.tooltipType,b=Math.abs(a.minAngle),j=Pt.parseCoordinateOfPie(a,n),f=Pt.parseDeltaAngle(l,m),d=Math.abs(f),C=c;$e(c)&&$e(g)?(Et(!1,`Use "dataKey" to specify the value of pie,
47      the props "valueKey" will be deprecated in 1.1.0`),C="value"):$e(c)&&(Et(!1,`Use "dataKey" to specify the value of pie,
48      the props "valueKey" will be deprecated in 1.1.0`),C=g);var E=r.filter(function(_){return Fe(_,C,0)!==0}).length,D=(d>=360?E:E-1)*o,k=d-E*b-D,O=r.reduce(function(_,M){var R=Fe(M,C,0);return _+(ce(R)?R:0)},0),T;if(O>0){var p;T=r.map(function(_,M){var R=Fe(_,C,0),v=Fe(_,x,M),P=(ce(R)?R:0)/O,N;M?N=p.endAngle+Tt(f)*o*(R!==0?1:0):N=l;var I=N+Tt(f)*((R!==0?b:0)+P*k),z=(N+I)/2,A=(j.innerRadius+j.outerRadius)/2,B=[{name:v,value:R,payload:_,dataKey:C,type:h}],U=Yt(j.cx,j.cy,A,z);return p=Q(Q(Q({percent:P,cornerRadius:i,name:v,tooltipPayload:B,midAngle:z,middleRadius:A,tooltipPosition:U},_),j),{},{value:Fe(_,C),startAngle:N,endAngle:I,payload:_,paddingAngle:Tt(f)*o}),p})}return Q(Q({},j),{},{sectors:T,data:r})});var yr=["x1","y1","x2","y2","key"],Nr=["offset"];function He(t){"@babel/helpers - typeof";return He=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(s){return typeof s}:function(s){return s&&typeof Symbol=="function"&&s.constructor===Symbol&&s!==Symbol.prototype?"symbol":typeof s},He(t)}function bs(t,s){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(t);s&&(a=a.filter(function(r){return Object.getOwnPropertyDescriptor(t,r).enumerable})),n.push.apply(n,a)}return n}function ae(t){for(var s=1;s<arguments.length;s++){var n=arguments[s]!=null?arguments[s]:{};s%2?bs(Object(n),!0).forEach(function(a){wr(t,a,n[a])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):bs(Object(n)).forEach(function(a){Object.defineProperty(t,a,Object.getOwnPropertyDescriptor(n,a))})}return t}function wr(t,s,n){return s=kr(s),s in t?Object.defineProperty(t,s,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[s]=n,t}function kr(t){var s=_r(t,"string");return He(s)=="symbol"?s:s+""}function _r(t,s){if(He(t)!="object"||!t)return t;var n=t[Symbol.toPrimitive];if(n!==void 0){var a=n.call(t,s||"default");if(He(a)!="object")return a;throw new TypeError("@@toPrimitive must return a primitive value.")}return(s==="string"?String:Number)(t)}function Ge(){return Ge=Object.assign?Object.assign.bind():function(t){for(var s=1;s<arguments.length;s++){var n=arguments[s];for(var a in n)Object.prototype.hasOwnProperty.call(n,a)&&(t[a]=n[a])}return t},Ge.apply(this,arguments)}function js(t,s){if(t==null)return{};var n=Sr(t,s),a,r;if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(t);for(r=0;r<i.length;r++)a=i[r],!(s.indexOf(a)>=0)&&Object.prototype.propertyIsEnumerable.call(t,a)&&(n[a]=t[a])}return n}function Sr(t,s){if(t==null)return{};var n={};for(var a in t)if(Object.prototype.hasOwnProperty.call(t,a)){if(s.indexOf(a)>=0)continue;n[a]=t[a]}return n}var Cr=function(s){var n=s.fill;if(!n||n==="none")return null;var a=s.fillOpacity,r=s.x,i=s.y,l=s.width,m=s.height,o=s.ry;return G.createElement("rect",{x:r,y:i,ry:o,width:l,height:m,stroke:"none",fill:n,fillOpacity:a,className:"recharts-cartesian-grid-bg"})};function ta(t,s){var n;if(G.isValidElement(t))n=G.cloneElement(t,s);else if(Oe(t))n=t(s);else{var a=s.x1,r=s.y1,i=s.x2,l=s.y2,m=s.key,o=js(s,yr),c=Ie(o,!1);c.offset;var x=js(c,Nr);n=G.createElement("line",Ge({},x,{x1:a,y1:r,x2:i,y2:l,fill:"none",key:m}))}return n}function Ar(t){var s=t.x,n=t.width,a=t.horizontal,r=a===void 0?!0:a,i=t.horizontalPoints;if(!r||!i||!i.length)return null;var l=i.map(function(m,o){var c=ae(ae({},t),{},{x1:s,y1:m,x2:s+n,y2:m,key:"line-".concat(o),index:o});return ta(r,c)});return G.createElement("g",{className:"recharts-cartesian-grid-horizontal"},l)}function Tr(t){var s=t.y,n=t.height,a=t.vertical,r=a===void 0?!0:a,i=t.verticalPoints;if(!r||!i||!i.length)return null;var l=i.map(function(m,o){var c=ae(ae({},t),{},{x1:m,y1:s,x2:m,y2:s+n,key:"line-".concat(o),index:o});return ta(r,c)});return G.createElement("g",{className:"recharts-cartesian-grid-vertical"},l)}function Pr(t){var s=t.horizontalFill,n=t.fillOpacity,a=t.x,r=t.y,i=t.width,l=t.height,m=t.horizontalPoints,o=t.horizontal,c=o===void 0?!0:o;if(!c||!s||!s.length)return null;var x=m.map(function(h){return Math.round(h+r-r)}).sort(function(h,b){return h-b});r!==x[0]&&x.unshift(0);var g=x.map(function(h,b){var j=!x[b+1],f=j?r+l-h:x[b+1]-h;if(f<=0)return null;var d=b%s.length;return G.createElement("rect",{key:"react-".concat(b),y:h,x:a,height:f,width:i,stroke:"none",fill:s[d],fillOpacity:n,className:"recharts-cartesian-grid-bg"})});return G.createElement("g",{className:"recharts-cartesian-gridstripes-horizontal"},g)}function Dr(t){var s=t.vertical,n=s===void 0?!0:s,a=t.verticalFill,r=t.fillOpacity,i=t.x,l=t.y,m=t.width,o=t.height,c=t.verticalPoints;if(!n||!a||!a.length)return null;var x=c.map(function(h){return Math.round(h+i-i)}).sort(function(h,b){return h-b});i!==x[0]&&x.unshift(0);var g=x.map(function(h,b){var j=!x[b+1],f=j?i+m-h:x[b+1]-h;if(f<=0)return null;var d=b%a.length;return G.createElement("rect",{key:"react-".concat(b),x:h,y:l,width:f,height:o,stroke:"none",fill:a[d],fillOpacity:r,className:"recharts-cartesian-grid-bg"})});return G.createElement("g",{className:"recharts-cartesian-gridstripes-vertical"},g)}var Er=function(s,n){var a=s.xAxis,r=s.width,i=s.height,l=s.offset;return Fs(Us(ae(ae(ae({},qs.defaultProps),a),{}
vendor: 11,971 bytes, lines 48-49
48,{ticks:zs(a,!0),viewBox:{x:0,y:0,width:r,height:i}})),l.left,l.left+l.width,n)},Or=function(s,n){var a=s.yAxis,r=s.width,i=s.height,l=s.offset;return Fs(Us(ae(ae(ae({},qs.defaultProps),a),{},{ticks:zs(a,!0),viewBox:{x:0,y:0,width:r,height:i}})),l.top,l.top+l.height,n)},Ye={horizontal:!0,vertical:!0,horizontalPoints:[],verticalPoints:[],stroke:"#ccc",fill:"none",verticalFill:[],horizontalFill:[]};function ut(t){var s,n,a,r,i,l,m=_a(),o=Sa(),c=Ca(),x=ae(ae({},t),{},{stroke:(s=t.stroke)!==null&&s!==void 0?s:Ye.stroke,fill:(n=t.fill)!==null&&n!==void 0?n:Ye.fill,horizontal:(a=t.horizontal)!==null&&a!==void 0?a:Ye.horizontal,horizontalFill:(r=t.horizontalFill)!==null&&r!==void 0?r:Ye.horizontalFill,vertical:(i=t.vertical)!==null&&i!==void 0?i:Ye.vertical,verticalFill:(l=t.verticalFill)!==null&&l!==void 0?l:Ye.verticalFill,x:ce(t.x)?t.x:c.left,y:ce(t.y)?t.y:c.top,width:ce(t.width)?t.width:c.width,height:ce(t.height)?t.height:c.height}),g=x.x,h=x.y,b=x.width,j=x.height,f=x.syncWithTicks,d=x.horizontalValues,C=x.verticalValues,E=Aa(),D=Ta();if(!ce(b)||b<=0||!ce(j)||j<=0||!ce(g)||g!==+g||!ce(h)||h!==+h)return null;var k=x.verticalCoordinatesGenerator||Er,O=x.horizontalCoordinatesGenerator||Or,T=x.horizontalPoints,p=x.verticalPoints;if((!T||!T.length)&&Oe(O)){var _=d&&d.length,M=O({yAxis:D?ae(ae({},D),{},{ticks:_?d:D.ticks}):void 0,width:m,height:o,offset:c},_?!0:f);Et(Array.isArray(M),"horizontalCoordinatesGenerator should return Array but instead it returned [".concat(He(M),"]")),Array.isArray(M)&&(T=M)}if((!p||!p.length)&&Oe(k)){var R=C&&C.length,v=k({xAxis:E?ae(ae({},E),{},{ticks:R?C:E.ticks}):void 0,width:m,height:o,offset:c},R?!0:f);Et(Array.isArray(v),"verticalCoordinatesGenerator should return Array but instead it returned [".concat(He(v),"]")),Array.isArray(v)&&(p=v)}return G.createElement("g",{className:"recharts-cartesian-grid"},G.createElement(Cr,{fill:x.fill,fillOpacity:x.fillOpacity,x:x.x,y:x.y,width:x.width,height:x.height,ry:x.ry}),G.createElement(Ar,Ge({},x,{offset:c,horizontalPoints:T,xAxis:E,yAxis:D})),G.createElement(Tr,Ge({},x,{offset:c,verticalPoints:p,xAxis:E,yAxis:D})),G.createElement(Pr,Ge({},x,{horizontalPoints:T})),G.createElement(Dr,Ge({},x,{verticalPoints:p})))}ut.displayName="CartesianGrid";var Ir=["type","layout","connectNulls","ref"],$r=["key"];function nt(t){"@babel/helpers - typeof";return nt=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(s){return typeof s}:function(s){return s&&typeof Symbol=="function"&&s.constructor===Symbol&&s!==Symbol.prototype?"symbol":typeof s},nt(t)}function vs(t,s){if(t==null)return{};var n=Rr(t,s),a,r;if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(t);for(r=0;r<i.length;r++)a=i[r],!(s.indexOf(a)>=0)&&Object.prototype.propertyIsEnumerable.call(t,a)&&(n[a]=t[a])}return n}function Rr(t,s){if(t==null)return{};var n={};for(var a in t)if(Object.prototype.hasOwnProperty.call(t,a)){if(s.indexOf(a)>=0)continue;n[a]=t[a]}return n}function mt(){return mt=Object.assign?Object.assign.bind():function(t){for(var s=1;s<arguments.length;s++){var n=arguments[s];for(var a in n)Object.prototype.hasOwnProperty.call(n,a)&&(t[a]=n[a])}return t},mt.apply(this,arguments)}function ys(t,s){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(t);s&&(a=a.filter(function(r){return Object.getOwnPropertyDescriptor(t,r).enumerable})),n.push.apply(n,a)}return n}function xe(t){for(var s=1;s<arguments.length;s++){var n=arguments[s]!=null?arguments[s]:{};s%2?ys(Object(n),!0).forEach(function(a){_e(t,a,n[a])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):ys(Object(n)).forEach(function(a){Object.defineProperty(t,a,Object.getOwnPropertyDescriptor(n,a))})}return t}function Qe(t){return zr(t)||Fr(t)||Lr(t)||Mr()}function Mr(){throw new TypeError(`Invalid attempt to spread non-iterable instance.
49In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function Lr(t,s){if(t){if(typeof t=="string")return Xt(t,s);var n=Object.prototype.toString.call(t).slice(8,-1);if(n==="Object"&&t.constructor&&(n=t.constructor.name),n==="Map"||n==="Set")return Array.from(t);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return Xt(t,s)}}function Fr(t){if(typeof Symbol<"u"&&t[Symbol.iterator]!=null||t["@@iterator"]!=null)return Array.from(t)}function zr(t){if(Array.isArray(t))return Xt(t)}function Xt(t,s){(s==null||s>t.length)&&(s=t.length);for(var n=0,a=new Array(s);n<s;n++)a[n]=t[n];return a}function Vr(t,s){if(!(t instanceof s))throw new TypeError("Cannot call a class as a function")}function Ns(t,s){for(var n=0;n<s.length;n++){var a=s[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(t,aa(a.key),a)}}function Ur(t,s,n){return s&&Ns(t.prototype,s),n&&Ns(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t}function qr(t,s,n){return s=It(s),Br(t,sa()?Reflect.construct(s,n||[],It(t).constructor):s.apply(t,n))}function Br(t,s){if(s&&(nt(s)==="object"||typeof s=="function"))return s;if(s!==void 0)throw new TypeError("Derived constructors may only return object or undefined");return Gr(t)}function Gr(t){if(t===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function sa(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch{}return(sa=function(){return!!t})()}function It(t){return It=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(n){return n.__proto__||Object.getPrototypeOf(n)},It(t)}function Wr(t,s){if(typeof s!="function"&&s!==null)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(s&&s.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),s&&es(t,s)}function es(t,s){return es=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(a,r){return a.__proto__=r,a},es(t,s)}function _e(t,s,n){return s=aa(s),s in t?Object.defineProperty(t,s,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[s]=n,t}function aa(t){var s=Hr(t,"string");return nt(s)=="symbol"?s:s+""}function Hr(t,s){if(nt(t)!="object"||!t)return t;var n=t[Symbol.toPrimitive];if(n!==void 0){var a=n.call(t,s||"default");if(nt(a)!="object")return a;throw new TypeError("@@toPrimitive must return a primitive value.")}return(s==="string"?String:Number)(t)}var bt=function(t){function s(){var n;Vr(this,s);for(var a=arguments.length,r=new Array(a),i=0;i<a;i++)r[i]=arguments[i];return n=qr(this,s,[].concat(r)),_e(n,"state",{isAnimationFinished:!0,totalLength:0}),_e(n,"generateSimpleStrokeDasharray",function(l,m){return"".concat(m,"px ").concat(l-m,"px")}),_e(n,"getStrokeDasharray",function(l,m,o){var c=o.reduce(function(C,E){return C+E});if(!c)return n.generateSimpleStrokeDasharray(m,l);for(var x=Math.floor(l/c),g=l%c,h=m-l,b=[],j=0,f=0;j<o.length;f+=o[j],++j)if(f+o[j]>g){b=[].concat(Qe(o.slice(0,j)),[g-f]);break}var d=b.length%2===0?[0,h]:[h];return[].concat(Qe(s.repeat(o,x)),Qe(b),d).map(function(C){return"".concat(C,"px")}).join(", ")}),_e(n,"id",Ls("recharts-line-")),_e(n,"pathRef",function(l){n.mainCurve=l}),_e(n,"handleAnimationEnd",function(){n.setState({isAnimationFinished:!0}),n.props.onAnimationEnd&&n.props.onAnimationEnd()}),_e(n,"handleAnimationStart",function(){n.setState({isAnimationFinished:!1}),n.props.onAnimationStart&&n.props.onAnimationStart()}),n}return Wr(s,t),Ur(s,[{key:"componentDidMount",value:function(){if(this.props.isAnimationActive){var a=this.getTotalLength();this.setState({totalLength:a})}}},{key:"componentDidUpdate",value:function(){if(this.props.isAnimationActive){var a=this.getTotalLength();a!==this.state.totalLength&&this.setState({totalLength:a})}}},{key:"getTotalLength",value:function(){var a=this.mainCurve;try{return a&&a.getTotalLength&&a.getTotalLength()||0}catch{return 0}}},{key:"renderErrorBar",value:function(a,r){if(this.props.isAnimationActive&&!this.state.isAnimationFinished)return null;var i=this.props,l=i.points,m=i.xAxis,o=i.yAxis,c=i.layout,x=i.children,g=Ms(x,Ea);if(!g)return null;var h=function(f,d){return{x:f.x,y:f.y,value:f.value,errorVal:Fe(f.payload,d)}},b={clipPath:a?"url(#clipPath-".concat(r,")"):null};return G.createElement(Le,b,g.map(function(j){return G.cloneElement(j,{key:"bar-".concat(j.props.dataKey),data:l,xAxis:m,yAxis:o,layout:c,dataPointFormatter:h})}))}},{key:"renderDots",value:function(a,r,i){var l=this.props.isAnimationActive;if(l&&!this.state.isAnimationFinished)return null;var m=this.props,o=m.dot,c=m.points,x=m.dataKey,g=Ie(this.props,!1),h=Ie(o,!0),b=c.map(function(f,d){var C=xe(xe(xe({key:"dot-".concat(d),r:3},g),h),{},{value:f.value,dataKey:x,cx:f.x,cy:f.y,index:d,payload:f.payload});return s.renderDotItem(o,C)}),j={clipPath:a?"url(#clipPath-".concat(r?"":"dots-").concat(i,")"):null};return G.createElement(Le,mt({className:"recharts-line-dots",key:"dots"},j),b)}},{key:"renderCurveStatically",value:function(a,r,i,l){var m=this.props,o=m.type,c=m.layout,x=m.connectNulls;m.ref;var g=vs(m,Ir),h=xe(xe(xe({},Ie(g,!0)),{},{fill:"none",className:"recharts-line-curve",clipPath:r?"url(#clipPath-".concat(i,")"):null,points:a},l),{},{type:o,layout:c,connectNulls:x});return G.createElement(Es,mt({},h,{pathRef:this.pathRef}))}},{key:"renderCurveWithAnimation",value:function(a,r){var i=this,l=this.props,m=l.points,o=l.strokeDasharray,c=l.isAnimationActive,x=l.animationBegin,g=l.animationDuration,h=l.animationEasing,b=l.animationId,j=l.animateNewValues,f=l.width,d=l.height,C=this.state,E=C.prevPoints,D=C.totalLength;return G.createElement(Os,{begin:x,duration:g,isActive:c,easing:h,from:{t:0},to:{t:1},key:"line-".concat(b),onAnimationEnd:this.handleAnimationEnd,onAnimationStart:this.handleAnimationStart},function(k){var O=k.t;if(E){var T=E.length/m.length,p=m.map(function(P,N){var I=Math.floor(N*T);if(E[I]){var z=E[I],A=Be(z.x,P.x),B=Be(z.y,P.y);return xe(xe({},P),{},{x:A(O),y:B(O)})}if(j){var U=Be(f*2,P.x),$=Be(d/2,P.y);return xe(xe({},P),{},{x:U(O),y:$(O)})}return xe(xe({},P),{},{x:P.x,y:P.y})});return i.renderCurveStatically(p,a,r)}var _=Be(0,D),M=_(O),R;if(o){var v="".concat(o).split(/[,\s]+/gim).map(function(P){return parseFloat(P)});R=i.getStrokeDasharray(M,D,v)}else R=i.generateSimpleStrokeDasharray(D,M);return i.renderCurveStatically(m,a,r,{strokeDasharray:R})})}},{key:"renderCurve",value:function(a,r){var i=this.props,l=i.points,m=i.isAnimationActive,o=this.state,c=o.prevPoints,x=o.totalLength;return m&&l&&l.length&&(!c&&x>0||!Is(c,l))?this.renderCurveWithAnimation(a,r):this.renderCurveStatically(l,a,r)}},{key:"render",value:function(){var a,r=this.props,i=r.hide,l=r.dot,m=r.points,o=r.className,c=r.xAxis,x=r.yAxis,g=r.top,h=r.left,b=r.width,j=r.height,f=r.isAnimationActive,d=r.id;if(i||!m||!m.length)return null;var C=this.state.isAnimationFinished,E=m.length===1,D=dt("recharts-line",o),k=c&&c.allowDataOverflow,O=x&&x.allowDataOverflow,T=k||O,p=$e(d)?this.id:d,_=(a=Ie(l,!1))!==null&&a!==void 0?a:{r:3,strokeWidth:2},M=_.r,R=M===void 0?3:M,v=_.strokeWidth,P=v===void 0?2:v,N=Da(l)?l:{},I=N.clipDot,z=I===void 0?!0:I,A=R*2+P;return G.createElement(Le,{className:D},k||O?G.createElement("defs",null,G.createElement("clipPath",{id:"clipPath-".concat(p)},G.createElement("rect",{x:k?h:h-b/2,y:O?g:g-j/2,width:k?b:b*2,height:O?j:j*2})),!z&&G.createElement("clipPath",{id:"clipPath-dots-".concat(p)},G.createElement("rect",{x:h-A/2,y:g-A/2,width:b+A,height:j+A}))):null,!E&&this.renderCurve(T,p),this.renderErrorBar(T,p),(E||l)&&this.renderDots(T,z,p),(!f||C)&&$s.renderCallByParent(this.props,m))}}],[{key:"getDerivedStateFromProps",value:function(a,r){return a.animationId!==r.prevAnimationId?{prevAnimationId:a.animationId,curPoints:a.points,prevPoints:r.curPoints}:a.points!==r.curPoints?{curPoints:a.points}:null}},{key:"repeat",value:function(a,r){for(var i=a.length%2!==0?[].concat(Qe(a),[0]):a,l=[],m=0;m<r;
49++m)l=[].concat(Qe(l),Qe(i));return l}},{key:"renderDotItem",value:function(a,r){var i;if(G.isValidElement(a))i=G.cloneElement(a,r);else if(Oe(a))i=a(r);else{var l=r.key,m=vs(r,$r),o=dt("recharts-line-dot",typeof a!="boolean"?a.className:"");i=G.createElement(Pa,mt({key:l},m,{className:o}))}return i}}])}(u.PureComponent);_e(bt,"displayName","Line");_e(bt,"defaultProps",{xAxisId:0,yAxisId:0,connectNulls:!1,activeDot:!0,dot:!0,legendType:"line",stroke:"#3182bd",strokeWidth:1,fill:"#fff",points:[],isAnimationActive:!Rs.isSsr,animateNewValues:!0,animationBegin:0,animationDuration:1500,animationEasing:"ease",hide:!1,label:!1});_e(bt,"getComposedData",function(t){var s=t.props,n=t.xAxis,a=t.yAxis,r=t.xAxisTicks,i=t.yAxisTicks,l=t.dataKey,m=t.bandSize,o=t.displayedData,c=t.offset,x=s.layout,g=o.map(function(h,b){var j=Fe(h,l);return x==="horizontal"?{x:xs({axis:n,ticks:r,bandSize:m,entry:h,index:b}),y:$e(j)?null:a.scale(j),value:j,payload:h}:{x:$e(j)?null:n.scale(j),y:xs({axis:a,ticks:i,bandSize:m,entry:h,index:b}),value:j,payload:h}});return xe({points:g,layout:x},c)});var Kr=ls({chartName:"LineChart",GraphicalChild:bt,axisComponents:[{axisType:"xAxis",AxisComp:st},{axisType:"yAxis",AxisComp:at}],formatAxisMap:Vs}),ra=ls({chartName:"BarChart",GraphicalChild:os,defaultTooltipEventType:"axis",validateTooltipEventTypes:["axis","item"],axisComponents:[{axisType:"xAxis",AxisComp:st},{axisType:"yAxis",AxisComp:at}],formatAxisMap:Vs}),na=ls({chartName:"PieChart",GraphicalChild:Pe,validateTooltipEventTypes:["item"],defaultTooltipEventType:"item",legendContent:"children",axisComponents:[{axisType:"angleAxis",AxisComp:Oa},{axisType:"radiusAxis",AxisComp:Ia}],formatAxisMap:$a,defaultProps:{layout:"centric",startAngle:0,endAngle:360,cx:"50%",cy:"50%",innerRadius:0,outerRadius:"80%"}});const Je=t=>t>=1e6?`${(t/1e6).toFixed(1)}M`:t>=1e3?`${(t/1e3).toFixed(1)}K`:t.toLocaleString(),_t=t=>`$${t.toLocaleString("en-US",{minimumFractionDigits:0,maximumFractionDigits:0})}`,Yr=t=>{if(t==="all")return"2020-01-01";const s=new Date,n=t==="7d"?7:t==="30d"?30:90;return s.setDate(s.getDate()-n),s.toISOString()},St=(t,s)=>{if(!t.length)return;const n=Object.keys(t[0]),a=[n.join(","),...t.map(m=>n.map(o=>`"${m[o]??""}"`).join(","))].join(`
50`),r=new Blob([a],{type:"text/csv"}),i=URL.createObjectURL(r),l=document.createElement("a");l.href=i,l.download=`${s}.csv`,l.click(),URL.revokeObjectURL(i)},Qr=()=>{const[t,s]=u.useState("30d"),[n,a]=u.useState(!0),[r,i]=u.useState(0),[l,m]=u.useState(0),[o,c]=u.useState(0),[x,g]=u.useState(0),[h,b]=u.useState(0),[j,f]=u.useState(0),[d,C]=u.useState(0),[E,D]=u.useState([]),[k,O]=u.useState([]),[T,p]=u.useState([]),[_,M]=u.useState([]),[R,v]=u.useState([]),[P,N]=u.useState([]),I=u.useCallback(async()=>{a(!0);const L=Yr(t),K=t==="7d"?14:t==="30d"?60:t==="90d"?180:0;K>0&&new Date(Date.now()-K*864e5).toISOString();const[qe,Nt,ue,ot,Ut,qt]=await Promise.all([S.from("profiles").select("id, tier, created_at"),S.from("videos").select("id",{count:"exact",head:!0}),S.from("videos").select("title, view_count, channels(name, color)").order("view_count",{ascending:!1}).limit(20),S.from("channels").select("name, color, video_count"),S.from("watch_history").select("created_at, video_id").gte("created_at",L).order("created_at"),S.from("tutor_conversations").select("messages, created_at").gte("created_at",L).limit(200)]),je=qe.data||[],ct=new Date,le=t==="7d"?7*864e5:t==="30d"?30*864e5:t==="90d"?90*864e5:0,Ne=je.filter(F=>t==="all"||new Date(F.created_at)<=ct),Ke=le>0?je.filter(F=>new Date(F.created_at)<=new Date(ct.getTime()-le)):je;i(Ne.length),m(Ne.filter(F=>F.tier==="pro").length),c(Ne.filter(F=>F.tier==="premium").length),g(Ke.length),b(Ke.filter(F=>F.tier==="pro").length),f(Ke.filter(F=>F.tier==="premium").length),C(Nt.count||0);const wt=new Map,y=[...je].sort((F,J)=>new Date(F.created_at).getTime()-new Date(J.created_at).getTime());let W=0,V=0,Me=0;for(const F of y){const J=new Date(F.created_at).toISOString().slice(0,10);F.tier==="pro"?V++:F.tier==="premium"?Me++:W++,wt.set(J,{free:W,pro:V,premium:Me})}const we=Array.from(wt.entries()).map(([F,J])=>({date:F,...J})).filter(F=>t==="all"||F.date>=L.slice(0,10));D(we.slice(-60));const me=new Map;for(const F of Ut.data||[]){const J=new Date(F.created_at).toISOString().slice(0,10);me.set(J,(me.get(J)||0)+1)}O(Array.from(me.entries()).map(([F,J])=>({date:F,views:J}))),p((ue.data||[]).map(F=>{var J,Ee;return{title:F.title,view_count:F.view_count||0,channel_name:((J=F.channels)==null?void 0:J.name)||"Unknown",channel_c
50olor:((Ee=F.channels)==null?void 0:Ee.color)||"#7c3aed"}})),M((ot.data||[]).filter(F=>(F.video_count||0)>0).map(F=>({name:F.name,views:F.video_count||0,color:F.color})));const oe=new Map;for(const F of qt.data||[]){const J=F.messages;if(Array.isArray(J)){for(const Ee of J)if(Ee.role==="user"&&Ee.content){const us=Ee.content.slice(0,100);oe.set(us,(oe.get(us)||0)+1)}}}const De=Array.from(oe.entries()).sort((F,J)=>J[1]-F[1]).slice(0,15).map(([F,J])=>({question:F,count:J}));v(De);const ke=je.length,re=je.filter(F=>F.tier==="free").length,Se=je.filter(F=>F.tier==="free"&&F.pro_trial_ends_at).length;N([{stage:"Signups",count:ke,pct:100},{stage:"Free Users",count:re,pct:Math.round(re/Math.max(ke,1)*100)},{stage:"Trial Users",count:Se,pct:Math.round(Se/Math.max(ke,1)*100)},{stage:"Pro",count:Ne.filter(F=>F.tier==="pro").length,pct:Math.round(Ne.filter(F=>F.tier==="pro").length/Math.max(ke,1)*100)},{stage:"Premium",count:Ne.filter(F=>F.tier==="premium").length,pct:Math.round(Ne.filter(F=>F.tier==="premium").length/Math.max(ke,1)*100)}]),a(!1)},[t]);u.useEffect(()=>{I()},[I]);const z=l*47+o*197,A=h*47+j*197,B=z*12,U=(L,K)=>K===0?L>0?100:0:Math.round((L-K)/K*100),$=[{label:"Total Users",value:Je(r),change:U(r,x),color:"hsl(262 83% 58%)",icon:Ft},{label:"Pro Subscribers",value:Je(l),change:U(l,h),color:"hsl(262 83% 58%)",icon:ms},{label:"Premium Subscribers",value:Je(o),change:U(o,j),color:"hsl(45 100% 60%)",icon:ms},{label:"MRR",value:_t(z),change:U(z,A),color:"hsl(142 71% 45%)",icon:ht},{label:"ARR Projection",value:_t(B),change:null,color:"hsl(217 91% 60%)",icon:As},{label:"Videos in Library",value:Je(d),change:null,color:"hsl(330 81% 60%)",icon:ns}],X=Math.max(...T.map(L=>L.view_count),1),lt=[{key:"7d",label:"7 days"},{key:"30d",label:"30 days"},{key:"90d",label:"90 days"},{key:"all",label:"All Time"}];return n?e.jsxs("div",{className:"space-y-6",children:[e.jsx("div",{className:"grid grid-cols-2 md:grid-cols-3 lg:grid-cols-6 gap-4",children:Array.from({length:6}).map((L,K)=>e.jsx("div",{className:"h-28 rounded-xl skeleton-shimmer"},K))}),e.jsx("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6",children:Array.from({length:4}).map((L,K)=>e.jsx("div",{className:"h-72 rounded-xl skeleton-shimmer"},K))})]}):e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row items-start sm:items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold text-foreground",children:"Analytics"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Platform performance and insights"})]}),e.jsx("div",{className:"flex gap-1 bg-muted rounded-lg p-1",children:lt.map(L=>e.jsx("button",{onClick:()=>s(L.key),className:`px-3 py-1.5 text-xs font-semibold rounded-md transition-colors ${t===L.key?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,children:L.label},L.key))})]}),e.jsx("div",{className:"grid grid-cols-2 md:grid-cols-3 lg:grid-cols-6 gap-4",children:$.map(L=>{const K=L.icon,qe=L.change!==null&&L.change>=0;return e.jsxs("div",{className:"bg-card rounded-xl border border-border/50 p-4 relative overflow-hidden",style:{borderLeftWidth:"3px",borderLeftColor:L.color},children:[e.jsxs("div",{className:"flex items-center gap-1.5 mb-2",children:[e.jsx(K,{className:"h-3.5 w-3.5 text-muted-foreground"}),e.jsx("span",{className:"text-[11px] font-medium text-muted-foreground uppercase tracking-wide",children:L.label})]}),e.jsx("p",{className:"text-xl font-bold text-foreground",children:L.value}),L.change!==null&&e.jsxs("div",{className:`flex items-center gap-0.5 mt-1 text-[11px] font-semibold ${qe?"text-emerald-600":"text-red-500"}`,children:[qe?e.jsx(ds,{className:"h-3 w-3"}):e.jsx(Qa,{className:"h-3 w-3"}),Math.abs(L.change),"%"]})]},L.label)})}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6",children:[e.jsxs("div",{className:"bg-card rounded-xl border border-border/50 p-5",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsx("h3",{className:"text-sm font-bold text-foreground",children:"User Growth"}),e.jsxs("button",{onClick:()=>St(E,"user-growth"),className:"text-[10px] text-muted-foreground hover:text-foreground flex items-center gap-1",children:[e.jsx(Ze,{className:"h-3 w-3"})," CSV"]})]}),e.jsx(Xe,{width:"100%",height:240,children:e.jsxs(Ra,{data:E,children:[e.jsx(ut,{strokeDasharray:"3 3",stroke:"hsl(var(--border))"}),e.jsx(st,{dataKey:"date",tick:{fontSize:10}
50,tickFormatter:L=>L.slice(5),stroke:"hsl(var(--muted-foreground))"}),e.jsx(at,{tick:{fontSize:10},stroke:"hsl(var(--muted-foreground))"}),e.jsx(et,{contentStyle:{fontSize:12,borderRadius:8,border:"1px solid hsl(var(--border))"}}),e.jsx(Qt,{wrapperStyle:{fontSize:11}}),e.jsx(Gt,{type:"monotone",dataKey:"premium",stackId:"1",fill:"hsl(45 100% 60%)",stroke:"hsl(45 85% 47%)",fillOpacity:.6,name:"Premium"}),e.jsx(Gt,{type:"monotone",dataKey:"pro",stackId:"1",fill:"hsl(262 83% 58%)",stroke:"hsl(262 83% 48%)",fillOpacity:.6,name:"Pro"}),e.jsx(Gt,{type:"monotone",dataKey:"free",stackId:"1",fill:"hsl(var(--muted))",stroke:"hsl(var(--muted-foreground))",fillOpacity:.4,name:"Free"})]})})]}),e.jsxs("div",{className:"bg-card rounded-xl border border-border/50 p-5",children:[e.jsx("div",{className:"flex items-center justify-between mb-4",children:e.jsx("h3",{className:"text-sm font-bold text-foreground",children:"Revenue (MRR)"})}),e.jsxs("div",{className:"flex items-baseline gap-3 mb-4",children:[e.jsx("span",{className:"text-3xl font-bold text-foreground",children:_t(z)}),e.jsx("span",{className:"text-sm text-muted-foreground",children:"/ month"}),e.jsxs("span",{className:"text-xs text-muted-foreground ml-auto",children:["ARR: ",_t(B)]})]}),e.jsx(Xe,{width:"100%",height:180,children:e.jsxs(Kr,{data:E.map(L=>({date:L.date,mrr:L.pro*47+L.premium*197})),children:[e.jsx(ut,{strokeDasharray:"3 3",stroke:"hsl(var(--border))"}),e.jsx(st,{dataKey:"date",tick:{fontSize:10},tickFormatter:L=>L.slice(5),stroke:"hsl(var(--muted-foreground))"}),e.jsx(at,{tick:{fontSize:10},stroke:"hsl(var(--muted-foreground))",tickFormatter:L=>`$${L}`}),e.jsx(et,{contentStyle:{fontSize:12,borderRadius:8},formatter:L=>[`$${L}`,"MRR"]}),e.jsx(bt,{type:"monotone",dataKey:"mrr",stroke:"hsl(142 71% 45%)",strokeWidth:2,dot:!1})]})})]})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6",children:[e.jsxs("div",{className:"bg-card rounded-xl border border-border/50 p-5",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsx("h3",{className:"text-sm font-bold text-foreground",children:"Video Views"}),e.jsxs("button",{onClick:()=>St(k,"video-views"),className:"text-[10px] text-muted-foreground hover:text-foreground flex items-center gap-1",children:[e.jsx(Ze,{className:"h-3 w-3"})," CSV"]})]}),e.jsx(Xe,{width:"100%",height:240,children:e.jsxs(ra,{data:k,children:[e.jsx(ut,{strokeDasharray:"3 3",stroke:"hsl(var(--border))"}),e.jsx(st,{dataKey:"date",tick:{fontSize:10},tickFormatter:L=>L.slice(5),stroke:"hsl(var(--muted-foreground))"}),e.jsx(at,{tick:{fontSize:10},stroke:"hsl(var(--muted-foreground))"}),e.jsx(et,{contentStyle:{fontSize:12,borderRadius:8}}),e.jsx(os,{dataKey:"views",fill:"hsl(262 83% 58%)",radius:[4,4,0,0]})]})})]}),e.jsxs("div",{className:"bg-card rounded-xl border border-border/50 p-5",children:[e.jsx("div",{className:"flex items-center justify-between mb-4",children:e.jsx("h3",{className:"text-sm font-bold text-foreground",children:"Channel Popularity"})}),e.jsx(Xe,{width:"100%",height:240,children:e.jsxs(na,{children:[e.jsx(Pe,{data:_,cx:"50%",cy:"50%",innerRadius:50,outerRadius:90,paddingAngle:2,dataKey:"views",nameKey:"name",children:_.map((L,K)=>e.jsx(is,{fill:L.color},K))}),e.jsx(et,{contentStyle:{fontSize:12,borderRadius:8}}),e.jsx(Qt,{wrapperStyle:{fontSize:11}})]})})]})]}),e.jsxs("div",{className:"bg-card rounded-xl border border-border/50 p-5",children:[e.jsx("h3",{className:"text-sm font-bold text-foreground mb-4",children:"Conversion Funnel"}),e.jsx("div",{className:"flex flex-col sm:flex-row items-stretch gap-2",children:P.map((L,K)=>e.jsxs("div",{className:"flex-1 text-center",children:[e.jsxs("div",{className:"rounded-lg py-4 px-3 mx-auto transition-all",style:{backgroundColor:`hsl(262 83% ${58+K*8}% / ${.9-K*.15})`,maxWidth:`${100-K*10}%`},children:[e.jsx("p",{className:"text-white text-lg font-bold",children:Je(L.count)}),e.jsxs("p",{className:"text-white/80 text-[10px] font-medium",children:[L.pct,"%"]})]}),e.jsx("p",{className:"text-xs font-medium text-foreground mt-2",children:L.stage}),K<P.length-1&&e.jsx("span",{className:"text-[10px] text-muted-foreground",children:"→"})]},L.stage))})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6",children:[e.jsxs("div",{className:"bg-card rounded-xl border border-border/50 p-5",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsx("h3",{className:"text-sm font-bold text-foreground",children:"Most Watched Videos"}),e.jsxs("button",{onClick:()=>St(T,"top-videos"),className:"text-[10px] text-muted-foreground hover:text-foreground flex items-center gap-1",children:[e.jsx(Ze,{className:"h-3 w-3"})," CSV"]})]}),e.jsxs("div",{className:"space-y-2 max-h-[400px] overflow-y-auto",children:[T.map((L,K)=>e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"text-[10px] font-mono text-muted-foreground w-5 shrink-0 text-right",children:K+1}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-xs font-medium text-foreground truncate",children:L.title}),e.jsx("span",{className:"text-[9px] font-bold text-white px-1.5 py-0.5 rounded",style:{backgroundColor:L.channel_c
50olor},children:L.channel_name})]}),e.jsxs("div",{className:"w-24 shrink-0 flex items-center gap-2",children:[e.jsx("div",{className:"flex-1 h-1.5 bg-muted rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full rounded-full",style:{width:`${L.view_count/X*100}%`,backgroundColor:"hsl(262 83% 58%)"}})}),e.jsx("span",{className:"text-[10px] font-mono text-muted-foreground",children:Je(L.view_count)})]})]},K)),T.length===0&&e.jsx("p",{className:"text-xs text-muted-foreground text-center py-4",children:"No video data yet"})]})]}),e.jsxs("div",{className:"bg-card rounded-xl border border-border/50 p-5",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsxs("h3",{className:"text-sm font-bold text-foreground flex items-center gap-1.5",children:[e.jsx(Bs,{className:"h-3.5 w-3.5"})," Top Nimbus Questions"]}),e.jsxs("button",{onClick:()=>St(R,"nimbus-questions"),className:"text-[10px] text-muted-foreground hover:text-foreground flex items-center gap-1",children:[e.jsx(Ze,{className:"h-3 w-3"})," CSV"]})]}),e.jsxs("div",{className:"space-y-2 max-h-[400px] overflow-y-auto",children:[R.map((L,K)=>e.jsxs("div",{className:"flex items-start gap-3 py-1.5 border-b border-border/30 last:border-0",children:[e.jsx("span",{className:"text-xs font-bold text-primary bg-primary/10 rounded-full w-6 h-6 flex items-center justify-center shrink-0",children:L.count}),e.jsx("p",{className:"text-xs text-foreground leading-relaxed",children:L.question})]},K)),R.length===0&&e.jsx("p",{className:"text-xs text-muted-foreground text-center py-4",children:"No conversation data yet"})]})]})]}),e.jsxs("div",{className:"bg-card rounded-xl border border-border/50 p-5",children:[e.jsx("div",{className:"flex items-center justify-between mb-4",children:e.jsxs("h3",{className:"text-sm font-bold text-foreground flex items-center gap-1.5",children:[e.jsx(Ma,{className:"h-3.5 w-3.5 text-amber-500"})," Content Gaps"]})}),e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-xs",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-border/40",children:[e.jsx("th",{className:"text-left py-2 pr-4 font-semibold text-muted-foreground",children:"Question / Topic"}),e.jsx("th",{className:"text-right py-2 px-2 font-semibold text-muted-foreground",children:"Frequency"}),e.jsx("th",{className:"text-left py-2 px-2 font-semibold text-muted-foreground",children:"Action"})]})}),e.jsxs("tbody",{children:[R.filter(L=>L.count>=2).map((L,K)=>e.jsxs("tr",{className:`border-b border-border/20 ${L.count>=5?"bg-amber-500/5":""}`,children:[e.jsx("td",{className:"py-2 pr-4 text-foreground max-w-[300px] truncate",children:L.question}),e.jsx("td",{className:"py-2 px-2 text-right font-mono text-foreground",children:L.count}),e.jsx("td",{className:"py-2 px-2",children:e.jsx("span",{className:"text-[10px] font-medium text-amber-600 bg-amber-100 rounded px-1.5 py-0.5",children:L.count>=5?"High Priority":"Monitor"})})]},K)),R.filter(L=>L.count>=2).length===0&&e.jsx("tr",{children:e.jsx("td",{colSpan:3,className:"py-6 text-center text-muted-foreground",children:"No content gaps detected yet — collect more tutor conversations"})})]})]})})]})]})},Jr=()=>{const[t,s]=u.useState([]),[n,a]=u.useState(!0),[r,i]=u.useState(!1),l=u.useCallback(async()=>{a(!0);const{data:g}=await S.from("analytics_events").select("event_data, created_at").eq("event_type","bcc_sync").order("created_at",{ascending:!1}).limit(7),h=(g||[]).map(b=>{const j=b.event_data;return{status:(j==null?void 0:j.status)||"unknown",synced_at:b.created_at,metrics_summary:j==null?void 0:j.metrics_summary,error:j==null?void 0:j.error}});s(h),a(!1)},[]);u.useEffect(()=>{l()},[l]);const m=async()=>{i(!0);try{const g="kcnwnuwipzuluqsgujtk",{data:{session:h}}=await S.auth.getSession(),j=await(await fetch(`https://${g}.supabase.co/functions/v1/academy-bcc-sync`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${(h==null?void 0:h.access_token)||"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImtjbndudXdpcHp1bHVxc2d1anRrIiwicm9sZSI6ImFub24iLCJpYXQiOjE3Njg0MjE3MTcsImV4cCI6MjA4Mzk5NzcxN30.uYbGvBSuX_GirHvIFBt9MP5tPhjOpsAKQswHZKMIrdo"}`}})).json();j.success?w.success("BCC sync completed"):w.error(`Sync failed: ${j.error||"Unknown error"}`),await l()}catch{w.error("Failed to trigger sync")}finally{i(!1)}},o=t[0],c=g=>g==="success"?e.jsx(La,{className:"h-4 w-4 text-emerald-500"}):g==="failed"?e.jsx(Fa,{className:"h-4 w-4 text-destructive"}):e.jsx(la,{className:"h-4 w-4 text-amber-500"}),x=g=>{const h=Date.now()-new Date(g).getTime(),b=Math.floor(h/6e4);if(b<60)return`${b}m ago`;const j=Math.floor(b/60);return j<24?`${j}h ago`:`${Math.floor(j/24)}d ago`};return e.jsxs(ne,{children:[e.jsx(Ce,{className:"pb-3",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(Ae,{className:"text-base flex items-center gap-2",children:[e.jsx(ds,{className:"h-4 w-4 text-primary"}),"BCC Sync"]}),e.jsxs(Z,{size:"sm",variant:"outline",onClick:m,disabled:r,className:"gap-1.5",children:[e.jsx(xt,{className:`h-3.5 w-3.5 ${r?"animate-spin":""}`}),r?"Syncing…":"Sync Now"]})]})}),e.jsxs(ie,{className:"space-y-4",children:[o?e.jsxs("div",{className:"flex items-center gap-3 p-3 rounded-lg bg-muted/50",children:[c(o.status),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-sm font-semibold text-foreground capitalize",children:o.status}),e.jsx("p",{className:"text-xs text-muted-foreground",children:x(o.synced_at)})]}),o.metrics_summary&&e.jsxs("div",{className:"text-right text-[11px] text-muted-foreground space-y-0.5",children:[e.jsxs("p",{children:[o.metrics_summary.total_users," users"]}),e.jsxs("p",{children:["$",o.metrics_summary.mrr," MRR"]})]})]}):e.jsx("p",{className:"text-sm text-muted-foreground",children:n?"Loading…":"No syncs yet"}),t.length>1&&e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-bold uppercase tracking-wider text-muted-foreground mb-2",children:"History"}),e.jsx("div",{className:"space-y-1.5",children:t.slice(1).map((g,h)=>e.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[c(g.status),e.jsx("span",{className:"text-muted-foreground",children:x(g.synced_at)}),e.jsx("span",{className:"capitalize text-foreground font-medium",children:g.status}),g.error&&e.jsx("span",{className:"text-destructive truncate max-w-[120px]",children:g.error})]},h))})]})]})]})},Wt=[{key:"nimbus",name:"Nimbus",emoji:"☁️",defaultPrompt:"Adorable small roun
50d robot with glowing blue visor eyes, tiny antenna on top, floating cloud motif, soft white-blue metallic body, friendly expression, cute 3D render, soft studio lighting, white background, high quality, 4k"},{key:"gizmo",name:"Gizmo",emoji:"⚙️",defaultPrompt:"Cute boxy tinkerer robot with oversized brass goggles, tiny mechanical arms holding tools, copper-teal metallic body, excited expression, cute 3D render, warm studio lighting, white background, high quality, 4k"},{key:"bandit",name:"Bandit",emoji:"🔍",defaultPrompt:"Scrappy scout robot with a small radar dish on head, utility vest panel on chest, orange-gold metallic body, mischievous LED grin, cute 3D render, warm studio lighting, white background, high quality, 4k"},{key:"fizz",name:"Fizz",emoji:"⚡",defaultPrompt:"Tiny energetic robot crackling with electricity, lightning bolt antenna, yellow-orange glowing chassis, joyful LED eyes, cute 3D render, magical glow, warm studio lighting, white background, high quality, 4k"},{key:"vox",name:"Vox",emoji:"🎧",defaultPrompt:"Sleek audio robot with large glowing headphones, speaker chest panel, purple-pink neon trim, confident LED smile, cute 3D render, dramatic studio lighting, white background, high quality, 4k"},{key:"openclaw",name:"OpenClaw",emoji:"🦾",defaultPrompt:"Adorable cute robot with oversized soft mechanical claw arms, open-source circuit motif on chest panel, glowing green optic eyes, white-and-emerald metallic body, antenna with tiny LED, expressive happy face, cute 3D render, soft studio lighting, white background, high quality, 4k"},{key:"hermes",name:"Hermes",emoji:"🪽",defaultPrompt:"Sleek messenger agent robot with tiny winged sneakers, swift aerodynamic chassis, glowing cyan visor eyes, silver-and-blue metallic body, small wing motifs on shoulders, confident friendly expression, cute 3D render, soft studio lighting, white background, high quality, 4k"},{key:"paperclip",name:"Paperclip",emoji:"📎",defaultPrompt:"Friendly stationery-inspired robot with a curved chrome paperclip body forming the head and arms, big round googly LED eyes, tiny note-paper accent on chest, helpful cheerful expression, polished silver and pastel-yellow finish, cute 3D render, soft studio lighting, white background, high quality, 4k"}],Zr=()=>{const[t,s]=u.useState("characters"),[n,a]=u.useState([]),[r,i]=u.useState({}),[l,m]=u.useState({}),[o,c]=u.useState({}),[x,g]=u.useState({}),[h,b]=u.useState([]),[j,f]=u.useState(!1);u.useEffect(()=>{(async()=>{const[{data:_},{data:M}]=await Promise.all([S.from("app_config").select("config_key, config_value").like("config_key","character_avatar_%"),S.from("channels").select("id, name, slug, color, icon_url, hero_image_url").order("sort_order")]),R={};(_||[]).forEach(P=>{const N=P.config_key.replace("character_avatar_","");R[N]=P.config_value}),i(R),M&&a(M);const v={};Wt.forEach(P=>{v[P.key]=P.defaultPrompt}),m(v)})()},[]);const d=u.useCallback(async(p,_,M,R)=>{c(v=>({...v,[_]:!0}));try{const{data:{session:v}}=await S.auth.getSession();if(!v)return w.error("Not authenticated"),null;const N=await fetch("https://kcnwnuwipzuluqsgujtk.supabase.co/functions/v1/academy-nano-generate",{method:"POST",headers:{Authorization:`Bearer ${v.access_token}`,"Content-Type":"application/json"},body:JSON.stringify({prompt:M,type:p,filename:R})}),I=await N.json();return N.ok?(g(z=>({...z,[_]:I.image_url})),w.success(`${_} art generated!`),I.image_url):(w.error(I.error||"Generation failed"),null)}catch(v){return w.error(v.message),null}finally{c(v=>({...v,[_]:!1}))}},[]),C=(p,_)=>{i(M=>({...M,[p]:_})),g(M=>{const R={...M};return delete R[p],R}),w.success("Image accepted and saved")},E=async p=>{f(!0),b(p.map(_=>({..._,status:"pending"})));for(let _=0;_<p.length;_++){b(R=>R.map((v,P)=>P===_?{...v,status:"generating"}:v));const M=await d(p[_].type,p[_].key,p[_].prompt,p[_].filename);b(R=>R.map((v,P)=>P===_?{...v,status:M?"done":"error",resultUrl:M||void 0,error:M?void 0:"Failed"}:v))}f(!1),w.success("Batch generation complete")},D=()=>{const p=Wt.map(_=>({key:_.key,type:"character",prompt:l[_.key]||_.defaultPrompt,filename:_.key,status:"pending"}));E(p)},k=()=>{const p=n.map(_=>({key:`ch_${_.slug}`,type:"channel_hero",prompt:`Beautiful wide cinematic hero image for an AI learning channel called "${_.name}", abstract tech patterns in ${_.color} color tones, modern digital art style, gradient background, no text, 4k, ultrawide`,filename:_.slug,status:"pending"}));E(p)},O=h.filter(p=>p.status==="done").length,T=h.length;return e.jsxs("div",{children:[e.jsx("div",{className:"flex items-center justify-between mb-6 flex-wrap gap-3",children:e.jsxs("div",{children:[e.jsxs("h2",{className:"text-2xl font-extrabold text-foreground flex items-center gap-2",children:[e.jsx(Va,{className:"h-6 w-6 text-primary"})," Nano Banana Art Studio"]}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:"Generate AI art for characters, channels, and certificates"})]})}),e.jsx("div",{className:"flex gap-1 mb-6 p-1 bg-muted rounded-xl w-fit",children:["characters","channels"].map(p=>e.jsx("button",{onClick:()=>s(p),className:`px-4 py-2 rounded-lg text-sm font-semibold transition-colors capitalize ${t===p?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,children:p},p))}),j&&e.jsxs("div",{className:"academy-card p-4 mb-6",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("span",{className:"text-sm font-semibold text-foreground",children:"Batch Generation"}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:[O,"/",T]})]}),e.jsx(za,{value:O/T*100,className:"h-2"}),e.jsx("div",{className:"mt-3 space-y-1",children:h.map(p=>e.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[p.status==="generating"&&e.jsx(H,{className:"h-3 w-3 animate-spin text-primary"}),p.status==="done"&&e.jsx(he,{className:"h-3 w-3 text-emerald-500"}),p.status==="error"&&e.jsx("span",{className:"text-destructive",children:"✕"}),p.status==="pending"&&e.jsx("span",{className:"w-3 h-3 rounded-full bg-muted-foreground
50/20"}),e.jsx("span",{className:p.status==="generating"?"text-foreground font-medium":"text-muted-foreground",children:p.key})]},p.key))})]}),t==="characters"&&e.jsxs("div",{children:[e.jsx("div",{className:"flex justify-end mb-4",children:e.jsxs("button",{onClick:D,disabled:j,className:"px-4 py-2 rounded-xl bg-primary text-primary-foreground text-sm font-semibold hover:opacity-90 transition-opacity flex items-center gap-2 disabled:opacity-50",children:[e.jsx(At,{className:"h-4 w-4"})," Generate All Characters"]})}),e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-4",children:Wt.map(p=>{const _=x[p.key]||r[p.key],M=o[p.key],R=!!x[p.key];return e.jsxs("div",{className:"academy-card p-5",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[e.jsx("div",{className:"w-14 h-14 rounded-2xl bg-muted flex items-center justify-center overflow-hidden shrink-0",children:_?e.jsx("img",{src:_,alt:p.name,className:"w-full h-full object-cover"}):e.jsx("span",{className:"text-2xl",children:p.emoji})}),e.jsxs("div",{children:[e.jsx("h3",{className:"font-bold text-foreground",children:p.name}),e.jsx("p",{className:"text-xs text-muted-foreground",children:_?"Generated":"Using emoji placeholder"})]})]}),e.jsx(Te,{value:l[p.key]||p.defaultPrompt,onChange:v=>m(P=>({...P,[p.key]:v.target.value})),rows:3,className:"text-xs mb-3"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("button",{onClick:()=>d("character",p.key,l[p.key]||p.defaultPrompt,p.key),disabled:M||j,className:"flex-1 py-2 rounded-xl bg-primary text-primary-foreground text-sm font-semibold disabled:opacity-50 flex items-center justify-center gap-2",children:[M?e.jsx(H,{className:"h-4 w-4 animate-spin"}):e.jsx(At,{className:"h-4 w-4"}),M?"Generating...":R?"Regenerate":"Generate"]}),R&&e.jsxs("button",{onClick:()=>C(p.key,x[p.key]),className:"px-4 py-2 rounded-xl bg-emerald-500/10 text-emerald-600 text-sm font-semibold hover:bg-emerald-500/20 transition-colors flex items-center gap-1",children:[e.jsx(he,{className:"h-4 w-4"})," Accept"]})]})]},p.key)})})]}),t==="channels"&&e.jsxs("div",{children:[e.jsx("div",{className:"flex justify-end mb-4",children:e.jsxs("button",{onClick:k,disabled:j,className:"px-4 py-2 rounded-xl bg-primary text-primary-foreground text-sm font-semibold hover:opacity-90 transition-opacity flex items-center gap-2 disabled:opacity-50",children:[e.jsx(Ua,{className:"h-4 w-4"})," Generate All Channel Heroes"]})}),e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:n.map(p=>{const _=`ch_${p.slug}`,M=o[_],R=x[_];return e.jsxs("div",{className:"academy-card overflow-hidden",children:[e.jsxs("div",{className:"h-32 relative",style:{background:R||p.hero_image_url?void 0:`linear-gradient(135deg, ${p.color}40, ${p.color}10)`},children:[(R||p.hero_image_url)&&e.jsx("img",{src:R||p.hero_image_url,alt:p.name,className:"w-full h-full object-cover"}),e.jsx("div",{className:"absolute inset-0 bg-gradient-to-t from-card/80 to-transparent"}),e.jsx("div",{className:"absolute bottom-3 left-4",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-4 h-4 rounded",style:{backgroundColor:p.color}}),e.jsx("span",{className:"font-bold text-foreground text-sm",children:p.name})]})})]}),e.jsx("div",{className:"p-4",children:e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("button",{onClick:()=>d("channel_hero",_,`Beautiful wide cinematic hero image for an AI learning channel called "${p.name}", abstract tech patterns in ${p.color} color tones, modern digital art style, gradient background, no text, 4k, ultrawide`,p.slug),disabled:M||j,className:"flex-1 py-2 rounded-xl bg-primary text-primary-foreground text-xs font-semibold disabled:opacity-50 flex items-center justify-center gap-1.5",children:[M?e.jsx(H,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(At,{className:"h-3.5 w-3.5"}),M?"Generating...":p.hero_image_url?"Regenerate Hero":"Generate Hero"]}),R&&e.jsxs("button",{onClick:()=>{a(v=>v.map(P=>P.id===p.id?{...P,hero_image_url:R}:P)),g(v=>{const P={...v};return delete P[_],P}),w.success("Hero image accepted")},className:"px-3 py-2 rounded-xl bg-emerald-500/10 text-emerald-600 text-xs font-semibold hover:bg-emerald-500/20 flex items-center gap-1",children:[e.jsx(he,{className:"h-3.5 w-3.5"})," Accept"]})]})})]}
50,p.id)})})]})]})},Ht={welcome:{label:"Welcome Email",icon:"🎉",desc:"Sent on new user signup"},milestone:{label:"Milestone",icon:"🏆",desc:"Sent when certificate earned"},workshop_reminder:{label:"Workshop Reminder",icon:"📅",desc:"Before workshops"},trial_ending:{label:"Trial Ending",icon:"⏳",desc:"2 days before trial expires"}},Xr=()=>{const[t,s]=u.useState([]),[n,a]=u.useState(!0),[r,i]=u.useState(""),[l,m]=u.useState(null);u.useEffect(()=>{o()},[]);const o=async()=>{a(!0);const{data:g}=await S.from("analytics_events").select("event_data, created_at").eq("event_type","email_sent").order("created_at",{ascending:!1}),h={};Object.keys(Ht).forEach(b=>{h[b]={count:0,lastSent:null}}),(g||[]).forEach(b=>{var f;const j=(f=b.event_data)==null?void 0:f.template;j&&h[j]!==void 0&&(h[j].count++,h[j].lastSent||(h[j].lastSent=b.created_at))}),s(Object.entries(h).map(([b,{count:j,lastSent:f}])=>({template:b,count:j,lastSent:f}))),a(!1)},c=async g=>{var h;if(!r){w.error("Enter a test email address first");return}m(g);try{const{data:{session:b}}=await S.auth.getSession();if(!b){w.error("Not authenticated");return}const d=await(await fetch("https://kcnwnuwipzuluqsgujtk.supabase.co/functions/v1/academy-send-email",{method:"POST",headers:{Authorization:`Bearer ${b.access_token}`,"Content-Type":"application/json"},body:JSON.stringify({template:g,user_id:b.user.id,data:{certificateTitle:"AI Explorer Certificate",tierEmoji:"🔍",shareToken:"test-token",nextTier:"AI Practitioner",nextTierScore:50,workshopTitle:"AI Mastery Workshop",date:"Jan 15, 2026",time:"2:00 PM EST",location:"Virtual (Zoom)",reminderType:"1d",meetingLink:"https://zoom.us/test",preparation:"Bring your laptop and a notebook"}})})).json();d.success?(w.success(`Test "${(h=Ht[g])==null?void 0:h.label}" email generated for ${d.recipient}`),o()):d.skipped?w.info(`Skipped: ${d.reason}`):w.error(d.error||"Failed")}catch(b){w.error(b.message)}finally{m(null)}},x=t.reduce((g,h)=>g+h.count,0);return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-6 flex-wrap gap-3",children:[e.jsxs("div",{children:[e.jsxs("h2",{className:"text-2xl font-extrabold text-foreground flex items-center gap-2",children:[e.jsx(cs,{className:"h-6 w-6 text-primary"})," Email Management"]}),e.jsxs("p",{className:"text-sm text-muted-foreground mt-1",children:[x," total emails sent"]})]}),e.jsx("button",{onClick:o,className:"p-2 rounded-lg hover:bg-muted transition-colors",children:e.jsx(xt,{className:"h-4 w-4 text-muted-foreground"})})]}),e.jsxs("div",{className:"academy-card p-4 mb-6",children:[e.jsx("label",{className:"block text-xs font-bold text-muted-foreground mb-1.5",children:"Test Email Address"}),e.jsx(q,{value:r,onChange:g=>i(g.target.value),placeholder:"Enter email to send test to...",className:"max-w-md"}),e.jsx("p",{className:"text-[10px] text-muted-foreground mt-1",children:'Used for "Send Test" buttons below'})]}),e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:n?Array.from({length:4}).map((g,h)=>e.jsx("div",{className:"academy-card p-5",children:e.jsx("div",{className:"h-20 rounded skeleton-shimmer"})},h)):t.map(g=>{const h=Ht[g.template];return h?e.jsxs("div",{className:"academy-card p-5",children:[e.jsxs("div",{className:"flex items-start justify-between mb-3",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"text-2xl",children:h.icon}),e.jsxs("div",{children:[e.jsx("h3",{className:"font-bold text-foreground text-sm",children:h.label}),e.jsx("p",{className:"text-xs text-muted-foreground",children:h.desc})]})]}),e.jsxs("div",{className:"text-right",children:[e.jsx("p",{className:"text-lg font-extrabold text-foreground",children:g.count}),e.jsx("p",{className:"text-[10px] text-muted-foreground",children:"sent"})]})]}),g.lastSent&&e.jsxs("p",{className:"text-[10px] text-muted-foreground mb-3",children:["Last sent: ",new Date(g.lastSent).toLocaleDateString("en-US",{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})]}),e.jsxs("button",{onClick:()=>c(g.template),disabled:l===g.template||!r,className:"w-full py-2 rounded-xl bg-muted text-foreground text-xs font-semibold hover:bg-muted/80 transition-colors disabled:opacity-50 flex items-center justify-center gap-1.5",children:[l===g.template?e.jsx(H,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(oa,{className:"h-3.5 w-3.5"}),"Send Test"]})]},g.template):null})}),e.jsx("div",{className:"academy-card p-4 mt-6 border-l-4 border-primary",children:e.jsxs("p",{className:"text-xs text-muted-foreground",children:[e.jsx("strong",{className:"text-foreground",children:"Note:"})," Weekly Digest and Manual Broadcast emails require a dedicated email marketing service (e.g., Mailchimp, ConvertKit) as they are bulk/scheduled emails. The templates above handle transactional emails triggered by specific user actions."]})})]})},en=()=>{const[t,s]=u.useState("facebook"),[n,a]=u.useState(""),[r,i]=u.useState("https://hour-accelerator-landing.lovable.app/browse"),l={facebook:`🚀 New on 100x Hour AI Academy!
51
52[Title]
53
54Learn from the best AI content, curated and structured for real results.
55
56👉 ${r}
57
58#AI #ArtificialIntelligence #Learning`,twitter:`🚀 Just dropped on @100xHourAI:
59
60[Title]
61
62Free to start 👉 ${r}
63
64#AI #MachineLearning`,linkedin:`Excited to share new content on 100x Hour AI Academy!
65
66[Title]
67
68Our platform curates the world's best AI training content into structured learning paths.
69
70Start free: ${r}`},m=()=>{navigator.clipboard.writeText(n||l[t]),w.success("Copied to clipboard!")};return e.jsxs("div",{className:"space-y-4",children:[e.jsx("h3",{className:"text-sm font-extrabold text-foreground",children:"Social Share Composer"}),e.jsx("div",{className:"flex gap-2",children:["facebook","twitter","linkedin"].map(o=>e.jsx("button",{onClick:()=>{s(o),a(l[o])},className:`px-3 py-1.5 rounded-lg text-xs font-semibold capitalize transition-colors ${t===o?"bg-primary text-primary-foreground":"bg-muted text-muted-foreground hover:bg-muted/80"}`,children:o},o))}),e.jsx(q,{placeholder:"Link URL",value:r,onChange:o=>i(o.target.value),className:"text-sm"}),e.jsx(Te,{value:n||l[t],onChange:o=>a(o.target.value),rows:6,className:"text-sm font-mono"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("button",{onClick:m,className:"flex items-center gap-1.5 px-3 py-1.5 rounded-lg bg-primary text-primary-foreground text-xs font-semibold",children:[e.jsx(Vt,{className:"h-3.5 w-3.5"})," Copy Text"]}),e.jsxs("a",{href:r,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 px-3 py-1.5 rounded-lg bg-muted text-foreground text-xs font-semibold hover:bg-muted/80",children:[e.jsx(Mt,{className:"h-3.5 w-3.5"})," Preview Link"]})]})]})},tn=()=>{const[t,s]=u.useState([]),[n,a]=u.useState(!0);u.useEffect(()=>{(async()=>{a(!0);const{data:l}=await S.from("profiles").select("referral_code, display_name, referred_by").not("referral_code","is",null);if(l){const m=new Map,o=l;for(const c of o)c.referral_code&&(m.has(c.referral_code)||m.set(c.referral_code,{name:c.display_name||"Unknown",signups:0}));for(const c of o)c.referred_by&&m.has(c.referred_by)&&m.get(c.referred_by).signups++;s(Array.from(m.entries()).map(([c,x])=>({code:c,...x})).sort((c,x)=>x.signups-c.signups))}a(!1)})()},[]);const r=t.reduce((i,l)=>i+l.signups,0);return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h3",{className:"text-sm font-extrabold text-foreground",children:"Referral Dashboard"}),e.jsxs("span",{className:"text-xs font-semibold text-muted-foreground",children:[r," total referral sign-ups"]})]}),n?e.jsx("p",{className:"text-sm text-muted-foreground",children:"Loading…"}):t.length===0?e.jsx("p",{className:"text-sm text-muted-foreground",children:"No referrals yet."}):e.jsx("div",{className:"rounded-lg border border-border overflow-hidden",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"bg-muted/50",children:e.jsxs("tr",{children:[e.jsx("th",{className:"text-left px-3 py-2 text-xs font-bold text-muted-foreground",children:"#"}),e.jsx("th",{className:"text-left px-3 py-2 text-xs font-bold text-muted-foreground",children:"Referrer"}),e.jsx("th",{className:"text-left px-3 py-2 text-xs font-bold text-muted-foreground",children:"Code"}),e.jsx("th",{className:"text-right px-3 py-2 text-xs font-bold text-muted-foreground",children:"Sign-ups"})]})}),e.jsx("tbody",{children:t.slice(0,20).map((i,l)=>e.jsxs("tr",{className:"border-t border-border",children:[e.jsx("td",{className:"px-3 py-2 text-muted-foreground",children:l+1}),e.jsx("td",{className:"px-3 py-2 font-medium text-foreground",children:i.name}),e.jsx("td",{className:"px-3 py-2 font-mono text-xs text-muted-foreground",children:i.code}),e.jsx("td",{className:"px-3 py-2 text-right font-bold text-foreground",children:i.signups})]},i.code))})]})})]})},sn=()=>{const[t,s]=u.useState([{id:"A",headline:"Master AI from the World's Best Content",subtitle:"Netflix for AI training",cta:"Start Free",active:!0},{id:"B",headline:"Turn One Hour into One Hundred",subtitle:"AI-powered learning paths",cta:"Get Started",active:!1}]),[n,a]=u.useState({});u.useEffect(()=>{(async()=>{const{data:l}=await S.from("analytics_events").select("event_type, event_data").in("event_type",["hero_view","hero_signup_click"]),m={A:{views:0,signups:0},B:{views:0,signups:0}};
70(l||[]).forEach(o=>{var x,g,h;const c=((x=o.event_data)==null?void 0:x.variant)||"A";o.event_type==="hero_view"&&(m[c]={...m[c],views:(((g=m[c])==null?void 0:g.views)||0)+1}),o.event_type==="hero_signup_click"&&(m[c]={...m[c],signups:(((h=m[c])==null?void 0:h.signups)||0)+1})}),a(m)})()},[]);const r=i=>{s(l=>l.map(m=>({...m,active:m.id===i}))),localStorage.setItem("hero_ab_variant",i),w.success(`Variant ${i} is now active`)};return e.jsxs("div",{className:"space-y-4",children:[e.jsx("h3",{className:"text-sm font-extrabold text-foreground",children:"Landing Page A/B Testing"}),e.jsx("div",{className:"grid gap-4 md:grid-cols-2",children:t.map(i=>{const l=n[i.id]||{views:0,signups:0},m=l.views>0?(l.signups/l.views*100).toFixed(1):"0.0";return e.jsxs("div",{className:`academy-card p-4 ${i.active?"ring-2 ring-primary":""}`,children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsxs("span",{className:"text-xs font-bold text-muted-foreground",children:["Variant ",i.id]}),e.jsx("button",{onClick:()=>r(i.id),className:`px-2 py-0.5 rounded text-[10px] font-bold ${i.active?"bg-emerald-500/10 text-emerald-600":"bg-muted text-muted-foreground hover:bg-muted/80"}`,children:i.active?"ACTIVE":"Activate"})]}),e.jsx(q,{value:i.headline,onChange:o=>s(c=>c.map(x=>x.id===i.id?{...x,headline:o.target.value}:x)),className:"text-sm font-semibold mb-2",placeholder:"Headline"}),e.jsx(q,{value:i.subtitle,onChange:o=>s(c=>c.map(x=>x.id===i.id?{...x,subtitle:o.target.value}:x)),className:"text-xs mb-2",placeholder:"Subtitle"}),e.jsx(q,{value:i.cta,onChange:o=>s(c=>c.map(x=>x.id===i.id?{...x,cta:o.target.value}:x)),className:"text-xs mb-3",placeholder:"CTA Text"}),e.jsxs("div",{className:"flex gap-4 text-xs",children:[e.jsxs("span",{className:"text-muted-foreground",children:["Views: ",e.jsx("strong",{className:"text-foreground",children:l.views})]}),e.jsxs("span",{className:"text-muted-foreground",children:["Sign-ups: ",e.jsx("strong",{className:"text-foreground",children:l.signups})]}),e.jsxs("span",{className:"text-muted-foreground",children:["Conv: ",e.jsxs("strong",{className:"text-foreground",children:[m,"%"]})]})]})]},i.id)})})]})},an=()=>e.jsxs("div",{children:[e.jsx("h2",{className:"text-xl font-extrabold text-foreground mb-6",children:"Marketing Toolkit"}),e.jsxs(ft,{defaultValue:"social",className:"space-y-6",children:[e.jsxs(gt,{className:"bg-muted/50",children:[e.jsxs(te,{value:"social",className:"text-xs gap-1.5",children:[e.jsx(qa,{className:"h-3.5 w-3.5"})," Social Share"]}),e.jsxs(te,{value:"referrals",className:"text-xs gap-1.5",children:[e.jsx(Ft,{className:"h-3.5 w-3.5"})," Referrals"]}),e.jsxs(te,{value:"ab",className:"text-xs gap-1.5",children:[e.jsx(Ba,{className:"h-3.5 w-3.5"})," A/B Testing"]})]}),e.jsx(se,{value:"social",children:e.jsx("div",{className:"academy-card p-5",children:e.jsx(en,{})})}),e.jsx(se,{value:"referrals",children:e.jsx("div",{className:"academy-card p-5",children:e.jsx(tn,{})})}),e.jsx(se,{value:"ab",children:e.jsx("div",{className:"academy-card p-5",children:e.jsx(sn,{})})})]})]}),jt=u.forwardRef(({className:t,...s},n)=>e.jsx("div",{className:"relative w-full overflow-auto",children:e.jsx("table",{ref:n,className:Ve("w-full caption-bottom text-sm",t),...s})}));jt.displayName="Table";const vt=u.forwardRef(({className:t,...s},n)=>e.jsx("thead",{ref:n,className:Ve("[&_tr]:border-b",t),...s}));vt.displayName="TableHeader";const yt=u.forwardRef(({className:t,...s},n)=>e.jsx("tbody",{ref:n,className:Ve("[&_tr:last-child]:border-0",t),...s}));yt.displayName="TableBody";const rn=u.forwardRef(({className:t,...s},n)=>e.jsx("tfoot",{ref:n,className:Ve("border-t bg-muted/50 font-medium [&>tr]:last:border-b-0",t),...s}));rn.displayName="TableFooter";const de=u.forwardRef(({className:t,...s},n)=>e.jsx("tr",{ref:n,className:Ve("border-b transition-colors hover:bg-muted/50 data-[state=selected]:bg-muted",t),...s}));de.displayName="TableRow";const ee=u.forwardRef(({className:t,...s},n)=>e.jsx("th",{ref:n,className:Ve("h-12 px-4 text-left align-middle font-medium text-muted-foreground [&:has([role=checkbox])]:pr-0",t),...s}));ee.displayName="TableHead";const Y=u.forwardRef(({className:t,...s},n)=>e.jsx("td",{ref:n,className:Ve("p-4 align-middle [&:has([role=checkbox])]:pr-0",t),...s}));Y.displayName="TableCell";const nn=u.forwardRef(({className:t,...s},n)=>e.jsx("caption",{ref:n,className:Ve("mt-4 text-sm text-muted-foreground",t),...s}));nn.displayName="TableCaption";const ln=({videos:t})=>{const[s,n]=u.useState(0),a=new Date,r=new Date(a.getFullYear(),a.getMonth()+s,1),i=r.getFullYear(),l=r.getMonth(),m=new Date(i,l+1,0).getDate(),o=new Date(i,l,1).getDay(),c=r.toLocaleStr
70ing("default",{month:"long",year:"numeric"}),x=u.useMemo(()=>{const f={};return t.forEach(d=>{const C=d.created_at?new Date(d.created_at):null;if(C&&C.getFullYear()===i&&C.getMonth()===l){const E=C.getDate();(f[E]=f[E]||[]).push(d)}}),f},[t,i,l]),g=u.useMemo(()=>{let f=0;Object.values(x).forEach(C=>f+=C.length);const d=Math.ceil(m/7);return{total:f,avg:d>0?(f/d).toFixed(1):"0"}},[x,m]),h=[];for(let f=0;f<o;f++)h.push(null);for(let f=1;f<=m;f++)h.push(f);const[b,j]=u.useState(null);return e.jsxs(ne,{children:[e.jsxs(Ce,{className:"pb-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(Ae,{className:"flex items-center gap-2 text-base",children:[e.jsx(Ks,{className:"h-4 w-4 text-primary"})," Content Calendar"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Z,{variant:"ghost",size:"icon",onClick:()=>n(f=>f-1),children:e.jsx(Ts,{className:"h-4 w-4"})}),e.jsx("span",{className:"text-sm font-semibold min-w-[140px] text-center",children:c}),e.jsx(Z,{variant:"ghost",size:"icon",onClick:()=>n(f=>f+1),children:e.jsx(Ps,{className:"h-4 w-4"})})]})]}),e.jsxs("div",{className:"flex gap-4 text-xs text-muted-foreground mt-1",children:[e.jsxs("span",{children:["Videos this month: ",e.jsx("strong",{className:"text-foreground",children:g.total})]}),e.jsxs("span",{children:["Avg/week: ",e.jsx("strong",{className:Number(g.avg)<5?"text-amber-500":"text-emerald-500",children:g.avg})," / 5 target"]})]})]}),e.jsx(ie,{children:e.jsxs("div",{className:"grid grid-cols-7 gap-1",children:[["Sun","Mon","Tue","Wed","Thu","Fri","Sat"].map(f=>e.jsx("div",{className:"text-[10px] font-bold text-muted-foreground text-center py-1",children:f},f)),h.map((f,d)=>{const C=f?x[f]||[]:[],E=f!==null&&C.length===0,D=f!==null&&new Date(i,l,f)<new Date(a.getFullYear(),a.getMonth(),a.getDate());return e.jsx("div",{className:`relative min-h-[48px] rounded-md border p-1 text-xs transition-colors ${f===null?"border-transparent":E&&D?"border-amber-200 bg-amber-50 dark:bg-amber-950/20 dark:border-amber-800":C.length>0?"border-border bg-muted/30":"border-border"}`,onMouseEnter:()=>f&&j(f),onMouseLeave:()=>j(null),children:f&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"font-semibold text-muted-foreground",children:f}),C.length>0&&e.jsxs("div",{className:"flex flex-wrap gap-0.5 mt-0.5",children:[C.slice(0,4).map((k,O)=>{var T;return e.jsx("div",{className:"w-2 h-2 rounded-full",style:{backgroundColor:((T=k.channels)==null?void 0:T.color)||"hsl(var(--primary))"}},O)}),C.length>4&&e.jsxs("span",{className:"text-[9px] text-muted-foreground",children:["+",C.length-4]})]}),b===f&&C.length>0&&e.jsx("div",{className:"absolute z-20 left-0 top-full mt-1 bg-popover border rounded-lg shadow-lg p-2 w-52 pointer-events-none",children:C.map(k=>e.jsx("p",{className:"text-[11px] text-foreground truncate",children:k.title},k.id))})]})},d)})]})})]})},on=({videos:t})=>{const s=new Date(Date.now()-15552e6).toISOString(),n=t.filter(c=>c.published_at&&c.published_at<s&&(c.view_count||0)<10),a=t.filter(c=>c.transcript_status!=="ready"),r=t.filter(c=>c.transcript_status==="ready"&&c.rag_status!=="ingested"),i=t.filter(c=>c.rating_avg!==null&&Number(c.rating_avg)>0&&Number(c.rating_avg)<3),l=async()=>{const c=a.slice(0,10);if(c.length!==0){w.info(`Triggering transcript extraction for ${c.length} videos...`);for(const x of c)await S.functions.invoke("academy-transcript",{body:{video_id:x.id,youtube_id:x.youtube_id}});w.success(`Triggered ${c.length} transcript extractions`)}},m=async()=>{const c=r.slice(0,10);if(c.length!==0){w.info(`Triggering RAG ingestion for ${c.length} videos...`);for(const x of c)await S.functions.invoke("academy-rag-ingest",{body:{video_id:x.id}});w.success(`Triggered ${c.length} RAG ingestions`)}},o=[{label:"Stale Videos",desc:">6 months, <10 views",count:n.length,color:"text-amber-500",icon:Ga,action:null},{label:"Missing Transcripts",desc:"Blocks RAG search",count:a.length,color:"text-red-500",icon:Dt,action:l,actionLabel:"Extract (next 10)"},{label:"Missing RAG",desc:"Transcript ready, not ingested",count:r.length,color:"text-orange-500",icon:rs,action:m,actionLabel:"Ingest (next 10)"},{label:"Low Rated",desc:"Rating < 3.0",count:i.length,color:"text-red-400",icon:as,action:null}];return e.jsxs(ne,{children:[e.jsx(Ce,{className:"pb-3",children:e.jsxs(Ae,{className:"flex items-center gap-2 text-base",children:[e.jsx(Gs,{className:"h-4 w-4 text-primary"})," Content Health"]})}),e.jsx(ie,{children:e.jsx("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4",children:o.map(c=>e.jsxs("div",{className:"rounded-lg border p-3",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx(c.icon,{className:`h-4 w-4 ${c.color}`}),e.jsx("span",{className:"text-xs font-bold text-foreground",children:c.label})]}),e.jsx("p",{className:"text-2xl font-black text-foreground",children:c.count}),e.jsx("p",{className:"text-[10px] text-muted-foreground",children:c.desc}),c.action&&c.count>0&&e.jsx(Z,{size:"sm",variant:"outline",className:"mt-2 h-7 text-xs",onClick:c.action,children:c.actionLabel})]},c.label))})})]})},ia=t=>{const s=Math.min(25,t.view_count?Math.log10(t.view_count+1)*10:0),n=Math.min(25,(Number(t.rating_avg)||0)*5),r=(t.published_at?Date.now()-new Date(t.published_at).getTime():1/0)/864e5,i=Math.max(0,25-r/365*25),l=t.transcript_status==="ready"?12.5:0,m=t.rag_status==="ingested"?12.5:0;return Math.round(s+n+i+l+m)},cn=({videos:t})=>{const s=u.useMemo(()=>t.map(r=>({...r,quality:ia(r)})).sort((r,i)=>r.quality-i.quality),[t]),n=s.length>0?Math.round(s.reduce((r,i)=>r+i.quality,0)/s.length):0,a=s.filter(r=>r.quality<30);return e.jsxs(ne,{children:[e.jsxs(Ce,{className:"pb-3",children:[e.jsxs(Ae,{className:"flex items-center gap-2 text-base",children:[e.jsx(We,{className:"h-4 w-4 text-primary"})," Content Quality Scores"]}),e.jsxs("div",{className:"flex gap-4 text-xs text-muted-foreground",children:[e.jsxs("span",{children:["Average: ",e.jsxs("strong",{className:"text-foreground",children:[n,"/100"]})]}),e.jsxs("span",{children:["Low quality (<30): ",e.jsx("strong",{className:a.length>0?"text-amber-500":"text-emerald-500",children:a.length})]})]})]}),e.jsx(ie,{children:a.length>0?e.jsx("div",{className:"border rounded-lg overflow-hidden",children:e.jsxs(jt,{children:[e.jsx(vt,{children:e.jsxs(de,{children:[e.jsx(ee,{children:"Video"}),e.jsx(ee,{className:"w-20",children:"Score"}),e.jsx(ee,{className:"w-20",children:"Views"}),e.jsx(ee,{className:"w-20",children:"Rating"})]})}),e.jsx(yt,{children:a.slice(0,15).map(r=>e.jsxs(de,{className:"bg-amber-50/50 dark:bg-amber-950/10",children:[e.jsx(Y,{className:"text-sm font-medium truncate max-w-[250px]",children:r.title}),e.jsx(Y,{children:e.jsx(it,{variant:"outline",className:"bg-amber-100 text-amber-800 dark:bg-amber-900 dark:text-amber-200 border-amber-300",children:r.quality})}),e.jsx(Y,{className:"text-sm text-muted-foreground",children:r.view_count||0}),e.jsx(Y,{className:"text-sm text-muted-foreground",children:Number(r.rating_avg||0).toFixed(1)})]},r.id))})]})}):e.jsx("p",{className:"text-sm text-muted-foreground text-center py-6",children:"✅ All videos meet quality threshold"})})]})},dn=({videos:t})=>{const[s,n]=u.useState([]),[a,r]=u.useState(!1),i=()=>{r(!0),setTimeout(()=>{const l=[],m=x=>x.toLowerCase().replace(/[^a-z0-9\s]/g,"").trim(),o=x=>{const g=new Set;for(let h=0;h<x.length-1;h++)g.add(x.slice(h,h+2));return g},c=(x,g)=>{const h=o(x),b=o(g);let j=0;return h.forEach(f=>{b.has(f)&&j++}),h.size+b.size>0?2*j/(h.size+b.size):0};for(let x=0;x<t.length;x++)for(let g=x+1;g<t.length;g++){const h=c(m(t[x].title),m(t[g].title));h>.6&&l.push({a:t[x],b:t[g],similarity:Math.round(h*100)})}l.sort((x,g)=>g.similarity-x.similarity),n(l.slice(0,20)),r(!1),w.success(`Found ${l.length} potential duplicate pairs`)},100)};return e.jsxs(ne,{children:[e.jsx(Ce,{className:"pb-3",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(Ae,{className:"flex items-center gap-2 text-base",children:[e.jsx(Vt,{className:"h-4 w-4 text-primary"})," Duplicate Detection"]}),e.jsxs(Z,{size:"sm",onClick:i,disabled:a,children:[a?e.jsx(H,{className:"h-3 w-3 animate-spin mr-1"}):e.jsx(xt,{className:"h-3 w-3 mr-1"}),"Scan"]})]})}),e.jsx(ie,{children:s.length===0?e.jsx("p",{className:"text-sm text-muted-foreground text-center py-6",children:a?"Scanning...":"Click Scan to check for duplicate videos"}):e.jsx("div",{className:"space-y-2 max-h-[400px] overflow-y-auto",children:s.map((l,m)=>e.jsxs("div",{className:"flex items-center gap-3 p-2 rounded-lg border bg-muted/20",children:[e.jsxs(it,{variant:"outline",className:l.similarity>80?"bg-red-100 text-red-800 border-red-300":"bg-amber-100 text-amber-800 border-amber-300",children:[l.similarity,"%"]}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-xs font-medium truncate",children:l.a.title}),e.jsx("p",{className:"text-xs text-muted-foreground truncate",children:l.b.title})]})]},m))})})]})},un=["ai","gpt","claude","llm","prompt","agent","automation","api","python","react","supabase","lovable","cursor","voice","chatbot","rag","embedding","vector","openai","anthropic","perplexity","midjourney","stable diffusion","langchain","tool-use","function-calling","fine-tuning","training","no-code","low-code","workflow","n8n","zapier","make","whisper","tts","stt","elevenlabs","typescript","javascript","nextjs","tailwind","database","sql","deployment","vercel","docker"],mn=({videos:t})=>{const[s,n]=u.useState([]),[a,r]=u.useState(!1),i=()=>{r(!0);const m=[];t.forEach(o=>{if(!o.transcript_text&&!o.title)return;const c=`${o.title} ${o.transcript_text||""}`.toLowerCase(),x=new Set((o.tags||[]).map(h=>h.toLowerCase())),g=un.filter(h=>c.includes(h)&&!x.has(h));g.length>0&&m.push({video:o,suggestedTags:g.slice(0,8)})}),m.sort((o,c)=>c.suggestedTags.length-o.suggestedTags.length),n(m.slice(0,30)),r(!1),w.success(`Found tag suggestions for ${m.length} videos`)},l=async(m,o)=>{const c=t.find(h=>h.id===m);if(!c)return;const x=[...new Set([...c.tags||[],...o])],{error:g}=await S.from("videos").update({tags:x}).eq("id",m);g?w.error(g.message):(w.success("Tags applied"),n(h=>h.filter(b=>b.video.id!==m)))};return e.jsxs(ne,{children:[e.jsx(Ce,{className:"pb-3",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(Ae,{className:"flex items-center gap-2 text-base",children:[e.jsx(Ws,{className:"h-4 w-4 text-primary"})," Auto-Tag Suggestions"]}),e.jsxs(Z,{size:"sm",onClick:i,disabled:a,children:[a?e.jsx(H,{className:"h-3 w-3 animate-spin mr-1"}):e.jsx(rs,{className:"h-3 w-3 mr-1"}),"Analyze All"]})]})}),e.jsx(ie,{children:s.length===0?e.jsx("p",{className:"text-sm text-muted-foreground text-center py-6",children:'Click "Analyze All" to generate tag suggestions from transcripts'}):e.jsx("div",{className:"space-y-3 max-h-[400px] overflow-y-auto",children:s.map(m=>e.jsxs("div",{className:"p-2 rounded-lg border",children:[e.jsx("p",{className:"text-xs font-semibold truncate mb-1",children:m.video.title}),e.jsx("div",{className:"flex flex-wrap gap-1 mb-2",children:m.suggestedTags.map(o=>e.jsx(it,{variant:"secondary",className:"text-[10px]",children:o},o))}),e.jsx(Z,{size:"sm",variant:"outline",className:"h-6 text-[10px]",onClick:()=>l(m.video.id,m.suggestedTags),children:"Apply All"})]},m.video.id))})})]})},xn=({videos:t})=>{const[s,n]=u.useState(new Set),a=i=>{n(l=>{const m=new Set(l);return m.has(i)?m.delete(i):m.size<4?m.add(i):w.error("Max 4 videos"),m})},r=t.filter(i=>s.has(i.id));return e.jsxs(ne,{children:[e.jsxs(Ce,{className:"pb-3",children:[e.jsxs(Ae,{className:"flex items-center gap-2 text-base",children:[e.jsx(zt,{className:"h-4 w-4 text-primary"})," Video Performance Comparison"]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Select 2-4 videos to compare"})]}),e.jsxs(ie,{children:[r.length>=2&&e.jsx("div",{className:"border rounded-lg overflow-hidden mb-4",children:e.jsxs(jt,{children:[e.jsx(vt,{children:e.jsxs(de,{children:[e.jsx(ee,{children:"Metric"}),r.map(i=>e.jsx(ee,{className:"text-xs max-w-[150px] truncate",children:i.title},i.id))]})}),e.jsxs(yt,{children:[e.jsxs(de,{children:[e.jsx(Y,{className:"font-medium text-sm",children:"Views"}),r.map(i=>e.jsx(Y,{className:"text-sm",children:i.view_count||0},i.id))]}),e.jsxs(de,{children:[e.jsx(Y,{className:"font-medium text-sm",children:"Rating"}),r.map(i=>e.jsx(Y,{className:"text-sm",children:Number(i.rating_avg||0).toFixed(1)},i.id))]}),e.jsxs(de,{children:[e.jsx(Y,{className:"font-medium text-sm",children:"Quality Score"}),r.map(i=>e.jsxs(Y,{className:"text-sm",children:[ia(i),"/100"]},i.id))]}),e.jsxs(de,{children:[e.jsx(Y,{className:"font-medium text-sm",children:"RAG Status"}),r.map(i=>e.jsx(Y,{children:e.jsx(it,{variant:"outline",className:i.rag_status==="ingested"?"bg-emerald-100 text-emerald-800":"bg-muted text-muted-foreground",children:i.rag_status||"pending"})},i.id))]}),e.jsxs(de,{children:[e.jsx(Y,{className:"font-medium text-sm",children:"Tags"}),r.map(i=>e.jsx(Y,{className:"text-xs",children:(i.tags||[]).join(", ")||"—"},i.id))]})]})]})}),e.jsx("div",{className:"max-h-[300px] overflow-y-auto space-y-1",children:t.slice(0,50).map(i=>e.jsxs("label",{className:`flex items-center gap-2 p-1.5 rounded cursor-pointer hover:bg-muted/50 transition-colors ${s.has(i.id)?"bg-primary/5":""}`,children:[e.jsx(ca,{checked:s.has(i.id),onCheckedChange:()=>a(i.id)}),e.jsx("span",{className:"text-xs truncate flex-1",children:i.title}),e.jsxs("span",{className:"text-[10px] text-muted-foreground",children:[i.view_count||0," views"]})]},i.id))})]})]})},hn=()=>{const[t,s]=u.useState([]),[n,a]=u.useState(!0);return u.useEffect(()=>{(async()=>{const{data:i}=await S.from("videos").select("id, title, youtube_id, published_at, view_count, rating_avg, tags, transcript_status, rag_status, rag_chunks_count, channel_id, created_at, transcript_text, channels(name, color)").order("created_at",{ascending:!1});s(i||[]),a(!1)})()},[]),n?e.jsx("div",{className:"flex items-center justify-center py-20",children:e.jsx(H,{className:"h-6 w-6 animate-spin text-primary"})}):e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-extrabold text-foreground mb-1",children:"Content Intelligence"}),e.jsx("p",{className:"text-sm text-muted-foreground mb-6",children:"Analytics, health monitoring, and content optimization tools"}),e.jsxs(ft,{defaultValue:"calendar",className:"space-y-4",children:[e.jsxs(gt,{className:"flex-wrap h-auto gap-1",children:[e.jsxs(te,{value:"calendar",className:"text-xs gap-1",children:[e.jsx(Ks,{className:"h-3 w-3"})," Calendar"]}),e.jsxs(te,{value:"health",className:"text-xs gap-1",children:[e.jsx(Gs,{className:"h-3 w-3"})," Health"]}
70),e.jsxs(te,{value:"quality",className:"text-xs gap-1",children:[e.jsx(We,{className:"h-3 w-3"})," Quality"]}),e.jsxs(te,{value:"duplicates",className:"text-xs gap-1",children:[e.jsx(Vt,{className:"h-3 w-3"})," Duplicates"]}),e.jsxs(te,{value:"tags",className:"text-xs gap-1",children:[e.jsx(Ws,{className:"h-3 w-3"})," Auto-Tags"]}),e.jsxs(te,{value:"compare",className:"text-xs gap-1",children:[e.jsx(zt,{className:"h-3 w-3"})," Compare"]})]}),e.jsx(se,{value:"calendar",children:e.jsx(ln,{videos:t})}),e.jsx(se,{value:"health",children:e.jsx(on,{videos:t})}),e.jsx(se,{value:"quality",children:e.jsx(cn,{videos:t})}),e.jsx(se,{value:"duplicates",children:e.jsx(dn,{videos:t})}),e.jsx(se,{value:"tags",children:e.jsx(mn,{videos:t})}),e.jsx(se,{value:"compare",children:e.jsx(xn,{videos:t})})]})]})},Ct=t=>`$${t.toLocaleString()}`,pn=()=>{const{user:t}=Ds(),[s,n]=u.useState([]),[a,r]=u.useState(!0),[i,l]=u.useState(""),[m,o]=u.useState("20"),[c,x]=u.useState("any"),[g,h]=u.useState("100"),[b,j]=u.useState(""),f=async()=>{const{data:E}=await S.from("coupons").select("*").order("created_at",{ascending:!1});n(E||[]),r(!1)};u.useEffect(()=>{f()},[]);const d=async()=>{if(!i.trim()){w.error("Enter a code");return}const{error:E}=await S.from("coupons").insert({code:i.toUpperCase().trim(),discount_percent:parseInt(m),applicable_tier:c==="any"?null:c,max_uses:parseInt(g)||null,expires_at:b||null,created_by:t==null?void 0:t.id});if(E){w.error(E.message);return}w.success(`Coupon ${i.toUpperCase()} created`),l(""),f()},C=async(E,D)=>{await S.from("coupons").update({is_active:!D}).eq("id",E),f()};return e.jsxs("div",{className:"space-y-4",children:[e.jsxs(ne,{children:[e.jsx(Ce,{className:"pb-3",children:e.jsxs(Ae,{className:"text-base flex items-center gap-2",children:[e.jsx(ye,{className:"h-4 w-4 text-primary"})," Create Coupon"]})}),e.jsx(ie,{children:e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-5 gap-3",children:[e.jsx(q,{placeholder:"CODE",value:i,onChange:E=>l(E.target.value),className:"uppercase"}),e.jsx(q,{type:"number",placeholder:"% off",value:m,onChange:E=>o(E.target.value)}),e.jsxs(da,{value:c,onValueChange:x,children:[e.jsx(ua,{children:e.jsx(ma,{})}),e.jsxs(xa,{children:[e.jsx(Bt,{value:"any",children:"Any Tier"}),e.jsx(Bt,{value:"pro",children:"Pro Only"}),e.jsx(Bt,{value:"premium",children:"Premium Only"})]})]}),e.jsx(q,{type:"number",placeholder:"Max uses",value:g,onChange:E=>h(E.target.value)}),e.jsxs(Z,{onClick:d,children:[e.jsx(ye,{className:"h-4 w-4 mr-1"})," Create"]})]})})]}),e.jsx(ne,{children:e.jsx(ie,{className:"pt-4",children:a?e.jsx("div",{className:"flex justify-center py-8",children:e.jsx(H,{className:"h-5 w-5 animate-spin text-primary"})}):e.jsxs(jt,{children:[e.jsx(vt,{children:e.jsxs(de,{children:[e.jsx(ee,{children:"Code"}),e.jsx(ee,{children:"Discount"}),e.jsx(ee,{children:"Tier"}),e.jsx(ee,{children:"Uses"}),e.jsx(ee,{children:"Status"}),e.jsx(ee,{children:"Actions"})]})}),e.jsxs(yt,{children:[s.map(E=>e.jsxs(de,{children:[e.jsx(Y,{children:e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("code",{className:"text-xs font-bold",children:E.code}),e.jsx("button",{onClick:()=>{navigator.clipboard.writeText(`${window.location.origin}/join?code=${E.code}`),w.success("Link copied")},children:e.jsx(Vt,{className:"h-3 w-3 text-muted-foreground hover:text-foreground"})})]})}),e.jsxs(Y,{className:"text-sm",children:[E.discount_percent,"%"]}),e.jsx(Y,{className:"text-sm",children:E.applicable_tier||"Any"}),e.jsxs(Y,{className:"text-sm",children:[E.uses_count,"/",E.max_uses||"∞"]}),e.jsx(Y,{children:e.jsx(it,{variant:E.is_active?"default":"secondary",className:"text-[10px]",children:E.is_active?"Active":"Disabled"})}),e.jsx(Y,{children:e.jsx(Wa,{checked:E.is_active,onCheckedChange:()=>C(E.id,E.is_active)})})]},E.id)),s.length===0&&e.jsx(de,{children:e.jsx(Y,{colSpan:6,className:"text-center text-sm text-muted-foreground py-6",children:"No coupons yet"})})]})]})})})]})},fn=()=>{const[t,s]=u.useState([]),[n,a]=u.useState(!0);u.useEffect(()=>{S.from("gift_codes").select("*").order("created_at",{ascending:!1}).limit(50).then(({data:m})=>{s(m||[]),a(!1)})},[]);const r=t.length,i=t.filter(m=>m.redeemed_at).length,l=r-i;return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-3 gap-4",children:[e.jsx(ne,{children:e.jsxs(ie,{className:"pt-4 text-center",children:[e.jsx("p",{className:"text-2xl font-bold text-foreground",children:r}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Total Gifts"})]})}),e.jsx(ne,{children:e.jsxs(ie,{className:"pt-4 text-center",children:[e.jsx("p",{className:"text-2xl font-bold text-emerald-600",children:i}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Redeemed"})]})}),e.jsx(ne,{children:e.jsxs(ie,{className:"pt-4 text-center",children:[e.jsx("p",{className:"text-2xl font-bold text-amber-500",children:l}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Pending"})]})})]}),e.jsx(ne,{children:e.jsx(ie,{className:"pt-4",children:n?e.jsx("div",{className:"flex justify-center py-8",children:e.jsx(H,{className:"h-5 w-5 animate-spin text-primary"})}):e.jsxs(jt,{children:[e.jsx(vt,{children:e.jsxs(de,{children:[e.jsx(ee,{children:"Code"}),e.jsx(ee,{children:"Tier"}),e.jsx(ee,{children:"Duration"}),e.jsx(ee,{children:"Recipient"}),e.jsx(ee,{children:"Status"})]})}),e.jsx(yt,{children:t.map(m=>e.jsxs(de,{children:[e.jsx(Y,{children:e.jsx("code",{className:"text-xs",children:m.code})}),e.jsx(Y,{className:"text-sm capitalize",children:m.tier}),e.jsxs(Y,{className:"text-sm",children:[m.duration_months,"mo"]}),e.jsx(Y,{className:"text-sm",children:m.recipient_email}),e.jsx(Y,{children:e.jsx(it,{variant:m.redeemed_at?"default":"secondary",className:"text-[10px]",children:m.redeemed_at?"Redeemed":"Pending"})})]},m.id))})]})})})]})},gn=()=>{const[t,s]=u.useState(0),[n,a]=u.useState(0),[r,i]=u.useState(0),[l,m]=u.useState(0),[o,c]=u.useState(0),[x,g]=u.useState(!0);u.useEffect(()=>{(async()=>{const[k,O,T]=await Promise.all([S.from("profiles").select("tier, created_at"),S.from("gift_codes").select("tier, duration_months, redeemed_at"),S.from("coupons").select("uses_count")]),p=k.data||[];i(p.length),s(p.filter(R=>R.tier==="pro").length),a(p.filter(R=>R.tier==="premium").length);const M=(O.data||[]).filter(R=>R.redeemed_at).reduce((R,v)=>{const P=v.tier==="premium"?197:47;return R+P*v.duration_months},0);
70m(M),c((T.data||[]).reduce((R,v)=>R+(v.uses_count||0),0)),g(!1)})()},[]);const h=t*47+n*197,b=h*12,j=r>0?Math.round(r*.05/r*100):0,f=h>0?Math.round(h/Math.max(t+n,1)*8):0,d=.08,C=[{month:"Current",mrr:h},{month:"+1 Month",mrr:Math.round(h*(1+d))},{month:"+2 Months",mrr:Math.round(h*Math.pow(1+d,2))},{month:"+3 Months",mrr:Math.round(h*Math.pow(1+d,3))}],E=[{name:"Organic",value:Math.round(h*.6),color:"hsl(262 83% 58%)"},{name:"Referral",value:Math.round(h*.2),color:"hsl(142 71% 45%)"},{name:"Coupon",value:Math.round(h*.1),color:"hsl(45 100% 50%)"},{name:"Gift",value:Math.round(l/12),color:"hsl(330 81% 60%)"}];return x?e.jsx("div",{className:"flex justify-center py-12",children:e.jsx(H,{className:"h-6 w-6 animate-spin text-primary"})}):e.jsxs("div",{className:"space-y-6",children:[e.jsx("div",{className:"grid grid-cols-2 md:grid-cols-4 lg:grid-cols-6 gap-4",children:[{label:"MRR",value:Ct(h),icon:ht,color:"hsl(142 71% 45%)"},{label:"ARR",value:Ct(b),icon:As,color:"hsl(217 91% 60%)"},{label:"Churn Rate",value:`~${j}%`,icon:ds,color:"hsl(0 72% 51%)"},{label:"Avg LTV",value:Ct(f),icon:We,color:"hsl(262 83% 58%)"},{label:"Gift Revenue",value:Ct(l),icon:Hs,color:"hsl(330 81% 60%)"},{label:"Coupon Uses",value:String(o),icon:Js,color:"hsl(45 100% 50%)"}].map(D=>e.jsxs("div",{className:"bg-card rounded-xl border p-4",style:{borderLeftWidth:3,borderLeftColor:D.color},children:[e.jsxs("div",{className:"flex items-center gap-1.5 mb-1",children:[e.jsx(D.icon,{className:"h-3.5 w-3.5 text-muted-foreground"}),e.jsx("span",{className:"text-[10px] font-bold uppercase tracking-wider text-muted-foreground",children:D.label})]}),e.jsx("p",{className:"text-xl font-bold text-foreground",children:D.value})]},D.label))}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6",children:[e.jsxs(ne,{children:[e.jsx(Ce,{className:"pb-2",children:e.jsxs(Ae,{className:"text-sm flex items-center gap-2",children:[e.jsx(Lt,{className:"h-4 w-4 text-primary"})," 3-Month Forecast"]})}),e.jsx(ie,{children:e.jsx(Xe,{width:"100%",height:200,children:e.jsxs(ra,{data:C,children:[e.jsx(ut,{strokeDasharray:"3 3",stroke:"hsl(var(--border))"}),e.jsx(st,{dataKey:"month",tick:{fontSize:10},stroke:"hsl(var(--muted-foreground))"}),e.jsx(at,{tick:{fontSize:10},stroke:"hsl(var(--muted-foreground))",tickFormatter:D=>`$${D}`}),e.jsx(et,{contentStyle:{fontSize:12,borderRadius:8},formatter:D=>[`$${D}`,"MRR"]}),e.jsx(os,{dataKey:"mrr",fill:"hsl(262 83% 58%)",radius:[4,4,0,0]})]})})})]}),e.jsxs(ne,{children:[e.jsx(Ce,{className:"pb-2",children:e.jsxs(Ae,{className:"text-sm flex items-center gap-2",children:[e.jsx(ht,{className:"h-4 w-4 text-primary"})," Revenue by Source"]})}),e.jsx(ie,{children:e.jsx(Xe,{width:"100%",height:200,children:e.jsxs(na,{children:[e.jsx(Pe,{data:E,cx:"50%",cy:"50%",innerRadius:45,outerRadius:80,paddingAngle:2,dataKey:"value",nameKey:"name",children:E.map((D,k)=>e.jsx(is,{fill:D.color},k))}),e.jsx(et,{contentStyle:{fontSize:12,borderRadius:8},formatter:D=>[`$${D}/mo`,""]}),e.jsx(Qt,{wrapperStyle:{fontSize:11}})]})})})]})]})]})},bn=()=>e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-extrabold text-foreground mb-1",children:"Billing & Revenue"}),e.jsx("p",{className:"text-sm text-muted-foreground mb-6",children:"Manage coupons, gifts, and revenue analytics"}),e.jsxs(ft,{defaultValue:"revenue",className:"space-y-4",children:[e.jsxs(gt,{className:"flex-wrap h-auto gap-1",children:[e.jsxs(te,{value:"revenue",className:"text-xs gap-1",children:[e.jsx(ht,{className:"h-3 w-3"})," Revenue"]}),e.jsxs(te,{value:"coupons",className:"text-xs gap-1",children:[e.jsx(Js,{className:"h-3 w-3"})," Coupons"]}),e.jsxs(te,{value:"gifts",className:"text-xs gap-1",children:[e.jsx(Hs,{className:"h-3 w-3"})," Gifts"]})]}),e.jsx(se,{value:"revenue",children:e.jsx(gn,{})}),e.jsx(se,{value:"coupons",children:e.jsx(pn,{})}),e.jsx(se,{value:"gifts",children:e.jsx(fn,{})})]})]}),ws={quote:"",author_name:"",author_role:"",avatar_url:"",rating:5,sort_order:0,is_published:!0},jn=()=>{const[t,s]=u.useState([]),[n,a]=u.useState(!0),[r,i]=u.useState(!1),[l,m]=u.useState(null),[o,c]=u.useState({...ws}),x=u.useCallback(async()=>{a(!0);const{data:d,error:C}=await S.from("testimonials").select("*").order("sort_order",{ascending:!0}).order("created_at",{ascending:!1});C&&w.error(C.message),s(d||[]),a(!1)},[]);u.useEffect(()=>{x()},[x]);const g=()=>{m(null),c({...ws}),i(!0)},h=d=>{m(d),c({quote:d.quote,author_name:d.author_name,author_role:d.author_role||"",avatar_url:d.avatar_url||"",rating:d.rating,sort_order:d.sort_order,is_published:d.is_published}),i(!0)},b=async()=>
70{if(!o.quote.trim()||!o.author_name.trim()){w.error("Quote and author name are required");return}const d={quote:o.quote.trim(),author_name:o.author_name.trim(),author_role:o.author_role.trim()||null,avatar_url:o.avatar_url.trim()||null,rating:Math.max(1,Math.min(5,Number(o.rating)||5)),sort_order:Number(o.sort_order)||0,is_published:o.is_published},{error:C}=l?await S.from("testimonials").update(d).eq("id",l.id):await S.from("testimonials").insert(d);if(C){w.error(C.message);return}w.success(l?"Updated":"Created"),i(!1),x()},j=async d=>{if(!confirm("Delete this testimonial?"))return;const{error:C}=await S.from("testimonials").delete().eq("id",d);if(C){w.error(C.message);return}w.success("Deleted"),x()},f=async d=>{const{error:C}=await S.from("testimonials").update({is_published:!d.is_published}).eq("id",d.id);if(C){w.error(C.message);return}x()};return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-6",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-extrabold text-foreground",children:"Testimonials"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Quotes shown on the homepage carousel."})]}),e.jsxs(Z,{onClick:g,children:[e.jsx(ye,{className:"h-4 w-4 mr-1"})," New testimonial"]})]}),n?e.jsx("div",{className:"flex justify-center py-10",children:e.jsx(H,{className:"h-6 w-6 animate-spin text-primary"})}):e.jsx("div",{className:"overflow-x-auto rounded-lg border border-border bg-card",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"bg-muted/40 text-xs uppercase tracking-wide text-muted-foreground",children:e.jsxs("tr",{children:[e.jsx("th",{className:"text-left p-3",children:"Author"}),e.jsx("th",{className:"text-left p-3",children:"Quote"}),e.jsx("th",{className:"text-left p-3",children:"Rating"}),e.jsx("th",{className:"text-left p-3",children:"Order"}),e.jsx("th",{className:"text-left p-3",children:"Status"}),e.jsx("th",{className:"p-3"})]})}),e.jsxs("tbody",{children:[t.map(d=>e.jsxs("tr",{className:"border-t border-border",children:[e.jsxs("td",{className:"p-3",children:[e.jsx("div",{className:"font-semibold",children:d.author_name}),e.jsx("div",{className:"text-xs text-muted-foreground",children:d.author_role})]}),e.jsx("td",{className:"p-3 max-w-md",children:e.jsx("div",{className:"line-clamp-2 text-muted-foreground",children:d.quote})}),e.jsx("td",{className:"p-3",children:e.jsx("div",{className:"flex items-center gap-0.5",children:Array.from({length:d.rating}).map((C,E)=>e.jsx(as,{className:"h-3.5 w-3.5 fill-amber-400 text-amber-400"},E))})}),e.jsx("td",{className:"p-3",children:d.sort_order}),e.jsx("td",{className:"p-3",children:e.jsx("button",{onClick:()=>f(d),className:`text-xs px-2 py-1 rounded ${d.is_published?"bg-emerald-500/15 text-emerald-500":"bg-muted text-muted-foreground"}`,children:d.is_published?"Published":"Hidden"})}),e.jsx("td",{className:"p-3 text-right",children:e.jsxs("div",{className:"flex justify-end gap-1",children:[e.jsx(Z,{size:"sm",variant:"ghost",onClick:()=>h(d),children:e.jsx(Ue,{className:"h-3.5 w-3.5"})}),e.jsx(Z,{size:"sm",variant:"ghost",onClick:()=>j(d.id),children:e.jsx(ze,{className:"h-3.5 w-3.5 text-destructive"})})]})})]},d.id)),t.length===0&&e.jsx("tr",{children:e.jsx("td",{colSpan:6,className:"p-10 text-center text-muted-foreground",children:"No testimonials yet."})})]})]})}),e.jsx(pe,{open:r,onOpenChange:i,children:e.jsxs(fe,{className:"max-w-lg",children:[e.jsx(ge,{children:e.jsx(be,{children:l?"Edit testimonial":"New testimonial"})}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-muted-foreground mb-1 block",children:"Quote"}),e.jsx(Te,{rows:4,value:o.quote,onChange:d=>c({...o,quote:d.target.value}),placeholder:"What did they say?"})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-muted-foreground mb-1 block",children:"Author name"}),e.jsx(q,{value:o.author_name,onChange:d=>c({...o,author_name:d.target.value})})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-muted-foreground mb-1 block",children:"Author role"}),e.jsx(q,{value:o.author_role,onChange:d=>c({...o,author_role:d.target.value}),placeholder:"Founder, Acme"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-muted-foreground mb-1 block",children:"Avatar URL"}),e.jsx(q,{value:o.avatar_url,onChange:d=>c({...o,avatar_url:d.target.value})})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-muted-foreground mb-1 block",children:"Rating (1–5)"}),e.jsx(q,{type:"number",min:1,max:5,value:o.rating,onChange:d=>c({...o,rating:Number(d.target.value)})})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-muted-foreground mb-1 block",children:"Sort order"}),e.jsx(q,{type:"number",value:o.sort_order,onChange:d=>c({...o,sort_order:Number(d.target.value)})})]}),e.jsx("div",{className:"flex items-end",children:e.jsxs("label",{className:"flex items-center gap-2 text-sm",children:[e.jsx("input",{type:"checkbox",checked:o.is_published,onChange:d=>c({...o,is_published:d.target.checked})}),"Published"]})})]}),e.jsxs("div",{className:"flex justify-end gap-2 pt-2",children:[e.jsx(Z,{variant:"ghost",onClick:()=>i(!1),children:"Cancel"}),e.jsx(Z,{onClick:b,children:l?"Save changes":"Create"})]})]})]})})]})},ks={title:"",description:"",link:"",is_published:!0,sort_order:0},vn=()=>{const[t,s]=u.useState([]),[n,a]=u.useState(!0),[r,i]=u.useState(!1),[l,m]=u.useState(null),[o,c]=u.useState({...ks}),x=u.useCallback(async()=>{a(!0);const{data:d,error:C}=await S.from("community_highlights").select("*").order("sort_order",{ascending:!0}).order("created_at",{ascending:!1});C&&w.error(C.message),s(d||[]),a(!1)},[]);u.useEffect(()=>{x()},[x]);const g=()=>{m(null),c({...ks}),i(!0)},h=d=>
70{m(d),c({title:d.title,description:d.description||"",link:d.link,is_published:d.is_published,sort_order:d.sort_order}),i(!0)},b=async()=>{if(!o.title.trim()||!o.link.trim()){w.error("Title and link are required");return}const d={title:o.title.trim(),description:o.description.trim()||null,link:o.link.trim(),is_published:o.is_published,sort_order:Number(o.sort_order)||0},{error:C}=l?await S.from("community_highlights").update(d).eq("id",l.id):await S.from("community_highlights").insert(d);if(C){w.error(C.message);return}w.success(l?"Updated":"Created"),i(!1),x()},j=async d=>{if(!confirm("Delete this highlight?"))return;const{error:C}=await S.from("community_highlights").delete().eq("id",d);if(C){w.error(C.message);return}w.success("Deleted"),x()},f=async d=>{const{error:C}=await S.from("community_highlights").update({is_published:!d.is_published}).eq("id",d.id);if(C){w.error(C.message);return}x()};return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-6",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-extrabold text-foreground",children:"Community Highlights"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:'Items featured in the dashboard "From the Community" widget.'})]}),e.jsxs(Z,{onClick:g,children:[e.jsx(ye,{className:"h-4 w-4 mr-1"})," New highlight"]})]}),n?e.jsx("div",{className:"flex justify-center py-10",children:e.jsx(H,{className:"h-6 w-6 animate-spin text-primary"})}):e.jsx("div",{className:"overflow-x-auto rounded-lg border border-border bg-card",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"bg-muted/40 text-xs uppercase tracking-wide text-muted-foreground",children:e.jsxs("tr",{children:[e.jsx("th",{className:"text-left p-3",children:"Title"}),e.jsx("th",{className:"text-left p-3",children:"Description"}),e.jsx("th",{className:"text-left p-3",children:"Link"}),e.jsx("th",{className:"text-left p-3",children:"Order"}),e.jsx("th",{className:"text-left p-3",children:"Status"}),e.jsx("th",{className:"p-3"})]})}),e.jsxs("tbody",{children:[t.map(d=>e.jsxs("tr",{className:"border-t border-border",children:[e.jsx("td",{className:"p-3 font-semibold",children:d.title}),e.jsx("td",{className:"p-3 max-w-md text-muted-foreground",children:e.jsx("div",{className:"line-clamp-2",children:d.description})}),e.jsx("td",{className:"p-3",children:e.jsxs("a",{href:d.link,target:"_blank",rel:"noreferrer",className:"inline-flex items-center gap-1 text-primary hover:underline text-xs",children:["Open ",e.jsx(Mt,{className:"h-3 w-3"})]})}),e.jsx("td",{className:"p-3",children:d.sort_order}),e.jsx("td",{className:"p-3",children:e.jsx("button",{onClick:()=>f(d),className:`text-xs px-2 py-1 rounded ${d.is_published?"bg-emerald-500/15 text-emerald-500":"bg-muted text-muted-foreground"}`,children:d.is_published?"Published":"Hidden"})}),e.jsx("td",{className:"p-3 text-right",children:e.jsxs("div",{className:"flex justify-end gap-1",children:[e.jsx(Z,{size:"sm",variant:"ghost",onClick:()=>h(d),children:e.jsx(Ue,{className:"h-3.5 w-3.5"})}),e.jsx(Z,{size:"sm",variant:"ghost",onClick:()=>j(d.id),children:e.jsx(ze,{className:"h-3.5 w-3.5 text-destructive"})})]})})]},d.id)),t.length===0&&e.jsx("tr",{children:e.jsx("td",{colSpan:6,className:"p-10 text-center text-muted-foreground",children:"No highlights yet."})})]})]})}),e.jsx(pe,{open:r,onOpenChange:i,children:e.jsxs(fe,{className:"max-w-lg",children:[e.jsx(ge,{children:e.jsx(be,{children:l?"Edit highlight":"New highlight"})}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-muted-foreground mb-1 block",children:"Title"}),e.jsx(q,{value:o.title,onChange:d=>c({...o,title:d.target.value})})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-muted-foreground mb-1 block",children:"Description"}),e.jsx(Te,{rows:3,value:o.description,onChange:d=>c({...o,description:d.target.value})})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-muted-foreground mb-1 block",children:"Link (Facebook discussion URL)"}),e.jsx(q,{value:o.link,onChange:d=>c({...o,link:d.target.value}),placeholder:"https://facebook.com/groups/chatgpt4u/posts/..."})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-muted-foreground mb-1 block",children:"Sort order"}),e.jsx(q,{type:"number",value:o.sort_order,onChange:d=>c({...o,sort_order:Number(d.target.value)})})]}),e.jsx("div",{className:"flex items-end",children:e.jsxs("label",{className:"flex items-center gap-2 text-sm",children:[e.jsx("input",{type:"checkbox",checked:o.is_published,onChange:d=>c({...o,is_published:d.target.checked})}),"Published"]})})]}),e.jsxs("div",{className:"flex justify-end gap-2 pt-2",children:[e.jsx(Z,{variant:"ghost",onClick:()=>i(!1),children:"Cancel"}),e.jsx(Z,{onClick:b,children:l?"Save changes":"Create"})]})]})]})})]})};function yn(t){if(t==null)return"";const s=String(t);return/[",\n]/.test(s)?`"${s.replace(/"/g,'""')}"`:s}function _s(t,s,n){const a=[n.join(",")];
70s.forEach(m=>a.push(n.map(o=>yn(m[o])).join(",")));const r=new Blob([a.join(`
71`)],{type:"text/csv;charset=utf-8"}),i=URL.createObjectURL(r),l=document.createElement("a");l.href=i,l.download=t,l.click(),URL.revokeObjectURL(i)}const Nn=()=>{const[t,s]=u.useState([]),[n,a]=u.useState([]),[r,i]=u.useState(!0),[l,m]=u.useState(""),[o,c]=u.useState("subscribers"),x=u.useCallback(async()=>{i(!0);const[{data:d,error:C},{data:E,error:D}]=await Promise.all([S.from("email_subscribers").select("*").order("subscribed_at",{ascending:!1}).limit(2e3),S.from("workshop_waitlist").select("*").order("created_at",{ascending:!1}).limit(2e3)]);C&&w.error(`Subscribers: ${C.message}`),D&&w.error(`Waitlist: ${D.message}`),s(d||[]),a(E||[]),i(!1)},[]);u.useEffect(()=>{x()},[x]);const g=t.filter(d=>!l||d.email.toLowerCase().includes(l.toLowerCase())||d.source.toLowerCase().includes(l.toLowerCase())),h=n.filter(d=>!l||d.email.toLowerCase().includes(l.toLowerCase())||d.name.toLowerCase().includes(l.toLowerCase())||(d.interest_topic||"").toLowerCase().includes(l.toLowerCase())),b=t.reduce((d,C)=>(d[C.source]=(d[C.source]||0)+1,d),{}),j=()=>{_s(`email-subscribers-${new Date().toISOString().slice(0,10)}.csv`,g.map(d=>({email:d.email,source:d.source,subscribed_at:d.subscribed_at,unsubscribed_at:d.unsubscribed_at})),["email","source","subscribed_at","unsubscribed_at"])},f=()=>{_s(`workshop-waitlist-${new Date().toISOString().slice(0,10)}.csv`,h.map(d=>({name:d.name,email:d.email,interest_topic:d.interest_topic,source:d.source,created_at:d.created_at})),["name","email","interest_topic","source","created_at"])};return e.jsxs("div",{children:[e.jsxs("div",{className:"flex flex-col md:flex-row md:items-center md:justify-between gap-3 mb-6",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-extrabold text-foreground",children:"Subscribers & Waitlist"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Email captures and workshop waitlist signups. Export to CSV."})]}),e.jsx("div",{className:"flex gap-2",children:e.jsx(q,{placeholder:"Search email or name…",value:l,onChange:d=>m(d.target.value),className:"md:w-64"})})]}),e.jsxs(ft,{value:o,onValueChange:c,children:[e.jsxs(gt,{children:[e.jsxs(te,{value:"subscribers",children:[e.jsx(cs,{className:"h-3.5 w-3.5 mr-1.5"})," Email subscribers (",t.length,")"]}),e.jsxs(te,{value:"waitlist",children:[e.jsx(Lt,{className:"h-3.5 w-3.5 mr-1.5"})," Workshop waitlist (",n.length,")"]})]}),e.jsx(se,{value:"subscribers",children:r?e.jsx("div",{className:"flex justify-center py-10",children:e.jsx(H,{className:"h-6 w-6 animate-spin text-primary"})}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex flex-wrap gap-2 mb-3",children:[Object.entries(b).map(([d,C])=>e.jsxs("span",{className:"text-xs px-2 py-1 rounded bg-muted text-muted-foreground",children:[d,": ",e.jsx("strong",{className:"text-foreground",children:C})]},d)),e.jsx("div",{className:"flex-1"}),e.jsxs(Z,{size:"sm",onClick:j,disabled:!g.length,children:[e.jsx(Ze,{className:"h-3.5 w-3.5 mr-1"})," Export CSV (",g.length,")"]})]}),e.jsx("div",{className:"overflow-x-auto rounded-lg border border-border bg-card",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"bg-muted/40 text-xs uppercase tracking-wide text-muted-foreground",children:e.jsxs("tr",{children:[e.jsx("th",{className:"text-left p-3",children:"Email"}),e.jsx("th",{className:"text-left p-3",children:"Source"}),e.jsx("th",{className:"text-left p-3",children:"Subscribed"}),e.jsx("th",{className:"text-left p-3",children:"Unsubscribed"})]})}),e.jsxs("tbody",{children:[g.map(d=>e.jsxs("tr",{className:"border-t border-border",children:[e.jsx("td",{className:"p-3 font-mono text-xs",children:d.email}),e.jsx("td",{className:"p-3",children:e.jsx("span",{className:"text-xs px-2 py-0.5 rounded bg-primary/10 text-primary",children:d.source})}),e.jsx("td",{className:"p-3 text-muted-foreground",children:new Date(d.subscribed_at).toLocaleString()}),e.jsx("td",{className:"p-3 text-muted-foreground",children:d.unsubscribed_at?new Date(d.unsubscribed_at).toLocaleStr
71ing():"—"})]},d.id)),g.length===0&&e.jsx("tr",{children:e.jsx("td",{colSpan:4,className:"p-10 text-center text-muted-foreground",children:"No subscribers match."})})]})]})})]})}),e.jsx(se,{value:"waitlist",children:r?e.jsx("div",{className:"flex justify-center py-10",children:e.jsx(H,{className:"h-6 w-6 animate-spin text-primary"})}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"flex justify-end mb-3",children:e.jsxs(Z,{size:"sm",onClick:f,disabled:!h.length,children:[e.jsx(Ze,{className:"h-3.5 w-3.5 mr-1"})," Export CSV (",h.length,")"]})}),e.jsx("div",{className:"overflow-x-auto rounded-lg border border-border bg-card",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"bg-muted/40 text-xs uppercase tracking-wide text-muted-foreground",children:e.jsxs("tr",{children:[e.jsx("th",{className:"text-left p-3",children:"Name"}),e.jsx("th",{className:"text-left p-3",children:"Email"}),e.jsx("th",{className:"text-left p-3",children:"Interest"}),e.jsx("th",{className:"text-left p-3",children:"Source"}),e.jsx("th",{className:"text-left p-3",children:"Joined"})]})}),e.jsxs("tbody",{children:[h.map(d=>e.jsxs("tr",{className:"border-t border-border",children:[e.jsx("td",{className:"p-3 font-semibold",children:d.name}),e.jsx("td",{className:"p-3 font-mono text-xs",children:d.email}),e.jsx("td",{className:"p-3 text-muted-foreground",children:d.interest_topic||"—"}),e.jsx("td",{className:"p-3 text-muted-foreground",children:d.source||"—"}),e.jsx("td",{className:"p-3 text-muted-foreground",children:new Date(d.created_at).toLocaleString()})]},d.id)),h.length===0&&e.jsx("tr",{children:e.jsx("td",{colSpan:5,className:"p-10 text-center text-muted-foreground",children:"No waitlist entries match."})})]})]})})]})})]})]})},Ss=[{key:"dashboard",label:"Dashboard",icon:Xa},{key:"videos",label:"Videos",icon:ns},{key:"channels",label:"Channels",icon:Ha},{key:"playlists",label:"Playlists",icon:Qs},{key:"sources",label:"Sources",icon:Cs},{key:"review",label:"Review Queue",icon:Ys},{key:"workshops",label:"Workshops",icon:Lt},{key:"tips",label:"Agent Tips",icon:Ka},{key:"analytics",label:"Analytics",icon:We},{key:"art",label:"Art Studio",icon:At},{key:"emails",label:"Emails",icon:cs},{key:"marketing",label:"Marketing",icon:Ya},{key:"intelligence",label:"Intelligence",icon:zt},{key:"billing",label:"Billing",icon:ht},{key:"testimonials",label:"Testimonials",icon:Bs},{key:"community",label:"Community",icon:Ft},{key:"subscribers",label:"Subscribers & Waitlist",icon:Za}],pt=["beginner","intermediate","advanced"],Kt=20,ii=()=>{var o;const{user:t}=Ds(),s=ha(),{isAdmin:n,loading:a}=pa(),[r,i]=u.useState("dashboard"),[l,m]=u.useState(!1);return u.useEffect(()=>{!a&&t&&!n&&s("/")},[a,t,n,s]),a?e.jsx("div",{className:"min-h-screen flex items-center justify-center bg-background",children:e.jsx(H,{className:"h-6 w-6 animate-spin text-primary"})}
71):n?e.jsxs("div",{className:"flex min-h-screen",children:[e.jsx("button",{className:"md:hidden fixed top-4 left-4 z-50 p-2 rounded-lg bg-[#0f172a] text-white",onClick:()=>m(!l),children:l?e.jsx(Rt,{className:"h-5 w-5"}):e.jsx(Ja,{className:"h-5 w-5"})}),l&&e.jsx("div",{className:"fixed inset-0 bg-black/40 z-40 md:hidden",onClick:()=>m(!1)}),e.jsxs("aside",{className:`${l?"fixed inset-y-0 left-0 z-50":"hidden md:flex"} w-[240px] shrink-0 bg-[#0f172a] text-white flex-col sticky top-0 h-screen md:flex`,children:[e.jsx("div",{className:"p-5 border-b border-white/10",children:e.jsx("h1",{className:"text-lg font-extrabold tracking-tight",children:"100x Admin"})}),e.jsx("nav",{className:"flex-1 p-3 space-y-0.5 overflow-y-auto",children:Ss.map(c=>e.jsxs("button",{onClick:()=>{i(c.key),m(!1)},className:`flex items-center gap-2.5 w-full px-3 py-2 rounded-lg text-sm font-medium transition-colors ${r===c.key?"bg-primary text-primary-foreground":"text-slate-400 hover:text-white hover:bg-white/5"}`,children:[e.jsx(c.icon,{className:"h-4 w-4 shrink-0"}),c.label]},c.key))}),e.jsx("div",{className:"p-4 border-t border-white/10",children:e.jsxs(fa,{to:"/browse",className:"flex items-center gap-2 text-xs text-slate-400 hover:text-white transition-colors",children:[e.jsx(ga,{className:"h-3.5 w-3.5"})," Back to Academy"]})})]}),e.jsx("main",{className:"flex-1 bg-background p-4 md:p-8 overflow-auto",children:e.jsxs("div",{className:"admin-table-wrapper",children:[r==="dashboard"&&e.jsx(wn,{onNav:i}),r==="videos"&&e.jsx(kn,{}),r==="channels"&&e.jsx(sr,{}),r==="playlists"&&e.jsx(nr,{}),r==="sources"&&e.jsx(lr,{}),r==="review"&&e.jsx(cr,{}),r==="tips"&&e.jsx(ur,{}),r==="workshops"&&e.jsx(xr,{}),r==="analytics"&&e.jsx(Qr,{}),r==="art"&&e.jsx(Zr,{}),r==="emails"&&e.jsx(Xr,{}),r==="marketing"&&e.jsx(an,{}),r==="intelligence"&&e.jsx(hn,{}),r==="billing"&&e.jsx(bn,{}),r==="testimonials"&&e.jsx(jn,{}),r==="community"&&e.jsx(vn,{}),r==="subscribers"&&e.jsx(Nn,{}),!["dashboard","videos","channels","playlists","sources","review","tips","workshops","analytics","art","emails","marketing","intelligence","billing","testimonials","community","subscribers"].includes(r)&&e.jsxs("div",{className:"text-center py-20",children:[e.jsx("p",{className:"text-lg font-semibold text-foreground mb-1",children:(o=Ss.find(c=>c.key===r))==null?void 0:o.label}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Coming soon"})]})]})})]}):null},wn=({onNav:t})=>{const[s,n]=u.useState({totalVideos:0,totalUsers:0,proSubs:0,premiumSubs:0,mrr:0,weekVideos:0,pendingReview:0}),[a,r]=u.useState([]),[i,l]=u.useState([]),[m,o]=u.useState({totalChunks:0,ingestedVideos:0,transcriptReady:0,avgChunks:0,totalVideos:0});u.useEffect(()=>{(async()=>{const[{count:b},{count:j},{data:f},{data:d}]=await Promise.all([S.from("videos").select("*",{count:"exact",head:!0}),S.from("profiles").select("*",{count:"exact",head:!0}),S.from("channels").select("name, video_count"),S.from("profiles").select("tier")]),C=new Date(Date.now()-7*864e5).toISOString(),{count:E}=await S.from("videos").select("*",{count:"exact",head:!0}).gte("created_at",C),{count:D}=await S.from("aggregation_queue").select("*",{count:"exact",head:!0}).eq("status","pending"),[{count:k},{count:O},{count:T}]=await Promise.all([S.from("video_chunks").select("*",{count:"exact",head:!0}),S.from("videos").select("*",{count:"exact",head:!0}).eq("rag_status","ingested"),S.from("videos").select("*",{count:"exact",head:!0}).eq("transcript_status","ready")]),p=(d||[]).reduce((P,N)=>{const I=N.tier||"free";return P[I]=(P[I]||0)+1,P},{}),_=p.pro||0,M=p.premium||0,R=b||0;n({totalVideos:R,totalUsers:j||0,proSubs:_,premiumSubs:M,mrr:_*47+M*197,weekVideos:E||0,pendingReview:D||0});const v=O||0;o({totalChunks:k||0,ingestedVideos:v,transcriptReady:T||0,avgChunks:v>0?Math.round((k||0)/v):0,totalVideos:R}),r((f||[]).map(P=>({name:P.name,count:P.video_count||0})).sort((P,N)=>N.count-P.count)),l(Object.entries(p).map(([P,N])=>({tier:P,count:N})))})()},[]);const c=[{label:"Total Videos",value:s.totalVideos,sub:`${a.slice(0,3).map(h=>`${h.name}: ${h.count}`).join(", ")}`},{label:"Total Users",value:s.totalUsers,sub:i.map(h=>`${h.tier}: ${h.count}`).join(", ")},{label:"Pro Subscribers",value:s.proSubs}
71,{label:"MRR",value:`$${s.mrr.toLocaleString()}`,sub:`Pro: $${s.proSubs*47} + Premium: $${s.premiumSubs*197}`},{label:"Videos This Week",value:s.weekVideos}],x=s.totalVideos>0?Math.round(m.transcriptReady/s.totalVideos*100):0,g=s.totalVideos>0?Math.round(m.ingestedVideos/s.totalVideos*100):0;return e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-extrabold text-foreground mb-6",children:"Dashboard"}),e.jsx("div",{className:"grid grid-cols-2 md:grid-cols-3 lg:grid-cols-5 gap-4 mb-8",children:c.map(h=>e.jsxs("div",{className:"academy-card p-4",children:[e.jsx("p",{className:"text-[11px] font-bold uppercase tracking-wider text-muted-foreground",children:h.label}),e.jsx("p",{className:"text-2xl font-black text-foreground mt-1",children:h.value}),h.sub&&e.jsx("p",{className:"text-[10px] text-muted-foreground mt-1 line-clamp-2",children:h.sub})]},h.label))}),e.jsxs("div",{className:"academy-card p-5 mb-8",children:[e.jsxs("h3",{className:"text-sm font-extrabold text-foreground mb-3 flex items-center gap-2",children:[e.jsx(We,{className:"h-4 w-4 text-primary"})," RAG Knowledge Base"]}),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-[11px] font-bold uppercase tracking-wider text-muted-foreground",children:"Total Chunks"}),e.jsx("p",{className:"text-xl font-black text-foreground mt-0.5",children:m.totalChunks.toLocaleString()})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-[11px] font-bold uppercase tracking-wider text-muted-foreground",children:"Videos Ingested"}),e.jsx("p",{className:"text-xl font-black text-foreground mt-0.5",children:m.ingestedVideos})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-[11px] font-bold uppercase tracking-wider text-muted-foreground",children:"Avg Chunks/Video"}),e.jsx("p",{className:"text-xl font-black text-foreground mt-0.5",children:m.avgChunks})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-[11px] font-bold uppercase tracking-wider text-muted-foreground",children:"Pipeline Health"}),e.jsxs("div",{className:"mt-1 space-y-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"flex-1 h-1.5 rounded-full bg-muted overflow-hidden",children:e.jsx("div",{className:"h-full rounded-full bg-emerald-500 transition-all",style:{width:`${x}%`}})}),e.jsxs("span",{className:"text-[10px] font-semibold text-muted-foreground",children:[x,"% transcribed"]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"flex-1 h-1.5 rounded-full bg-muted overflow-hidden",children:e.jsx("div",{className:"h-full rounded-full bg-primary transition-all",style:{width:`${g}%`}})}),e.jsxs("span",{className:"text-[10px] font-semibold text-muted-foreground",children:[g,"% ingested"]})]})]})]})]})]}),e.jsx("div",{className:"mb-8",children:e.jsx(Jr,{})}),e.jsxs("div",{className:"flex flex-wrap gap-3",children:[e.jsxs("button",{onClick:()=>t("videos"),className:"px-4 py-2 rounded-xl bg-primary text-primary-foreground text-sm font-semibold hover:opacity-90 transition-opacity flex items-center gap-2",children:[e.jsx(ye,{className:"h-4 w-4"})," Add Video"]}),e.jsxs("button",{onClick:()=>t("review"),className:"px-4 py-2 rounded-xl bg-muted text-foreground text-sm font-semibold hover:bg-muted/80 transition-colors flex items-center gap-2",children:[e.jsx(Ys,{className:"h-4 w-4"})," Review Queue (",s.pendingReview," pending)"]})]})]})},kn=()=>{const[t,s]=u.useState([]),[n,a]=u.useState([]),[r,i]=u.useState([]),[l,m]=u.useState(!0),[o,c]=u.useState(""),[x,g]=u.useState(""),[h,b]=u.useState(""),[j,f]=u.useState(""),[d,C]=u.useState(0),[E,D]=u.useState(0),[k,O]=u.useState(!1),[T,p]=u.useState(!1),[_,M]=u.useState(null),[R,v]=u.useState(new Set),[P,N]=u.useState(""),[I,z]=u.useState(""),[A,B]=u.useState(!1),U=u.useCallback(async()=>{m(!0);let y=S.from("videos").select("*, channels(name, color)",{count:"exact"});o&&(y=y.ilike("title",`%${o}%`)),x&&(y=y.eq("channel_id",x)),h&&(y=y.eq("source",h)),j&&(y=y.eq("difficulty",j)),y=y.order("created_at",{ascending:!1}).range(d*Kt,(d+1)*Kt-1);const{data:W,count:V}=await y;s(W||[]),D(V||0),m(!1)},[o,x,h,j,d]);u.useEffect(()=>{U()},[U]),u.useEffect(()=>{S.from("channels").select("id, name, slug, color, video_count").order("name").then(({data:y})=>{y&&a(y)}),S.from("playlists").select("id, title").order("title").then(({data:y})=>{y&&i(y)})},[]);const $=Math.ceil(E/Kt),X=async y=>{if(!confirm("Delete this video? This cannot be undone."))return;const{error:W}=await S.from("videos").delete().eq("id",y);W?w.error(W.message):(w.success("Deleted"),U())},lt=y=>v(W=>{const V=new Set(W);return V.has(y)?V.delete(y):V.add(y),V}),L=()=>{R.size===t.length?v(new Set):v(new Set(t.map(y=>y.id)))},K=async()=>{var W;if(R.size===0){w.error("Select videos first");return}B(!0);const y=Array.from(R);if(P==="channel"&&I){const{error:V}=await S.from("videos").update({channel_id:I}).in("id",y);V?w.error(V.message):w.success(`Updated ${y.length} videos`)}else if(P==="difficulty"&&I){const{error:V}=await S.from("videos").update({difficulty:I}).in("id",y);V?w.error(V.message):w.success(`Updated ${y.length} videos`)}else if(P==="playlist"&&I){const{data:V}=await S.from("playlist_videos").select("position").eq("playlist_id",I).order("position",{ascending:!1}).limit(1);let Me=(((W=V==null?void 0:V[0])==null?void 0:W.position)??-1)+1;const we=y.map(oe=>({playlist_id:I,video_id:oe,position:Me++})),{error:me}=await S.from("playlist_videos").insert(we);me?w.error(me.message):w.success(`Added ${y.length} videos to playlist`)}else if(P==="delete"){if(!confirm(`Delete ${y.length} videos?`)){B(!1);return}const{error:V}=await S.from("videos").delete().in("id",y);V?w.error(V.message):w.success(`Deleted ${y.length} videos`)}B(!1),v(new Set),N(""),z(""),U()},[qe,Nt]=u.useState(new Set),[ue,ot]=u.useState(null),Ut=async y=>{Nt(W=>new Set(W).add(y));try{const{data:W,error:V}=await S.functions.invoke("academy-transcript",{body:{video_id:y}});if(V)throw V;if(!W.success)throw new Error(W.error||"Extraction failed");w.success(`Transcript extracted (${(W.transcript_length/1e3).toFixed(1)}k chars)`),U()}catch(W){w.error(W.message||"Transcript extraction failed"),U()}finally{Nt(W=>{const V=new Set(W);return V.delete(y),V})}},qt=async()=>{const{count:y}=await S.from("videos").select("*",{count:"exact",head:!0}
71).in("transcript_status",["pending","failed"]),W=y||0;if(W===0){w.info("No pending transcripts to extract");return}if(!confirm(`This will process ${W} videos. Continue?`))return;const{data:V}=await S.from("videos").select("id").in("transcript_status",["pending","failed"]).limit(500);if(!V||V.length===0)return;ot({running:!0,total:V.length,done:0,success:0,failed:0});const Me=5;let we=0,me=0;for(let oe=0;oe<V.length;oe+=Me){const De=V.slice(oe,oe+Me);(await Promise.allSettled(De.map(re=>S.functions.invoke("academy-transcript",{body:{video_id:re.id}})))).forEach(re=>{var Se;re.status==="fulfilled"&&((Se=re.value.data)!=null&&Se.success)?we++:me++}),ot({running:!0,total:V.length,done:oe+De.length,success:we,failed:me})}ot({running:!1,total:V.length,done:V.length,success:we,failed:me}),w.success(`Transcript extraction complete: ${we} succeeded, ${me} failed`),U()},[je,ct]=u.useState(new Set),[le,Ne]=u.useState(null),Ke=async y=>{ct(W=>new Set(W).add(y));try{const{data:W,error:V}=await S.functions.invoke("academy-rag-ingest",{body:{video_id:y}});if(V)throw V;if(!W.success)throw new Error(W.error||"Ingestion failed");w.success(`RAG ingested (${W.chunks_created} chunks)`),U()}catch(W){w.error(W.message||"RAG ingestion failed"),U()}finally{ct(W=>{const V=new Set(W);return V.delete(y),V})}},wt=async()=>{const{count:y}=await S.from("videos").select("*",{count:"exact",head:!0}).eq("transcript_status","ready").in("rag_status",["pending","failed"]);if((y||0)===0){w.info("No videos ready for RAG ingestion");return}const{data:V}=await S.from("videos").select("id, transcript_text").eq("transcript_status","ready").in("rag_status",["pending","failed"]).limit(500);if(!V||V.length===0)return;const we=V.reduce((re,Se)=>{var F;return re+(((F=Se.transcript_text)==null?void 0:F.length)||0)},0)/4,me=we/1e6*.02;if(!confirm(`This will process ${V.length} videos (~${(we/1e3).toFixed(0)}k tokens, est. $${me.toFixed(4)}). Continue?`))return;Ne({running:!0,total:V.length,done:0,success:0,failed:0});const oe=3;let De=0,ke=0;for(let re=0;re<V.length;re+=oe){const Se=V.slice(re,re+oe);(await Promise.allSettled(Se.map(J=>S.functions.invoke("academy-rag-ingest",{body:{video_id:J.id}})))).forEach(J=>{var Ee;J.status==="fulfilled"&&((Ee=J.value.data)!=null&&Ee.success)?De++:ke++}),Ne({running:!0,total:V.length,done:re+Se.length,success:De,failed:ke})}Ne({running:!1,total:V.length,done:V.length,success:De,failed:ke}),w.success(`RAG ingestion complete: ${De} succeeded, ${ke} failed`),U()};return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-6 flex-wrap gap-3",children:[e.jsx("h2",{className:"text-2xl font-extrabold text-foreground",children:"Videos"}),e.jsxs("div",{className:"flex gap-2 flex-wrap",children:[e.jsxs("button",{onClick:qt,disabled:ue==null?void 0:ue.running,className:"px-4 py-2 rounded-xl bg-muted text-foreground text-sm font-semibold hover:bg-muted/80 transition-colors flex items-center gap-2",children:[ue!=null&&ue.running?e.jsx(H,{className:"h-4 w-4 animate-spin"}):e.jsx(Dt,{className:"h-4 w-4"}),ue!=null&&ue.running?`Transcripts ${ue.done}/${ue.total}...`:"Extract All Pending"]}),e.jsxs("button",{onClick:wt,disabled:le==null?void 0:le.running,className:"px-4 py-2 rounded-xl bg-muted text-foreground text-sm font-semibold hover:bg-muted/80 transition-colors flex items-center gap-2",children:[le!=null&&le.running?e.jsx(H,{className:"h-4 w-4 animate-spin"}):e.jsx(We,{className:"h-4 w-4"}),le!=null&&le.running?`RAG ${le.done}/${le.total}...`:"Ingest All Ready"]}),e.jsxs("button",{onClick:()=>p(!0),className:"px-4 py-2 rounded-xl bg-muted text-foreground text-sm font-semibold hover:bg-muted/80 transition-colors flex items-center gap-2",children:[e.jsx(ss,{className:"h-4 w-4"})," Bulk Import"]}),e.jsxs("button",{onClick:()=>O(!0),className:"px-4 py-2 rounded-xl bg-primary text-primary-foreground text-sm font-semibold hover:opacity-90 transition-opacity flex items-center gap-2",children:[e.jsx(ye,{className:"h-4 w-4"})," Add Video"]})]})]}),e.jsxs("div",{className:"flex flex-wrap gap-3 mb-4",children:[e.jsxs("div",{className:"relative flex-1 min-w-[200px]",children:[e.jsx($t,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(q,{placeholder:"Search title...",value:o,onChange:y=>{c(y.target.value),C(0)},className:"pl-9"})]}),e.jsxs("select",{value:x,onChange:y=>{g(y.target.value),C(0)},className:"px-3 py-2 rounded-xl border bg-background text-sm",children:[e.jsx("option",{value:"",children:"All Channels"}),n.map(y=>e.jsx("option",{value:y.id,children:y.name},y.id))]}),e.jsxs("select",{value:h,onChange:y=>{b(y.target.value),C(0)},className:"px-3 py-2 rounded-xl border bg-background text-sm",children:[e.jsx("option",{value:"",children:"All Sources"}),e.jsx("option",{value:"curated",children:"Curated"}),e.jsx("option",{value:"aggregated",children:"Aggregated"}),e.jsx("option",{value:"original",children:"Original"})]}),e.jsxs("select",{value:j,onChange:y=>{f(y.target.value),C(0)},className:"px-3 py-2 rounded-xl border bg-background text-sm",children:[e.jsx("option",{value:"",children:"All Difficulty"}),pt.map(y=>e.jsx("option",{value:y,children:y},y))]})]}),R.size>0&&e.jsxs("div",{className:"flex items-center gap-3 mb-3 p-3 rounded-xl bg-primary/5 border border-primary/20",children:[e.jsxs("span",{className:"text-xs font-semibold text-foreground",children:[R.size," selected"]}),e.jsxs("select",{value:P,onChange:y=>{N(y.target.value),z("")},className:"px-2 py-1.5 rounded-lg border bg-background text-xs",children:[e.jsx("option",{value:"",children:"Bulk action..."}),e.jsx("option",{value:"channel",children:"Assign to Channel"}),e.jsx("option",{value:"playlist",children:"Add to Playlist"}),e.jsx("option",{value:"difficulty",children:"Set Difficulty"}),e.jsx("option",{value:"delete",children:"Delete"})]}),P==="channel"&&e.jsxs("select",{value:I,onChange:y=>z(y.target.value),className:"px-2 py-1.5 rounded-lg border bg-background text-xs",children:[e.jsx("option",{value:"",children:"Select channel..."}),n.map(y=>e.jsx("option",{value:y.id,children:y.name},y.id))]}),P==="playlist"&&e.jsxs("select",{value:I,onChange:y=>z(y.target.value),className:"px-2 py-1.5 rounded-lg border bg-background text-xs",children:[e.jsx("option",{value:"",children:"Select playlist..."}),r.map(y=>e.jsx("option",{value:y.id,children:y.title},y.id))]}),P==="difficulty"&&e.jsxs("select",{value:I,onChange:y=>z(y.target.value),className:"px-2 py-1.5 rounded-lg border bg-background text-xs capitalize",children:[e.jsx("option",{value:"",children:"Select difficulty..."}),pt.map(y=>e.jsx("option",{value:y,children:y},y))]}),e.jsxs("button",{onClick:K,disabled:A||!P||P!=="delete"&&!I,className:"px-3 py-1.5 rounded-lg bg-primary text-primary-foreground text-xs font-semibold disabled:opacity-50 flex items-center gap-1.5",children:[A?e.jsx(H,{className:"h-3 w-3 animate-spin"}):e.jsx(he,{className:"h-3 w-3"}),"Apply"]}),e.jsx("button",{onClick:()=>{v(new Set),N("")},className:"text-xs text-muted-foreground hover:text-foreground ml-auto",children:"Clear"})]}),e.jsxs("div",{className:"academy-card overflow-hidden",children:[e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b bg-muted/30",children:[e.jsx("th",{className:"w-10 p-3",children:e.jsx("input",{type:"checkbox",checked:t.length>0&&R.size===t.length,onChange:L,className:"rounded"})}),e.jsx("th",{className:"text-left p-3 text-xs font-bold text-muted-foreground uppercase tracking-wider",children:"Video"}),e.jsx("th",{className:"text-left p-3 text-xs font-bold text-muted-foreground uppercase tracking-wider",children:"Channel"}),e.jsx("th",{className:"text-left p-3 text-xs font-bold text-muted-foreground uppercase tracking-wider",children:"Difficulty"}),e.jsx("th",{className:"text-left p-3 text-xs font-bold text-muted-foreground uppercase tracking-wider",children:"Source"}),e.jsx("th",{className:"text-left p-3 text-xs font-bold text-muted-foreground uppercase tracking-wider",children:"Transcript"}),e.jsx("th",{className:"text-left p-3 text-xs font-bold text-muted-foreground uppercase tracking-wider",children:"RAG"}),e.jsx("th",{className:"text-right p-3 text-xs font-bold text-muted-foreground uppercase tracking-wider",children:"Views"}),e.jsx("th",{className:"text-right p-3 text-xs font-bold text-muted-foreground uppercase tracking-wider",children:"Actions"})]})}),e.jsx("tbody",{children:l?Array.from({length:5}).map((y,W)=>e.jsx("tr",{className:"border-b",children:e.jsx("td",{colSpan:9,className:"p-3",children:e.jsx("div",{className:"h-10 rounded skeleton-shimmer"})})},W)):t.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:9,className:"p-8 text-center text-muted-foreground",children:"No videos found"})}):t.map(y=>{var W;return e.jsxs("tr",{className:`border-b hover:bg-muted/20 transition-colors ${R.has(y.id)?"bg-primary/5":""}`,children:[e.jsx("td",{className:"p-3",children:e.jsx("input",{type:"checkbox",checked:R.has(y.id),onChange:()=>lt(y.id),className:"rounded"})}),e.jsx("td",{className:"p-3",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-16 h-9 rounded-md overflow-hidden shrink-0 bg-muted flex items-center justify-center",children:y.thumbnail_url?e.jsx("img",{src:y.thumbnail_url,alt:"",className:"w-full h-full object-cover"}):e.jsx(ns,{className:"h-4 w-4 text-muted-foreground"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"font-semibold text-foreground line-clamp-1 text-xs",children:y.title}),e.jsx("p",{className:"text-[10px] text-muted-foreground",children:y.instructor||"—"})]})]})}),e.jsx("td",{className:"p-3",children:y.channels?e.jsx("span",{className:"text-[11px] font-medium px-2 py-0.5 rounded-full",style:{background:`${y.channels.color}15`,color:y.channels.color},children:y.channels.name}):e.jsx("span",{className:"text-muted-foreground text-xs",children:"—"})}),e.jsx("td",{className:"p-3 text-xs capitalize",children:y.difficulty||"—"}),e.jsx("td",{className:"p-3 text-xs capitalize",children:y.source||"—"}),e.jsx("td",{className:"p-3",children:e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(ts,{status:y.transcript_status,charCount:(W=y.transcript_text)==null?void 0:W.length}),(y.transcript_status==="pending"||y.transcript_status==="failed"||!y.transcript_status)&&e.jsx("button",{onClick:()=>Ut(y.id),disabled:qe.has(y.id),className:"p-1 rounded hover:bg-muted transition-colors",title:y.transcript_status==="failed"?"Retry extraction":"Extract transcript",children:qe.has(y.id)?e.jsx(H,{className:"h-3 w-3 animate-spin text-blue-500"}):y.transcript_status==="failed"?e.jsx(Jt,{className:"h-3 w-3 text-destructive"}):e.jsx(Dt,{className:"h-3 w-3 text-muted-foreground"})})]})}),e.jsx("td",{className:"p-3",children:e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(ts,{status:y.rag_status||"pending",countLabel:y.rag_status==="ingested"?`${y.rag_chunks_count||0} chunks`:void 0}),y.transcript_status==="ready"&&(y.rag_status==="pending"||y.rag_status==="failed"||!y.rag_status)&&e.jsx("button",{onClick:()=>Ke(y.id),disabled:je.has(y.id),className:"p-1 rounded hover:bg-muted transition-colors",title:"Ingest RAG",children:je.has(y.id)?e.jsx(H,{className:"h-3 w-3 animate-spin text-blue-500"}):e.jsx(We,{className:"h-3 w-3 text-muted-foreground"})}),y.rag_status==="ingested"&&e.jsx("button",{onClick:()=>Ke(y.id),disabled:je.has(y.id),className:"p-1 rounded hover:bg-muted transition-colors",title:"Re-ingest",children:je.has(y.id)?e.jsx(H,{className:"h-3 w-3 animate-spin text-blue-500"}):e.jsx(Jt,{className:"h-3 w-3 text-muted-foreground"})})]})}),e.jsx("td",{className:"p-3 text-right text-xs text-muted-foreground",children:y.view_count||0}),e.jsx("td",{className:"p-3",children:e.jsxs("div",{className:"flex items-center gap-1 justify-end",children:[e.jsx("button",{onClick:()=>M(y),className:"p-1.5 rounded-lg hover:bg-muted transition-colors",children:e.jsx(Ue,{className:"h-3.5 w-3.5 text-muted-foreground"})}),e.jsx("a",{href:y.youtube_url,target:"_blank",rel:"noopener noreferrer",className:"p-1.5 rounded-lg hover:bg-muted transition-colors",children:e.jsx(Mt,{className:"h-3.5 w-3.5 text-muted-foreground"})}),e.jsx("button",{onClick:()=>
71X(y.id),className:"p-1.5 rounded-lg hover:bg-destructive/10 transition-colors",children:e.jsx(ze,{className:"h-3.5 w-3.5 text-destructive"})})]})})]},y.id)})})]})}),$>1&&e.jsxs("div",{className:"flex items-center justify-between p-3 border-t bg-muted/20",children:[e.jsxs("p",{className:"text-xs text-muted-foreground",children:[E," videos · Page ",d+1," of ",$]}),e.jsxs("div",{className:"flex gap-1",children:[e.jsx("button",{disabled:d===0,onClick:()=>C(y=>y-1),className:"p-1.5 rounded-lg hover:bg-muted disabled:opacity-30 transition-colors",children:e.jsx(Ts,{className:"h-4 w-4"})}),e.jsx("button",{disabled:d>=$-1,onClick:()=>C(y=>y+1),className:"p-1.5 rounded-lg hover:bg-muted disabled:opacity-30 transition-colors",children:e.jsx(Ps,{className:"h-4 w-4"})})]})]})]}),e.jsx(_n,{open:k,onClose:()=>O(!1),channels:n,onSuccess:U}),e.jsx(Cn,{open:T,onClose:()=>p(!1),channels:n,onSuccess:U}),_&&e.jsx(Sn,{video:_,channels:n,onClose:()=>M(null),onSuccess:U})]})},ts=({status:t,charCount:s,countLabel:n})=>{const a=t||"pending",r={pending:"bg-amber-500/10 text-amber-600",processing:"bg-blue-500/10 text-blue-500",ready:"bg-emerald-500/10 text-emerald-600",ingested:"bg-emerald-500/10 text-emerald-600",completed:"bg-emerald-500/10 text-emerald-600",done:"bg-emerald-500/10 text-emerald-600",failed:"bg-destructive/10 text-destructive",error:"bg-destructive/10 text-destructive"};return e.jsxs("span",{className:`text-[10px] font-semibold px-2 py-0.5 rounded-full inline-flex items-center gap-1 ${r[a]||"bg-muted text-muted-foreground"}`,children:[a==="processing"&&e.jsx(H,{className:"h-2.5 w-2.5 animate-spin"}),a,n&&e.jsxs("span",{className:"text-[9px] opacity-70",children:["(",n,")"]}),!n&&a==="ready"&&s!=null&&e.jsxs("span",{className:"text-[9px] opacity-70",children:["(",(s/1e3).toFixed(1),"k)"]})]})},_n=({open:t,onClose:s,channels:n,onSuccess:a})=>{const[r,i]=u.useState(1),[l,m]=u.useState(""),[o,c]=u.useState(!1),[x,g]=u.useState(null),[h,b]=u.useState({channelId:"",difficulty:"intermediate",multiplier:1,tags:"",isFree:!0,isFeatured:!1,instructor:"",description:""}),[j,f]=u.useState(!1),d=D=>{const k=D.match(/(?:v=|\/embed\/|youtu\.be\/|\/v\/|\/e\/|watch\?.*v=)([^&\s?#]+)/);return(k==null?void 0:k[1])||""},C=async()=>{if(!d(l)){w.error("Invalid YouTube URL");return}c(!0);try{const{data:k,error:O}=await S.functions.invoke("academy-youtube-import",{body:{youtube_url:l}});if(O)throw O;if(k.error)throw new Error(k.error);g({title:k.title,thumbnail:k.thumbnail_url,youtubeId:k.youtube_id,duration:k.duration_seconds||0,instructor:k.instructor||"",description:k.description||""}),b(T=>({...T,instructor:k.instructor||"",description:(k.description||"").slice(0,500)})),i(2)}catch(k){w.error(k.message||"Could not fetch video metadata")}finally{c(!1)}},E=async()=>{if(!x)return;f(!0);const{data:D,error:k}=await S.from("videos").insert({title:x.title,youtube_id:x.youtubeId,youtube_url:`https://www.youtube.com/watch?v=${x.youtubeId}`,thumbnail_url:x.thumbnail,channel_id:h.channelId||null,difficulty:h.difficulty,time_savings_multiplier:h.multiplier,tags:h.tags?h.tags.split(",").map(O=>O.trim()).filter(Boolean):[],is_free:h.isFree,is_featured:h.isFeatured,instructor:h.instructor||null,description:h.description||null,source:"curated",duration_seconds:x.duration||null}).select("id").single();f(!1),k?w.error(k.message):(w.success("Video added!"),a(),s(),i(1),m(""),g(null),D!=null&&D.id&&setTimeout(()=>{S.functions.invoke("academy-transcript",{body:{video_id:D.id}}).then(({data:O})=>{O!=null&&O.success&&w.success("Transcript auto-extracted successfully")}).catch(()=>{})},5e3))};return e.jsx(pe,{open:t,onOpenChange:D=>{D||s()},children:e.jsxs(fe,{className:"max-w-lg",children:[e.jsx(ge,{children:e.jsx(be,{children:"Add Video"})}),r===1&&e.jsxs("div",{className:"space-y-4",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Paste a YouTube URL to get started"}),e.jsx(q,{placeholder:"https://youtube.com/watch?v=...",value:l,onChange:D=>m(D.target.value)}),x&&e.jsxs("div",{className:"flex items-center gap-3 p-3 rounded-xl bg-muted/50",children:[e.jsx("img",{src:x.thumbnail,alt:"",className:"w-24 h-14 roun
71ded-lg object-cover"}),e.jsx("p",{className:"text-sm font-semibold text-foreground line-clamp-2",children:x.title})]}),e.jsxs("button",{onClick:C,disabled:!l||o,className:"w-full py-2.5 rounded-xl bg-primary text-primary-foreground text-sm font-semibold disabled:opacity-50 flex items-center justify-center gap-2",children:[o?e.jsx(H,{className:"h-4 w-4 animate-spin"}):e.jsx($t,{className:"h-4 w-4"}),"Fetch Metadata"]})]}),r===2&&x&&e.jsxs("div",{className:"space-y-3 max-h-[60vh] overflow-y-auto pr-1",children:[e.jsxs("div",{className:"flex items-center gap-3 p-3 rounded-xl bg-muted/50",children:[e.jsx("img",{src:x.thumbnail,alt:"",className:"w-20 h-12 rounded-lg object-cover"}),e.jsx("p",{className:"text-xs font-semibold text-foreground line-clamp-2",children:x.title})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-xs font-bold text-muted-foreground",children:"Channel"}),e.jsxs("select",{value:h.channelId,onChange:D=>b(k=>({...k,channelId:D.target.value})),className:"w-full mt-1 px-3 py-2 rounded-xl border bg-background text-sm",children:[e.jsx("option",{value:"",children:"Select channel..."}),n.map(D=>e.jsx("option",{value:D.id,children:D.name},D.id))]})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-xs font-bold text-muted-foreground",children:"Difficulty"}),e.jsx("div",{className:"flex gap-2 mt-1",children:pt.map(D=>e.jsx("button",{onClick:()=>b(k=>({...k,difficulty:D})),className:`px-3 py-1.5 rounded-lg text-xs font-semibold capitalize transition-colors ${h.difficulty===D?"bg-primary text-primary-foreground":"bg-muted text-muted-foreground hover:bg-muted/80"}`,children:D},D))})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-xs font-bold text-muted-foreground",children:"Time-Savings Multiplier"}),e.jsx(q,{type:"number",min:1,max:50,value:h.multiplier,onChange:D=>b(k=>({...k,multiplier:parseInt(D.target.value)||1})),className:"mt-1"})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-xs font-bold text-muted-foreground",children:"Instructor"}),e.jsx(q,{value:h.instructor,onChange:D=>b(k=>({...k,instructor:D.target.value})),className:"mt-1"})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-xs font-bold text-muted-foreground",children:"Tags (comma-separated)"}),e.jsx(q,{value:h.tags,onChange:D=>b(k=>({...k,tags:D.target.value})),className:"mt-1",placeholder:"ai, automation, beginner"})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-xs font-bold text-muted-foreground",children:"Description"}),e.jsx(Te,{value:h.description,onChange:D=>b(k=>({...k,description:D.target.value})),rows:2,className:"mt-1"})]}),e.jsxs("div",{className:"flex gap-4",children:[e.jsxs("label",{className:"flex items-center gap-2 text-sm",children:[e.jsx("input",{type:"checkbox",checked:h.isFree,onChange:D=>b(k=>({...k,isFree:D.target.checked})),className:"rounded"}),"Free"]}),e.jsxs("label",{className:"flex items-center gap-2 text-sm",children:[e.jsx("input",{type:"checkbox",checked:h.isFeatured,onChange:D=>b(k=>({...k,isFeatured:D.target.checked})),className:"rounded"}),"Featured"]})]}),e.jsxs("div",{className:"flex gap-2 pt-2",children:[e.jsx("button",{onClick:()=>i(1),className:"px-4 py-2 rounded-xl text-sm text-muted-foreground hover:text-foreground transition-colors",children:"Back"}),e.jsxs("button",{onClick:E,disabled:j,className:"flex-1 py-2.5 rounded-xl bg-primary text-primary-foreground text-sm font-semibold disabled:opacity-50 flex items-center justify-center gap-2",children:[j?e.jsx(H,{className:"h-4 w-4 animate-spin"}):e.jsx(he,{className:"h-4 w-4"}),"Add Video"]})]})]})]})})},Sn=({video:t,channels:s,onClose:n,onSuccess:a})=>{const[r,i]=u.useState("details"),[l,m]=u.useState({title:t.title,channelId:t.channel_id||"",difficulty:t.difficulty||"intermediate",multiplier:t.time_savings_multiplier||1,tags:(t.tags||[]).join(", "),isFree:t.is_free??!0,isFeatured:t.is_featured??!1,instructor:t.instructor||"",description:t.description||""}),[o,c]=u.useState(!1),[x,g]=u.useState(!1),[h,b]=u.useState(t.transcript_text||""),[j,f]=u.useState(t.transcript_status||"pending"),d=async()=>{c(!0);const{error:k}=await S.from("videos").update({title:l.title,channel_id:l.channelId||null,difficulty:l.difficulty,time_savings_multiplier:l.multiplier,tags:l.tags?l.tags.split(",").map(O=>
71O.trim()).filter(Boolean):[],is_free:l.isFree,is_featured:l.isFeatured,instructor:l.instructor||null,description:l.description||null}).eq("id",t.id);c(!1),k?w.error(k.message):(w.success("Updated"),a(),n())},C=async()=>{g(!0),f("processing");try{const{data:k,error:O}=await S.functions.invoke("academy-transcript",{body:{video_id:t.id}});if(O)throw O;if(!k.success)throw new Error(k.error||"Failed");const{data:T}=await S.from("videos").select("transcript_text, transcript_status").eq("id",t.id).single();b((T==null?void 0:T.transcript_text)||""),f((T==null?void 0:T.transcript_status)||"ready"),w.success("Transcript extracted!"),a()}catch(k){f("failed"),w.error(k.message||"Extraction failed")}finally{g(!1)}},E=h?h.split(/\s+/).filter(Boolean).length:0,D=(h==null?void 0:h.length)||0;return e.jsx(pe,{open:!0,onOpenChange:k=>{k||n()},children:e.jsxs(fe,{className:"max-w-2xl max-h-[85vh] overflow-hidden flex flex-col",children:[e.jsx(ge,{children:e.jsx(be,{children:"Edit Video"})}),e.jsxs(ft,{value:r,onValueChange:i,className:"flex-1 overflow-hidden flex flex-col",children:[e.jsxs(gt,{className:"grid w-full grid-cols-2",children:[e.jsx(te,{value:"details",children:"Details"}),e.jsxs(te,{value:"transcript",className:"flex items-center gap-1.5",children:[e.jsx(Dt,{className:"h-3.5 w-3.5"}),"Transcript",e.jsx(ts,{status:j})]})]}),e.jsxs(se,{value:"details",className:"flex-1 overflow-y-auto pr-1 space-y-3 mt-3",children:[e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-xs font-bold text-muted-foreground",children:"Title"}),e.jsx(q,{value:l.title,onChange:k=>m(O=>({...O,title:k.target.value})),className:"mt-1"})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-xs font-bold text-muted-foreground",children:"Channel"}),e.jsxs("select",{value:l.channelId,onChange:k=>m(O=>({...O,channelId:k.target.value})),className:"w-full mt-1 px-3 py-2 rounded-xl border bg-background text-sm",children:[e.jsx("option",{value:"",children:"None"}),s.map(k=>e.jsx("option",{value:k.id,children:k.name},k.id))]})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-xs font-bold text-muted-foreground",children:"Difficulty"}),e.jsx("div",{className:"flex gap-2 mt-1",children:pt.map(k=>e.jsx("button",{onClick:()=>m(O=>({...O,difficulty:k})),className:`px-3 py-1.5 rounded-lg text-xs font-semibold capitalize transition-colors ${l.difficulty===k?"bg-primary text-primary-foreground":"bg-muted text-muted-foreground"}`,children:k},k))})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-xs font-bold text-muted-foreground",children:"Time-Savings Multiplier"}),e.jsx(q,{type:"number",min:1,max:50,value:l.multiplier,onChange:k=>m(O=>({...O,multiplier:parseInt(k.target.value)||1})),className:"mt-1"})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-xs font-bold text-muted-foreground",children:"Instructor"}),e.jsx(q,{value:l.instructor,onChange:k=>m(O=>({...O,instructor:k.target.value})),className:"mt-1"})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-xs font-bold text-muted-foreground",children:"Tags"}),e.jsx(q,{value:l.tags,onChange:k=>m(O=>({...O,tags:k.target.value})),className:"mt-1"})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-xs font-bold text-muted-foreground",children:"Description"}),e.jsx(Te,{value:l.description,onChange:k=>m(O=>({...O,description:k.target.value})),rows:2,className:"mt-1"})]}),e.jsxs("div",{className:"flex gap-4",children:[e.jsxs("label",{className:"flex items-center gap-2 text-sm",children:[e.jsx("input",{type:"checkbox",checked:l.isFree,onChange:k=>m(O=>({...O,isFree:k.target.checked})),className:"rounded"})," Free"]}),e.jsxs("label",{className:"flex items-center gap-2 text-sm",children:[e.jsx("input",{type:"checkbox",checked:l.isFeatured,onChange:k=>m(O=>({...O,isFeatured:k.target.checked})),className:"rounded"})," Featured"]})]}),e.jsxs("div",{className:"flex gap-2 pt-2",children:[e.jsx("button",{onClick:n,className:"px-4 py-2 rounded-xl text-sm text-muted-foreground hover:text-foreground transition-colors",children:"Cancel"}),e.jsxs("button",{onClick:d,disabled:o,className:"flex-1 py-2.5 rounded-xl bg-primary text-primary-foreground text-sm font-semibold disabled:opacity-50 flex items-center justify-center gap-2",children:[o?e.jsx(H,{className:"h-4 w-4 animate-spin"}):e.jsx(he,{className:"h-4 w-4"}),"Save Changes"]})]})]}),e.jsxs(se,{value:"transcript",className:"flex-1 overflow-hidden flex flex-col mt-3",children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsx("div",{className:"flex items-center gap-3 text-xs text-muted-foreground",children:h&&e.jsxs(e.Fragment,{children:[e.jsxs("span",{children:[E.toLocaleStr
71ing()," words"]}),e.jsx("span",{children:"·"}),e.jsxs("span",{children:[D.toLocaleString()," chars"]})]})}),e.jsxs("button",{onClick:C,disabled:x,className:"px-3 py-1.5 rounded-lg bg-primary text-primary-foreground text-xs font-semibold disabled:opacity-50 flex items-center gap-1.5",children:[x?e.jsx(H,{className:"h-3 w-3 animate-spin"}):e.jsx(Jt,{className:"h-3 w-3"}),h?"Re-extract":"Extract Transcript"]})]}),h?e.jsx("div",{className:"flex-1 overflow-y-auto rounded-xl border bg-muted/30 p-4 font-mono text-xs leading-relaxed whitespace-pre-wrap",children:h.split(`
72`).map((k,O)=>{const T=k.match(/^\[(\d{2}:\d{2})\]/);return T?e.jsxs("div",{children:[e.jsxs("span",{className:"text-primary font-semibold",children:["[",T[1],"]"]}),k.slice(T[0].length)]},O):e.jsx("div",{children:k},O)})}):e.jsx("div",{className:"flex-1 flex items-center justify-center text-muted-foreground text-sm",children:j==="processing"?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(H,{className:"h-4 w-4 animate-spin"})," Extracting transcript..."]}):e.jsx("p",{children:'No transcript available. Click "Extract Transcript" to generate one.'})})]})]})]})})},Cn=({open:t,onClose:s,channels:n,onSuccess:a})=>{const[r,i]=u.useState(""),[l,m]=u.useState(!1),[o,c]=u.useState([]),[x,g]=u.useState(""),[h,b]=u.useState("intermediate"),[j,f]=u.useState(!1),d=async()=>{if(r){m(!0);try{const{data:T,error:p}=await S.functions.invoke("academy-playlist-import",{body:{playlist_url:r}});if(p)throw p;if(T.error)throw new Error(T.error);c((T.videos||[]).map(_=>({..._,selected:!0})))}catch(T){w.error(T.message||"Could not fetch playlist")}finally{m(!1)}}},C=T=>c(p=>p.map((_,M)=>M===T?{..._,selected:!_.selected}:_)),E=()=>{const T=o.every(p=>p.selected);c(p=>p.map(_=>({..._,selected:!T})))},D=async()=>{const T=o.filter(M=>M.selected);if(T.length===0){w.error("Select at least one video");return}f(!0);const p=T.map(M=>({title:M.title,youtube_id:M.youtube_id,youtube_url:`https://www.youtube.com/watch?v=${M.youtube_id}`,thumbnail_url:M.thumbnail_url,duration_seconds:M.duration_seconds||null,instructor:M.instructor||null,channel_id:x||null,difficulty:h,source:"curated",is_free:!0,time_savings_multiplier:1})),{error:_}=await S.from("videos").insert(p);f(!1),_?w.error(_.message):(w.success(`Imported ${T.length} videos!`),a(),s(),c([]),i(""))},k=T=>T?`${Math.floor(T/60)}:${String(T%60).padStart(2,"0")}`:"—",O=o.filter(T=>T.selected).length;return e.jsx(pe,{open:t,onOpenChange:T=>{T||s()},children:e.jsxs(fe,{className:"max-w-2xl max-h-[85vh] overflow-hidden flex flex-col",children:[e.jsx(ge,{children:e.jsx(be,{children:"Bulk Import from YouTube Playlist"})}),e.jsxs("div",{className:"flex-1 overflow-y-auto space-y-4 pr-1",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Paste a YouTube playlist URL to import all videos at once."}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(q,{placeholder:"https://youtube.com/playlist?list=...",value:r,onChange:T=>i(T.target.value),className:"flex-1"}),e.jsxs("button",{onClick:d,disabled:!r||l,className:"px-4 py-2 rounded-xl bg-primary text-primary-foreground text-sm font-semibold disabled:opacity-50 flex items-center gap-2 shrink-0",children:[l?e.jsx(H,{className:"h-4 w-4 animate-spin"}):e.jsx($t,{className:"h-4 w-4"}),"Fetch"]})]})]}),o.length>0&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("select",{value:x,onChange:T=>g(T.target.value),className:"px-3 py-2 rounded-xl border bg-background text-sm",children:[e.jsx("option",{value:"",children:"Assign channel..."}),n.map(T=>e.jsx("option",{value:T.id,children:T.name},T.id))]}),e.jsx("select",{value:h,onChange:T=>b(T.target.value),className:"px-3 py-2 rounded-xl border bg-background text-sm capitalize",children:pt.map(T=>e.jsx("option",{value:T,children:T},T))}),e.jsxs("span",{className:"text-xs text-muted-foreground ml-auto",children:[O,"/",o.length," selected"]})]}),e.jsx("div",{className:"border rounded-xl overflow-hidden",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b bg-muted/30",children:[e.jsx("th",{className:"w-10 p-2",children:e.jsx("input",{type:"checkbox",checked:o.every(T=>T.selected),onChange:E,className:"rounded"})}),e.jsx("th",{className:"text-left p-2 text-xs font-bold text-muted-foreground",children:"Video"}),e.jsx("th",{className:"text-right p-2 text-xs font-bold text-muted-foreground",children:"Duration"})]})}),e.jsx("tbody",{className:"max-h-60 overflow-y-auto",children:o.map((T,p)=>e.jsxs("tr",{className:`border-b transition-colors ${T.selected?"bg-primary/5":"opacity-50"}`,children:[e.jsx("td",{className:"p-2",children:e.jsx("input",{type:"checkbox",checked:T.selected,onChange:()=>C(p),className:"rounded"})}),e.jsx("td",{className:"p-2",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("img",{src:T.thumbnail_url,alt:"",className:"w-14 h-8 rounded object-cover shrink-0"}),e.jsx("span",{className:"text-xs font-medium line-clamp-1",children:T.title})]})}),e.jsx("td",{className:"p-2 text-right text-xs text-muted-foreground",children:k(T.duration_seconds)})]},T.youtube_id))})]})}),e.jsxs("button",{onClick:D,disabled:j||O===0,className:"w-full py-2.5 rounded-xl bg-primary text-primary-foreground text-sm font-semibold disabled:opacity-50 flex items-center justify-center gap-2",children:[j?e.jsx(H,{className:"h-4 w-4 animate-spin"}):e.jsx(he,{className:"h-4 w-4"}),"Import ",O," Videos"]})]})]})]})})};export{ii 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.