1import{c as G,g as se,d as H,e as k,r as h,j as e,I as y,a as _,B as j,aK as ie,h as ne,L as oe,U as P,aL as le,s as Y,b as w,_ as de,$ as ce,a0 as ue,a1 as me,a2 as Z,aq as he,X as xe}from"./index-Cpo6LK8b.js";import{u as z}from"./useQuery-BXLsLZGT.js";import{g as pe,u as ve,a as je,b as fe,c as be,e as ge,l as _e}from"./courses-admin.functions-DuUbCCDJ.js";import{u as ye,d as Ne,F as we}from"./lesson-media.functions-DzH8gy-S.js";import{g as te,l as Ce,u as Se}from"./course-landing.functions-_cZcjk-6.js";import{C as M,a as O}from"./card-O66kI7ep.js";import{D as $,a as B,b as K,c as V,d as Q}from"./dialog-Dt5DIcVY.js";import{T as J}from"./textarea-ZVrhoIi-.js";import{S as ee}from"./switch-CI6HtVb_.js";import{T as A}from"./trash-2-DeOtjVrL.js";import{P as I}from"./plus-BUNMnbYT.js";import{C as ke}from"./chevron-left-CVjoSaUT.js";import{P as ae}from"./pencil-Q8pPXulQ.js";import"./index-D-m-u33h.js";import"./index-pmVZdHky.js";import"./x-D4YgSkSt.js";const qe=G({method:"GET"}).handler(H("51b841935932637a9a65e836945b4bcb900e92d9675560d71cffd97fd1588738")),Le=G({method:"POST"}).middleware([se]).handler(H("6a61bd8d81928129fe27c4601864d236c4fe17a9d9ce2c618e01c2b7e8075e8a"));G({method:"POST"}
1).middleware([se]).handler(H("f5591a602ab943e70942933503844d36aa5acce81ebe54eb404dd793497af511"));const Fe={preview_video_url:"",learn_bullets:[],audience_for:[],audience_not_for:[],instructor_bio:{},faqs:[],guarantee_enabled:!1,guarantee_days:7,sticky_bar_enabled:!0,testimonial_ids:[]};function Te({courseId:s,value:d,onChange:u}){const f=k(te),m=k(Ce),{data:n}=z({queryKey:["course-landing-admin",s],queryFn:()=>f({data:{courseId:s}})}),{data:l}=z({queryKey:["admin-testimonials-all"],queryFn:()=>m()}),[b,x]=h.useState(Fe);h.useEffect(()=>{if(n){const{testimonials:i,...a}=n;x({...a,preview_video_url:a.preview_video_url??""})}},[n]);const N=d!==void 0&&u!==void 0,t=N?d:b,o=N?u:x;return e.jsx(M,{children:e.jsxs(O,{className:"p-5 space-y-8",children:[e.jsx("div",{className:"flex items-center justify-between",children:e.jsxs("div",{children:[e.jsx("h2",{className:"font-semibold",children:"Landing page content"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Controls what visitors see on the course sales page."})]})}),e.jsx(T,{title:"Preview video",desc:"60-second hook. YouTube or Vimeo URL.",children:e.jsx(y,{value:t.preview_video_url??"",onChange:i=>o({...t,preview_video_url:i.target.value}),placeholder:"https://youtu.be/..."})}),e.jsx(T,{title:"What you'll learn",desc:"Short bullet points (max 50).",children:e.jsx(W,{items:t.learn_bullets,onChange:i=>o({...t,learn_bullets:i}),placeholder:"e.g. Build winning Facebook ad creatives"})}),e.jsxs("div",{className:"grid gap-6 md:grid-cols-2",children:[e.jsx(T,{title:"Who this is for",children:e.jsx(W,{items:t.audience_for,onChange:i=>o({...t,audience_for:i}),placeholder:"Beginner marketers"})}),e.jsx(T,{title:"Not for",children:e.jsx(W,{items:t.audience_not_for,onChange:i=>o({...t,audience_not_for:i}),placeholder:"People who want overnight results"})})]}),e.jsxs(T,{title:"Instructor bio",children:[e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[e.jsxs("div",{children:[e.jsx(_,{children:"Name"}),e.jsx(y,{value:t.instructor_bio.name??"",onChange:i=>o({...t,instructor_bio:{...t.instructor_bio,name:i.target.value}})})]}),e.jsxs("div",{children:[e.jsx(_,{children:"Title"}),e.jsx(y,{value:t.instructor_bio.title??"",onChange:i=>o({...t,instructor_bio:{...t.instructor_bio,title:i.target.value}}),placeholder:"Performance Marketer"})]}),e.jsxs("div",{className:"sm:col-span-2",children:[e.jsx(_,{children:"Avatar URL"}),e.jsx(y,{value:t.instructor_bio.avatar_url??"",onChange:i=>o({...t,instructor_bio:{...t.instructor_bio,avatar_url:i.target.value}})})]}),e.jsxs("div",{className:"sm:col-span-2",children:[e.jsx(_,{children:"Bio"}),e.jsx(J,{rows:4,value:t.instructor_bio.bio??"",onChange:i=>o({...t,instructor_bio:{...t.instructor_bio,bio:i.target.value}})})]})]}),e.jsxs("div",{className:"mt-4",children:[e.jsx(_,{className:"text-xs",children:"Stats (years, ad spend, students taughtâ¦)"}),e.jsx(De,{items:t.instructor_bio.stats??[],onChange:i=>o({...t,instructor_bio:{...t.instructor_bio,stats:i}})})]})]}),e.jsx(T,{title:"FAQ",desc:"Per-course frequently asked questions.",children:e.jsxs("div",{className:"space-y-3",children:[t.faqs.map((i,a)=>e.jsxs("div",{className:"rounded-lg border border-border p-3 space-y-2",children:[e.jsx(y,{value:i.q,onChange:v=>{const C=[...t.faqs];C[a]={...i,q:v.target.value},o({...t,faqs:C})},placeholder:"Question"}),e.jsx(J,{rows:3,value:i.a,onChange:v=>{const C=[...t.faqs];C[a]={...i,a:v.target.value},o({...t,faqs:C})},placeholder:"Answer"}),e.jsxs(j,{type:"button",variant:"ghost",size:"sm",onClick:()=>o({...t,faqs:t.faqs.filter((v,C)=>C!==a)}),children:[e.jsx(A,{className:"h-4 w-4 text-destructive"})," Remove"]})]},a)),e.jsxs(j,{type:"button",size:"sm",variant:"outline",onClick:()=>o({...t,faqs:[...t.faqs,{q:"",a:""}]}),children:[e.jsx(I,{className:"mr-1 h-4 w-4"})," Add FAQ"]})]})}),e.jsx(T,{title:"Conversion features",children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between rounded-lg border border-border p-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-medium",children:"Money-back guarantee badge"}),e.jsx("div",{className:"text-xs text-muted-foreground",children:"Show a guarantee badge on the landing page."})]}),e.jsx(ee,{checked:t.guarantee_enabled,onCheckedChange:i=>o({...t,guarantee_enabled:i})})]}),t.guarantee_enabled&&e.jsxs("div",{className:"max-w-[200px]",children:[e.jsx(_,{children:"Guarantee days"}),e.jsx(y,{type:"number",min:1,max:365,value:t.guarantee_days,onChange:i=>o({...t,guarantee_days:Number(i.target.value)})})]}),e.jsxs("div",{className:"flex items-center justify-between rounded-lg border border-border p-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-medium",children:"Sticky buy bar (mobile)"}),e.jsx("div",{className:"text-xs text-muted-foreground",children:"Floating bar with price + enroll button as user scrolls."})]}),e.jsx(ee,{checked:t.sticky_bar_enabled,onCheckedChange:i=>o({...t,sticky_bar_enabled:i})})]})]})}),e.jsx(T,{title:"Featured testimonials",desc:"Only published testimonials appear publicly.",children:(l??[]).length===0?e.jsx("p",{className:"text-xs text-muted-foreground",children:"No testimonials created yet."}):e.jsx("div",{className:"space-y-2 max-h-72 overflow-y-auto pr-1",children:(l??[]).map(i=>{const a=t.testimonial_ids.includes(i.id);return e.jsxs("label",{className:"flex gap-3 rounded-lg border border-border p-3 text-sm cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:a,onChange:v=>{const C=v.target.checked?[...t.testimonial_ids,i.id]:t.testimonial_ids.filter(R=>R!==i.id);o({...t,testimonial_ids:C})}}),e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"font-medium flex items-center gap-2",children:[i.name,!i.is_published&&e.jsx("span",{className:"text-[10px] text-muted-foreground",children:"(unpublished)"})]}),e.jsx("div",{className:"text-xs text-muted-foreground line-clamp-2",children:i.content})]})]},i.id)})})})]})})}function T({title:s,desc:d,children:u}){return e.jsxs("div",{children:[e.jsxs("div",{className:"mb-2",children:[e.jsx("div",{className:"text-sm font-semibold",children:s}),d&&e.jsx("div",{className:"text-xs text-muted-foreground",children:d})]}),u]})}function W({items:s,onChange:d,placeholder:u}){return e.jsxs("div",{className:"space-y-2",children:[s.map((f,m)=>e.jsxs("div",{className:"flex gap-2",children:[e.jsx(y,{value:f,onChange:n=>{const l=[...s];l[m]=n.target.value,d(l)},placeholder:u}),e.jsx(j,{type:"button",variant:"ghost",size:"sm",onClick:()=>d(s.filter((n,l)=>l!==m)),children:e.jsx(A,{className:"h-4 w-4 text-destructive"})})]},m)),e.jsxs(j,{type:"button",variant:"outline",size:"sm",onClick:()=>d([...s,""]),children:[e.jsx(I,{className:"mr-1 h-4 w-4"})," Add"]})]})}function De({items:s,onChange:d}){return e.jsxs("div",{className:"space-y-2 mt-2",children:[s.map((u,f)=>e.jsxs("div",{className:"flex gap-2",children:[e.jsx(y,{value:u.value,placeholder:"$2M+",onChange:m=>{const n=[...s];n[f]={...u,value:m.target.value},d(n)}}),e.jsx(y,{value:u.label,placeholder:"Ad spend managed",onChange:m=>{const n=[...s];n[f]={...u,label:m.target.value},d(n)}}),e.jsx(j,{type:"button",variant:"ghost",size:"sm",onClick:()=>d(s.filter((m,n)=>n!==f)),children:e.jsx(A,{className:"h-4 w-4 text-destructive"})})]},f)),e.jsxs(j,{type:"button",variant:"outline",size:"sm",onClick:()=>d([...s,{label:"",value:""}]),children:[e.jsx(I,{className:"mr-1 h-4 w-4"})," Add stat"]})]})}function ss(){const{id:s}=ie.useParams(),d=k(pe),u=k(ve),f=k(je),m=k(fe),n=k(be),l=k(ge),b=k(Le),x=k(Se),N=k(te),t=ne(),{data:o,isLoading:i}=z({queryKey:["admin-course",s],queryFn:()=>d({data:{id:s}})}),{data:a}=z({queryKey:["course-landing-admin",s],queryFn:()=>N({data:{courseId:s}})}),{data:v}=z({queryKey:["course-prereqs",s],queryFn:()=>qe({data:{courseId:s}})}),[C,R]=h.useState(null),[U,E]=h.useState([]),[r,p]=h.useState(!1),[c,F]=h.useState(null),[L,X]=h.useState(!1);h.useEffect(()=>{o&&(R(o.course),p(!!o.course.sequential_lessons))},[o]),h.useEffect(()=>{v&&E(v.map(S=>S.required_course_id))},[v]),h.useEffect(()=>{if(a){const{testimonials:S,...g}=a;F({...g,preview_video_url:g.preview_video_url??""})}},[a]);const D=()=>{t.invalidateQueries({queryKey:["admin-course",s]}),t.invalidateQueries({queryKey:["course-prereqs",s]}),t.invalidateQueries({queryKey:["course-landing-admin",s]})};async function re(S){if(S.preventDefault(),!!C){X(!0);try{await u({data:{...C,id:s}}),await b({data:{courseId:s,requiredCourseIds:U}}),await Y.from("courses").update({sequential_lessons:r}).eq("id",s),c&&await x({data:{courseId:s,preview_video_url:c.preview_video_url?.trim()?c.preview_video_url.trim():null,learn_bullets:c.learn_bullets.filter(g=>g.trim()),audience_for:c.audience_for.filter(g=>g.trim()),audience_not_for:c.audience_not_for.filter(g=>g.trim()),instructor_bio:{name:c.instructor_bio.name||void 0,title:c.instructor_bio.title||void 0,bio:c.instructor_bio.bio||void 0,avatar_url:c.instructor_bio.avatar_url||void 0,stats:(c.instructor_bio.stats??[]).filter(g=>g.label.trim()&&g.value.trim())},faqs:c.faqs.filter(g=>g.q.trim()&&g.a.trim()),guarantee_enabled:c.guarantee_enabled,guarantee_days:Number(c.guarantee_days),sticky_bar_enabled:c.sticky_bar_enabled,testimonial_ids:c.testimonial_ids}}),w.success("Course saved successfully"),D()}catch(g){w.error(g?.message||"Failed to save")}finally{X(!1)}}}return i||!o||!C||!c?e.jsx("div",{className:"text-muted-foreground",children:"Loadingâ¦"}):e.jsxs("form",{onSubmit:re,className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx(j,{asChild:!0,variant:"ghost",size:"sm",className:"-ml-2",children:e.jsxs(oe,{to:"/admin/courses",children:[e.jsx(ke,{className:"mr-1 h-4 w-4"})," All courses"]})}),e.jsx("h1",{className:"font-display text-2xl font-bold mt-2",children:o.course.title})]}),e.jsxs(j,{type:"submit",disabled:L,className:"bg-gradient-primary text-primary-foreground",children:[L?e.jsx(P,{className:"mr-1 h-4 w-4 animate-spin"}):null,L?"Savingâ¦":"Save all changes"]})]}),e.jsx(M,{children:e.jsxs(O,{className:"p-5",children:[e.jsx("h2",{className:"font-semibold mb-3",children:"Course details"}),e.jsx(le,{initial:C,onSubmit:S=>R(S),submitting:!1,hideSubmitButton:!0})]})}),e.jsx(Pe,{courseId:s,value:U,onChange:E}),e.jsx(Me,{value:r,onChange:p}),e.jsx(Te,{courseId:s,value:c,onChange:F}),e.jsx(M,{children:e.jsxs(O,{className:"p-5",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsx("h2",{className:"font-semibold",children:"Curriculum"}),e.jsx(Ae,{courseId:s,onDone:D,upsertM:f})]}),o.modules.length===0&&e.jsx("p",{className:"text-sm text-muted-foreground py-4",children:"No modules yet. Add one to get started."}),e.jsx("div",{className:"space-y-4",children:o.modules.map(S=>{const g=o.lessons.filter(q=>q.module_id===S.id);return e.jsxs("div",{className:"rounded-lg border border-border bg-muted/30 p-4",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-medium",children:S.title}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:[g.length," lesson(s)"]})]}),e.jsxs("div",{className:"flex gap-1",children:[e.jsx(Re,{module:S,upsertM:f,onDone:D}),e.jsx(j,{variant:"ghost",size:"sm",onClick:()=>{confirm(`Delete module "${S.title}" and its lessons?`)&&m({data:{id:S.id}}).then(D)},children:e.jsx(A,{className:"h-4 w-4 text-destructive"})})]})]}),e.jsxs("div",{className:"mt-3 space-y-2",children:[g.map(q=>e.jsxs("div",{className:"flex items-center justify-between rounded-md bg-background px-3 py-2 text-sm",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"truncate font-medium",children:q.title}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:[q.youtube_video_id?`â¶ ${q.youtube_video_id}`:"no video"," ·"," ",Math.round(q.duration_seconds/60),"m",q.free_preview?" · free preview":""]})]}),e.jsxs("div",{className:"flex gap-1",children:[e.jsx(Ie,{lesson:q,upsertL:n,onDone:D}),e.jsx(j,{variant:"ghost",size:"sm",onClick:()=>{confirm(`Delete lesson "${q.title}"?`)&&l({data:{id:q.id}}).then(D)},children:e.jsx(A,{className:"h-4 w-4 text-destructive"})})]})]},q.id)),e.jsx(ze,{moduleId:S.id,nextSort:g.length,upsertL:n,onDone:D})]})]},S.id)})})]})})]})}function Ae({courseId:s,onDone:d,upsertM:u}
1){const[f,m]=h.useState(!1),[n,l]=h.useState("");return e.jsxs($,{open:f,onOpenChange:m,children:[e.jsx(B,{asChild:!0,children:e.jsxs(j,{size:"sm",variant:"outline",children:[e.jsx(I,{className:"mr-1 h-4 w-4"}),"Add module"]})}),e.jsxs(K,{children:[e.jsx(V,{children:e.jsx(Q,{children:"New module"})}),e.jsxs("form",{className:"space-y-3",onSubmit:async b=>{b.preventDefault();try{await u({data:{course_id:s,title:n,sort_order:0}}),w.success("Module added"),l(""),m(!1),d()}catch(x){w.error(x.message)}},children:[e.jsxs("div",{children:[e.jsx(_,{children:"Title"}),e.jsx(y,{value:n,onChange:b=>l(b.target.value),required:!0})]}),e.jsx(j,{type:"submit",children:"Save"})]})]})]})}function Re({module:s,onDone:d,upsertM:u}){const[f,m]=h.useState(!1),[n,l]=h.useState(s.title),[b,x]=h.useState(s.sort_order),[N,t]=h.useState(!1);return e.jsxs($,{open:f,onOpenChange:m,children:[e.jsx(B,{asChild:!0,children:e.jsx(j,{size:"sm",variant:"ghost",children:e.jsx(ae,{className:"h-4 w-4"})})}),e.jsxs(K,{children:[e.jsx(V,{children:e.jsx(Q,{children:"Edit module"})}),e.jsxs("form",{className:"space-y-3",onSubmit:async o=>{o.preventDefault(),t(!0);try{await u({data:{id:s.id,title:n,sort_order:Number(b)}}),w.success("Saved"),m(!1),d()}catch(i){w.error(i?.message||"Failed to save module")}finally{t(!1)}},children:[e.jsxs("div",{children:[e.jsx(_,{children:"Title"}),e.jsx(y,{value:n,onChange:o=>l(o.target.value),required:!0})]}),e.jsxs("div",{children:[e.jsx(_,{children:"Sort order"}),e.jsx(y,{type:"number",value:b,onChange:o=>x(Number(o.target.value))})]}),e.jsxs(j,{type:"submit",disabled:N,children:[N?e.jsx(P,{className:"mr-1 h-4 w-4 animate-spin"}):null,"Save"]})]})]})]})}function ze({moduleId:s,nextSort:d,onDone:u,upsertL:f}){const[m,n]=h.useState(!1),[l,b]=h.useState({title:"",youtube:"",duration_minutes:0,free_preview:!1});return e.jsxs($,{open:m,onOpenChange:n,children:[e.jsx(B,{asChild:!0,children:e.jsxs(j,{size:"sm",variant:"ghost",className:"w-full justify-start text-muted-foreground",children:[e.jsx(I,{className:"mr-1 h-4 w-4"})," Add lesson"]})}),e.jsxs(K,{children:[e.jsx(V,{children:e.jsx(Q,{children:"New lesson"})}),e.jsxs("form",{className:"space-y-3",onSubmit:async x=>{x.preventDefault();try{await f({data:{module_id:s,title:l.title,youtube:l.youtube,duration_seconds:Math.round(Number(l.duration_minutes)*60),free_preview:l.free_preview,sort_order:d}}),n(!1),u(),w.success("Lesson added")}catch(N){w.error(N.message)}},children:[e.jsxs("div",{children:[e.jsx(_,{children:"Title"}),e.jsx(y,{value:l.title,onChange:x=>b({...l,title:x.target.value}),required:!0})]}),e.jsxs("div",{children:[e.jsx(_,{children:"YouTube URL or ID"}),e.jsx(y,{value:l.youtube,onChange:x=>b({...l,youtube:x.target.value}),placeholder:"https://youtu.be/⦠or video ID"})]}),e.jsxs("div",{children:[e.jsx(_,{children:"Duration (minutes)"}),e.jsx(y,{type:"number",value:l.duration_minutes,onChange:x=>b({...l,duration_minutes:Number(x.target.value)})})]}),e.jsxs("label",{className:"flex items-center gap-2 text-sm",children:[e.jsx("input",{type:"checkbox",checked:l.free_preview,onChange:x=>b({...l,free_preview:x.target.checked})}),"Free preview (anyone can watch)"]}),e.jsx(j,{type:"submit",children:"Save"})]})]})]})}function Ie({lesson:s,onDone:d,upsertL:u}){const[f,m]=h.useState(!1),n=k(ye),l=k(Ne),b=h.useRef(null),x=h.useRef(null),[N,t]=h.useState(null),[o,i]=h.useState(!1),[a,v]=h.useState({title:s.title,youtube:s.youtube_video_id??"",duration_minutes:Math.round(s.duration_seconds/60),free_preview:s.free_preview,sort_order:s.sort_order,video_source:s.video_source??"youtube",video_path:s.video_path??null,resources:s.resources??[],notes:s.notes??""});async function C(r){t("video");try{const p=r.name.split(".").pop()||"mp4",c=`${s.id}/video-${Date.now()}.${p}`,{error:F}=await Y.storage.from("lesson-videos").upload(c,r,{cacheControl:"3600",upsert:!1,contentType:r.type});if(F)throw F;if(a.video_path)try{await l({data:{bucket:"lesson-videos",path:a.video_path}})}catch{}const L={...a,video_path:c,video_source:"upload"};v(L),await n({data:{lesson_id:s.id,video_source:"upload",video_path:c}}),w.success("Video uploaded")}catch(p){w.error(p.message||"Upload failed")}finally{t(null)}}async function R(){if(a.video_path&&confirm("Remove uploaded video?"))try{await l({data:{bucket:"lesson-videos",path:a.video_path}});const r={...a,video_path:null};v(r),await n({data:{lesson_id:s.id,video_path:null}}),w.success("Video removed")}catch(r){w.error(r.message)}}async function U(r){t("resource");try{const p=r.name.replace(/[^a-zA-Z0-9._-]+/g,"_"),c=`${s.id}/${Date.now()}-${p}`,{error:F}=await Y.storage.from("lesson-resources").upload(c,r,{cacheControl:"3600",upsert:!1,contentType:r.type});if(F)throw F;const L={...a,resources:[...a.resources,{name:r.name,path:c,size:r.size,type:r.type}]};v(L),await n({data:{lesson_id:s.id,resources:L.resources}}),w.success("Resource added")}catch(p){w.error(p.message||"Upload failed")}finally{t(null)}}async function E(r){const p=a.resources[r];if(confirm(`Remove "${p.name}"?`))try{await l({data:{bucket:"lesson-resources",path:p.path}});const c={...a,resources:a.resources.filter((F,L)=>L!==r)};v(c),await n({data:{lesson_id:s.id,resources:c.resources}})}catch(c){w.error(c.message)}}return e.jsxs($,{open:f,onOpenChange:m,children:[e.jsx(B,{asChild:!0,children:e.jsx(j,{size:"sm",variant:"ghost",children:e.jsx(ae,{className:"h-4 w-4"})})}),e.jsxs(K,{className:"max-w-2xl max-h-[90vh] overflow-y-auto",children:[e.jsx(V,{children:e.jsx(Q,{children:"Edit lesson"})}),e.jsxs("form",{className:"space-y-4",onSubmit:async r=>{r.preventDefault(),i(!0);try{await u({data:{id:s.id,module_id:s.module_id,title:a.title,youtube:a.video_source==="youtube"?a.youtube:"",duration_seconds:Math.round(Number(a.duration_minutes)*60),free_preview:a.free_preview,sort_order:Number(a.sort_order),notes:a.notes||null}}),await n({data:{lesson_id:s.id,video_source:a.video_source,video_path:a.video_source==="upload"?a.video_path:null}}),w.success("Saved"),m(!1),d()}catch(p){w.error(p?.message||"Failed to save lesson")}finally{i(!1)}},children:[e.jsxs("div",{children:[e.jsx(_,{children:"Title"}),e.jsx(y,{value:a.title,onChange:r=>v({...a,title:r.target.value})})]}),e.jsxs("div",{className:"rounded-lg border border-border p-3 space-y-3",children:[e.jsx(_,{children:"Video source"}),e.jsxs(de,{value:a.video_source,onValueChange:r=>v({...a,video_source:r}),children:[e.jsx(ce,{children:e.jsx(ue,{})}),e.jsxs(me,{children:[e.jsx(Z,{value:"youtube",children:"YouTube (embed)"}),e.jsx(Z,{value:"upload",children:"Uploaded video (more secure)"})]})]}),a.video_source==="youtube"?e.jsxs("div",{children:[e.jsx(_,{children:"YouTube URL or ID"}),e.jsx(y,{value:a.youtube,onChange:r=>v({...a,youtube:r.target.value}),placeholder:"https://youtu.be/â¦"})]}
1):e.jsxs("div",{className:"space-y-2",children:[a.video_path?e.jsxs("div",{className:"flex items-center justify-between rounded-md bg-muted/40 px-3 py-2 text-sm",children:[e.jsxs("span",{className:"truncate",children:["ð¹ ",a.video_path.split("/").pop()]}),e.jsx(j,{type:"button",size:"sm",variant:"ghost",onClick:R,children:e.jsx(A,{className:"h-4 w-4 text-destructive"})})]}):e.jsx("p",{className:"text-xs text-muted-foreground",children:"No video uploaded yet."}),e.jsx("input",{ref:b,type:"file",accept:"video/mp4,video/webm,video/quicktime",className:"hidden",onChange:r=>{const p=r.target.files?.[0];p&&C(p),r.target.value=""}}),e.jsxs(j,{type:"button",variant:"outline",size:"sm",disabled:N==="video",onClick:()=>b.current?.click(),children:[N==="video"?e.jsx(P,{className:"mr-1 h-4 w-4 animate-spin"}):e.jsx(he,{className:"mr-1 h-4 w-4"}),a.video_path?"Replace video":"Upload video"]})]})]}),e.jsxs("div",{className:"rounded-lg border border-border p-3 space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(_,{children:"Lesson resources (PDFs, files)"}),e.jsx("input",{ref:x,type:"file",className:"hidden",onChange:r=>{const p=r.target.files?.[0];p&&U(p),r.target.value=""}}),e.jsxs(j,{type:"button",variant:"outline",size:"sm",disabled:N==="resource",onClick:()=>x.current?.click(),children:[N==="resource"?e.jsx(P,{className:"mr-1 h-4 w-4 animate-spin"}):e.jsx(I,{className:"mr-1 h-4 w-4"}),"Add file"]})]}),a.resources.length===0?e.jsx("p",{className:"text-xs text-muted-foreground",children:"No resources attached."}):e.jsx("ul",{className:"space-y-1",children:a.resources.map((r,p)=>e.jsxs("li",{className:"flex items-center justify-between rounded-md bg-muted/40 px-3 py-2 text-sm",children:[e.jsxs("span",{className:"flex items-center gap-2 truncate",children:[e.jsx(we,{className:"h-4 w-4 shrink-0"}),r.name]}),e.jsx(j,{type:"button",size:"sm",variant:"ghost",onClick:()=>E(p),children:e.jsx(A,{className:"h-4 w-4 text-destructive"})})]},r.path))})]}),e.jsxs("div",{className:"rounded-lg border border-border p-3 space-y-2",children:[e.jsx(_,{children:"Notes, instructions, tips & links"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Shown to students under the video. Use it for instructions, tips & tricks, helpful links, etc."}),e.jsx(xe,{value:a.notes,onChange:r=>v({...a,notes:r}),placeholder:"Add instructions, tips, tricks, linksâ¦",minHeight:180})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx(_,{children:"Duration (min)"}),e.jsx(y,{type:"number",value:a.duration_minutes,onChange:r=>v({...a,duration_minutes:Number(r.target.value)})})]}),e.jsxs("div",{children:[e.jsx(_,{children:"Sort"}),e.jsx(y,{type:"number",value:a.sort_order,onChange:r=>v({...a,sort_order:Number(r.target.value)})})]})]}),e.jsxs("label",{className:"flex items-center gap-2 text-sm",children:[e.jsx("input",{type:"checkbox",checked:a.free_preview,onChange:r=>v({...a,free_preview:r.target.checked})}),"Free preview"]}),e.jsxs(j,{type:"submit",disabled:o||N!==null,children:[o?e.jsx(P,{className:"mr-1 h-4 w-4 animate-spin"}):null,"Save"]})]})]})]})}function Pe({courseId:s,value:d,onChange:u}){const f=k(_e),{data:m}=z({queryKey:["admin-courses-all"],queryFn:()=>f()});return e.jsx(M,{children:e.jsxs(O,{className:"p-5",children:[e.jsx("h2",{className:"font-semibold mb-1",children:"Prerequisites"}),e.jsx("p",{className:"text-xs text-muted-foreground mb-3",children:"Students must complete 90% of these courses before they can enroll here."}),e.jsx("div",{className:"space-y-2",children:(m??[]).filter(n=>n.id!==s).map(n=>{const l=d.includes(n.id);return e.jsxs("label",{className:"flex items-center gap-2 text-sm",children:[e.jsx("input",{type:"checkbox",checked:l,onChange:b=>{const x=b.target.checked?[...d,n.id]:d.filter(N=>N!==n.id);u(x)}}),n.title]},n.id)})})]})})}function Me({value:s,onChange:d}){return e.jsx(M,{children:e.jsxs(O,{className:"p-5",children:[e.jsx("h2",{className:"font-semibold mb-1",children:"Sequential lessons"}),e.jsx("p",{className:"text-xs text-muted-foreground mb-3",children:"When ON, students must complete each lesson before unlocking the next one. Free-preview lessons stay unlocked."}),e.jsxs("label",{className:"flex items-center gap-2 text-sm",children:[e.jsx("input",{type:"checkbox",checked:s,onChange:u=>d(u.target.checked)}),"Require lessons to be completed in order"]})]})})}export{ss as component};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.