PageSourceSearch

https://msastroacademy.com/assets/course-builder-Dsic-y4a.js

js msastroacademy.com collected 2026-09-24 14:49:09 UTC 92,558 bytes, 9 lines download raw bytes

1import{r,j as e,c as Bt}from"./react-vendor-DDlTsOEd.js";import{g as ge,aS as Ws,ax as At,aT as Ks,aD as ct,aw as fe,aU as Ne,ay as ue,aV as Vt,aW as Gs,aX as Ys,aY as Zs,az as re,aF as Xs,aB as Qs,aC as Js,aH as ea,aI as ta,aZ as sa,a_ as aa,j as dt,al as we,af as ra,K as W,R as na,s as la,J as B,F as de,A as Pe,l as Qe,ad as ae,f as oa,ae as ia,k as zt,v as ze,B as ut,d as le,X as mt,V as xt,ac as pt,y as Ke,z as Ge,D as Ye,E as Ze,G as O,a$ as ht,T as Je,b0 as ca,aR as da}from"./index-dMYrr1t8.js";import{A as ua,c as ma,F as Ht}from"./AdminLayout-C0t6TWD9.js";import{B as gt}from"./badge-CWfsDbmg.js";import{T as Ue}from"./textarea-DtKC4rYi.js";import{u as xa,S as $e}from"./switch-CEy2TkWe.js";import{D as ft,a as bt,b as yt,c as vt,d as qt}from"./dialog-CWLM8hAZ.js";import{h as pa,u as ha,d as ga,F as fa}from"./index-Cqcshn79.js";import{C as jt}from"./check-DVW38x0e.js";import{S as ba}from"./skeleton-DXQeB_cl.js";import{F as ya,B as va,M as Wt}from"./BulkFileUploader-BE60z7RV.js";import{U as Mt}from"./upload-Csh4KAbr.js";import{I as Me}from"./image-CrlXsVPe.js";import{C as et}from"./chevron-right-EYQmpmp2.js";import{L as ja}from"./layout-list-CFUpWT7n.js";import{P as tt}from"./plus-DSg0jD-f.js";import{P as Nt}from"./play-MFKEhHAF.js";import{P as st}from"./pen-T_C3rRV6.js";import{T as _t}from"./trash-2-BFoxcqPY.js";import"./megaphone-CG_Y22E9.js";import"./clipboard-check-H9MOfMyT.js";import"./database-BMcpOIuo.js";import"./tag-CsU2rQcC.js";import"./credit-card-CV_Lm4ZC.js";import"./circle-x-DRWcnEQU.js";const Na=[["path",{d:"M12 5v14",key:"s699le"}],["path",{d:"m19 12-7 7-7-7",key:"1idqje"}]],Dt=ge("arrow-down",Na);const wa=[["path",{d:"m5 12 7-7 7 7",key:"hav0vg"}],["path",{d:"M12 19V5",key:"x0mq9r"}]],Ft=ge("arrow-up",wa);const Sa=[["path",{d:"m16 18 6-6-6-6",key:"eg8j8"}],["path",{d:"m8 6-6 6 6 6",key:"ppft3o"}]],wt=ge("code",Sa);const Ca=[["path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z",key:"1rqfz7"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["circle",{cx:"10",cy:"12",r:"2",key:"737tya"}],["path",{d:"m20 17-1.296-1.296a2.41 2.41 0 0 0-3.408 0L9 22",key:"wt3hpn"}]],Ae=ge("file-image",Ca);const ka=[["circle",{cx:"9",cy:"12",r:"1",key:"1vctgf"}],["circle",{cx:"9",cy:"5",r:"1",key:"hp0tcf"}],["circle",{cx:"9",cy:"19",r:"1",key:"fkjjf6"}],["circle",{cx:"15",cy:"12",r:"1",key:"1tmaij"}],["circle",{cx:"15",cy:"5",r:"1",key:"19l28e"}],["circle",{cx:"15",cy:"19",r:"1",key:"f4zoj3"}]],$t=ge("grip-vertical",ka);const Ta=[["path",{d:"M9 17H7A5 5 0 0 1 7 7h2",key:"8i5ue5"}],["path",{d:"M15 7h2a5 5 0 1 1 0 10h-2",key:"1b9ql8"}],["line",{x1:"8",x2:"16",y1:"12",y2:"12",key:"1jonct"}]],St=ge("link-2",Ta);const Ia=[["path",{d:"M9 18V5l12-2v13",key:"1jmyc2"}],["circle",{cx:"6",cy:"18",r:"3",key:"fqmcym"}],["circle",{cx:"18",cy:"16",r:"3",key:"1hluhg"}]],ve=ge("music",Ia);const Pa=[["rect",{x:"14",y:"3",width:"5",height:"18",rx:"1",key:"kaeet6"}],["rect",{x:"5",y:"3",width:"5",height:"18",rx:"1",key:"1wsw3u"}]],Kt=ge("pause",Pa);const Ra=[["path",{d:"M11 4.702a.705.705 0 0 0-1.203-.498L6.413 7.587A1.4 1.4 0 0 1 5.416 8H3a1 1 0 0 0-1 1v6a1 1 0 0 0 1 1h2.416a1.4 1.4 0 0 1 .997.413l3.383 3.384A.705.705 0 0 0 11 19.298z",key:"uqj9uw"}],["path",{d:"M16 9a5 5 0 0 1 0 6",key:"1q6k2b"}],["path",{d:"M19.364 18.364a9 9 0 0 0 0-12.728",key:"ijwkga"}]],Ea=ge("volume-2",Ra);const La=[["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}],["line",{x1:"21",x2:"16.65",y1:"21",y2:"16.65",key:"13gj7c"}],["line",{x1:"11",x2:"11",y1:"8",y2:"14",key:"1vmskp"}],["line",{x1:"8",x2:"14",y1:"11",y2:"11",key:"durymu"}]],Ua=ge("zoom-in",La);function Ot(t,[s,a]){return Math.min(a,Math.max(s,t))}var Aa=[" ","Enter","ArrowUp","ArrowDown"],za=[" ","Enter"],Te="Select",[Ve,He,Ma]=Gs(Te),[Re]=Qs(Te,[Ma,Vt]),qe=Vt(),[_a,Se]=Re(Te),[Da,Fa]=Re(Te),Gt=t=>{const{__scopeSelect:s,children:a,open:n,defaultOpen:l,onOpenChange:m,value:d,defaultValue:c,onValueChange:o,dir:u,name:f,autoComplete:j,disabled:k,required:T,form:S}=t,h=qe(s),[y,N]=r.useState(null),[i,g]=r.useState(null),[R,E]=r.useState(!1),H=Ws(u),[P,x]=At({prop:n,defaultProp:l??!1,onChange:m,caller:Te}),[L,D]=At({prop:d,defaultProp:c,onChange:o,caller:Te}),q=r.useRef(null),Q=y?S||!!y.closest("form"):!0,[J,ee]=r.useState(new Set),K=Array.from(J).map(V=>V.props.value).join(";");return e.jsx(Ks,{...h,children:e.jsxs(_a,{required:T,scope:s,trigger:y,onTriggerChange:N,valueNode:i,onValueNodeChange:g,valueNodeHasChildren:R,onValueNodeHasChildrenChange:E,contentId:ct(),value:L,onValueChange:D,open:P,onOpenChange:x,dir:H,triggerPointerDownPosRef:q,disabled:k,children:[e.jsx(Ve.Provider,{scope:s,children:e.jsx(Da,{scope:t.__scopeSelect,onNativeOptionAdd:r.useCallback(V=>{ee(G=>new Set(G).add(V))},[]),onNativeOptionRemove:r.useCallback(V=>{ee(G=>{const Z=new Set(G);return Z.delete(V),Z})},[]),children:a})}
1),Q?e.jsxs(bs,{"aria-hidden":!0,required:T,tabIndex:-1,name:f,autoComplete:j,value:L,onChange:V=>D(V.target.value),disabled:k,form:S,children:[L===void 0?e.jsx("option",{value:""}):null,Array.from(J)]},K):null]})})};Gt.displayName=Te;var Yt="SelectTrigger",Zt=r.forwardRef((t,s)=>{const{__scopeSelect:a,disabled:n=!1,...l}=t,m=qe(a),d=Se(Yt,a),c=d.disabled||n,o=fe(s,d.onTriggerChange),u=He(a),f=r.useRef("touch"),[j,k,T]=vs(h=>{const y=u().filter(g=>!g.disabled),N=y.find(g=>g.value===d.value),i=js(y,h,N);i!==void 0&&d.onValueChange(i.value)}),S=h=>{c||(d.onOpenChange(!0),T()),h&&(d.triggerPointerDownPosRef.current={x:Math.round(h.pageX),y:Math.round(h.pageY)})};return e.jsx(Zs,{asChild:!0,...m,children:e.jsx(ue.button,{type:"button",role:"combobox","aria-controls":d.contentId,"aria-expanded":d.open,"aria-required":d.required,"aria-autocomplete":"none",dir:d.dir,"data-state":d.open?"open":"closed",disabled:c,"data-disabled":c?"":void 0,"data-placeholder":ys(d.value)?"":void 0,...l,ref:o,onClick:re(l.onClick,h=>{h.currentTarget.focus(),f.current!=="mouse"&&S(h)}),onPointerDown:re(l.onPointerDown,h=>{f.current=h.pointerType;const y=h.target;y.hasPointerCapture(h.pointerId)&&y.releasePointerCapture(h.pointerId),h.button===0&&h.ctrlKey===!1&&h.pointerType==="mouse"&&(S(h),h.preventDefault())}),onKeyDown:re(l.onKeyDown,h=>{const y=j.current!=="";!(h.ctrlKey||h.altKey||h.metaKey)&&h.key.length===1&&k(h.key),!(y&&h.key===" ")&&Aa.includes(h.key)&&(S(),h.preventDefault())})})})});Zt.displayName=Yt;var Xt="SelectValue",Qt=r.forwardRef((t,s)=>{const{__scopeSelect:a,className:n,style:l,children:m,placeholder:d="",...c}=t,o=Se(Xt,a),{onValueNodeHasChildrenChange:u}=o,f=m!==void 0,j=fe(s,o.onValueNodeChange);return Ne(()=>{u(f)},[u,f]),e.jsx(ue.span,{...c,ref:j,style:{pointerEvents:"none"},children:ys(o.value)?e.jsx(e.Fragment,{children:d}):m})});Qt.displayName=Xt;var $a="SelectIcon",Jt=r.forwardRef((t,s)=>{const{__scopeSelect:a,children:n,...l}=t;
1return e.jsx(ue.span,{"aria-hidden":!0,...l,ref:s,children:n||"▼"})});Jt.displayName=$a;var Oa="SelectPortal",es=t=>e.jsx(Xs,{asChild:!0,...t});es.displayName=Oa;var Ie="SelectContent",ts=r.forwardRef((t,s)=>{const a=Se(Ie,t.__scopeSelect),[n,l]=r.useState();if(Ne(()=>{l(new DocumentFragment)},[]),!a.open){const m=n;return m?Bt.createPortal(e.jsx(ss,{scope:t.__scopeSelect,children:e.jsx(Ve.Slot,{scope:t.__scopeSelect,children:e.jsx("div",{children:t.children})})}),m):null}return e.jsx(as,{...t,ref:s})});ts.displayName=Ie;var xe=10,[ss,Ce]=Re(Ie),Ba="SelectContentImpl",Va=ta("SelectContent.RemoveScroll"),as=r.forwardRef((t,s)=>{const{__scopeSelect:a,position:n="item-aligned",onCloseAutoFocus:l,onEscapeKeyDown:m,onPointerDownOutside:d,side:c,sideOffset:o,align:u,alignOffset:f,arrowPadding:j,collisionBoundary:k,collisionPadding:T,sticky:S,hideWhenDetached:h,avoidCollisions:y,...N}=t,i=Se(Ie,a),[g,R]=r.useState(null),[E,H]=r.useState(null),P=fe(s,v=>R(v)),[x,L]=r.useState(null),[D,q]=r.useState(null),Q=He(a),[J,ee]=r.useState(!1),K=r.useRef(!1);r.useEffect(()=>{if(g)return pa(g)},[g]),ha();const V=r.useCallback(v=>{const[F,...X]=Q().map(Y=>Y.ref.current),[z]=X.slice(-1),_=document.activeElement;for(const Y of v)if(Y===_||(Y?.scrollIntoView({block:"nearest"}),Y===F&&E&&(E.scrollTop=0),Y===z&&E&&(E.scrollTop=E.scrollHeight),Y?.focus(),document.activeElement!==_))return},[Q,E]),G=r.useCallback(()=>V([x,g]),[V,x,g]);r.useEffect(()=>{J&&G()},[J,G]);const{onOpenChange:Z,triggerPointerDownPosRef:w}=i;r.useEffect(()=>{if(g){let v={x:0,y:0};const F=z=>{v={x:Math.abs(Math.round(z.pageX)-(w.current?.x??0)),y:Math.abs(Math.round(z.pageY)-(w.current?.y??0))}},X=z=>{v.x<=10&&v.y<=10?z.preventDefault():g.contains(z.target)||Z(!1),document.removeEventListener("pointermove",F),w.current=null};return w.current!==null&&(document.addEventListener("pointermove",F),document.addEventListener("pointerup",X,{capture:!0,once:!0})),()=>{document.removeEventListener("pointermove",F),document.removeEventListener("pointerup",X,{capture:!0})}}},[g,Z,w]),r.useEffect(()=>{const v=()=>Z(!1);return window.addEventListener("blur",v),window.addEventListener("resize",v),()=>{window.removeEventListener("blur",v),window.removeEventListener("resize",v)}},[Z]);const[M,I]=vs(v=>{const F=Q().filter(_=>!_.disabled),X=F.find(_=>_.ref.current===document.activeElement),z=js(F,v,X);z&&setTimeout(()=>z.ref.current.focus())}),U=r.useCallback((v,F,X)=>{const z=!K.current&&!X;(i.value!==void 0&&i.value===F||z)&&(L(v),z&&(K.current=!0))},[i.value]),se=r.useCallback(()=>g?.focus(),[g]),b=r.useCallback((v,F,X)=>{const z=!K.current&&!X;(i.value!==void 0&&i.value===F||z)&&q(v)},[i.value]),A=n==="popper"?at:rs,ce=A===at?{side:c,sideOffset:o,align:u,alignOffset:f,arrowPadding:j,collisionBoundary:k,collisionPadding:T,sticky:S,hideWhenDetached:h,avoidCollisions:y}:{};return e.jsx(ss,{scope:a,content:g,viewport:E,onViewportChange:H,itemRefCallback:U,selectedItem:x,onItemLeave:se,itemTextRefCallback:b,focusSelectedItem:G,selectedItemText:D,position:n,isPositioned:J,searchRef:M,children:e.jsx(ga,{as:Va,allowPinchZoom:!0,children:e.jsx(fa,{asChild:!0,trapped:i.open,onMountAutoFocus:v=>{v.preventDefault()},onUnmountAutoFocus:re(l,v=>{i.trigger?.focus({preventScroll:!0}),v.preventDefault()}),children:e.jsx(ea,{asChild:!0,disableOutsidePointerEvents:!0,onEscapeKeyDown:m,onPointerDownOutside:d,onFocusOutside:v=>v.preventDefault(),onDismiss:()=>i.onOpenChange(!1),children:e.jsx(A,{role:"listbox",id:i.contentId,"data-state":i.open?"open":"closed",dir:i.dir,onContextMenu:v=>v.preventDefault(),...N,...ce,onPlaced:()=>ee(!0),ref:P,style:{display:"flex",flexDirection:"column",outline:"none",...N.style},onKeyDown:re(N.onKeyDown,v=>{const F=v.ctrlKey||v.altKey||v.metaKey;if(v.key==="Tab"&&v.preventDefault(),!F&&v.key.length===1&&I(v.key),["ArrowUp","ArrowDown","Home","End"].includes(v.key)){let z=Q().filter(_=>!_.disabled).map(_=>_.ref.current);if(["ArrowUp","End"].includes(v.key)&&(z=z.slice().reverse()),["ArrowUp","ArrowDown"].includes(v.key)){const _=v.target,Y=z.indexOf(_);z=z.slice(Y+1)}setTimeout(()=>V(z)),v.preventDefault()}})})})})})})});as.displayName=Ba;var Ha="SelectItemAlignedPosition",rs=r.forwardRef((t,s)=>{const{__scopeSelect:a,onPlaced:n,...l}=t,m=Se(Ie,a),d=Ce(Ie,a),[c,o]=r.useState(null),[u,f]=r.useState(null),j=fe(s,P=>f(P)),k=He(a),T=r.useRef(!1),S=r.useRef(!0),{viewport:h,selectedItem:y,selectedItemText:N,focusSelectedItem:i}=d,g=r.useCallback(()=>
1{if(m.trigger&&m.valueNode&&c&&u&&h&&y&&N){const P=m.trigger.getBoundingClientRect(),x=u.getBoundingClientRect(),L=m.valueNode.getBoundingClientRect(),D=N.getBoundingClientRect();if(m.dir!=="rtl"){const _=D.left-x.left,Y=L.left-_,C=P.left-Y,te=P.width+C,ne=Math.max(te,x.width),me=window.innerWidth-xe,je=Ot(Y,[xe,Math.max(xe,me-ne)]);c.style.minWidth=te+"px",c.style.left=je+"px"}else{const _=x.right-D.right,Y=window.innerWidth-L.right-_,C=window.innerWidth-P.right-Y,te=P.width+C,ne=Math.max(te,x.width),me=window.innerWidth-xe,je=Ot(Y,[xe,Math.max(xe,me-ne)]);c.style.minWidth=te+"px",c.style.right=je+"px"}const q=k(),Q=window.innerHeight-xe*2,J=h.scrollHeight,ee=window.getComputedStyle(u),K=parseInt(ee.borderTopWidth,10),V=parseInt(ee.paddingTop,10),G=parseInt(ee.borderBottomWidth,10),Z=parseInt(ee.paddingBottom,10),w=K+V+J+Z+G,M=Math.min(y.offsetHeight*5,w),I=window.getComputedStyle(h),U=parseInt(I.paddingTop,10),se=parseInt(I.paddingBottom,10),b=P.top+P.height/2-xe,A=Q-b,ce=y.offsetHeight/2,v=y.offsetTop+ce,F=K+V+v,X=w-F;if(F<=b){const _=q.length>0&&y===q[q.length-1].ref.current;c.style.bottom="0px";const Y=u.clientHeight-h.offsetTop-h.offsetHeight,C=Math.max(A,ce+(_?se:0)+Y+G),te=F+C;c.style.height=te+"px"}else{const _=q.length>0&&y===q[0].ref.current;c.style.top="0px";const C=Math.max(b,K+h.offsetTop+(_?U:0)+ce)+X;c.style.height=C+"px",h.scrollTop=F-b+h.offsetTop}c.style.margin=`${xe}px 0`,c.style.minHeight=M+"px",c.style.maxHeight=Q+"px",n?.(),requestAnimationFrame(()=>T.current=!0)}},[k,m.trigger,m.valueNode,c,u,h,y,N,m.dir,n]);Ne(()=>g(),[g]);const[R,E]=r.useState();Ne(()=>{u&&E(window.getComputedStyle(u).zIndex)},[u]);const H=r.useCallback(P=>{P&&S.current===!0&&(g(),i?.(),S.current=!1)},[g,i]);return e.jsx(Wa,{scope:a,contentWrapper:c,shouldExpandOnScrollRef:T,onScrollButtonChange:H,children:e.jsx("div",{ref:o,style:{display:"flex",flexDirection:"column",position:"fixed",zIndex:R},children:e.jsx(ue.div,{...l,ref:j,style:{boxSizing:"border-box",maxHeight:"100%",...l.style}})})})});rs.displayName=Ha;var qa="SelectPopperPosition",at=r.forwardRef((t,s)=>{const{__scopeSelect:a,align:n="start",collisionPadding:l=xe,...m}=t,d=qe(a);return e.jsx(sa,{...d,...m,ref:s,align:n,collisionPadding:l,style:{boxSizing:"border-box",...m.style,"--radix-select-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-select-content-available-width":"var(--radix-popper-available-width)","--radix-select-content-available-height":"var(--radix-popper-available-height)","--radix-select-trigger-width":"var(--radix-popper-anchor-width)","--radix-select-trigger-height":"var(--radix-popper-anchor-height)"}})});at.displayName=qa;var[Wa,Ct]=Re(Ie,{}),rt="SelectViewport",ns=r.forwardRef((t,s)=>{const{__scopeSelect:a,nonce:n,...l}=t,m=Ce(rt,a),d=Ct(rt,a),c=fe(s,m.onViewportChange),o=r.useRef(0);return e.jsxs(e.Fragment,{children:[e.jsx("style",{dangerouslySetInnerHTML:{__html:"[data-radix-select-viewport]{scrollbar-width:none;-ms-overflow-style:none;-webkit-overflow-scrolling:touch;}[data-radix-select-viewport]::-webkit-scrollbar{display:none}"},nonce:n}),e.jsx(Ve.Slot,{scope:a,children:e.jsx(ue.div,{"data-radix-select-viewport":"",role:"presentation",...l,ref:c,style:{position:"relative",flex:1,overflow:"hidden auto",...l.style},onScroll:re(l.onScroll,u=>{const f=u.currentTarget,{contentWrapper:j,shouldExpandOnScrollRef:k}=d;if(k?.current&&j){const T=Math.abs(o.current-f.scrollTop);if(T>0){const S=window.innerHeight-xe*2,h=parseFloat(j.style.minHeight),y=parseFloat(j.style.height),N=Math.max(h,y);if(N<S){const i=N+T,g=Math.min(S,i),R=i-g;j.style.height=g+"px",j.style.bottom==="0px"&&(f.scrollTop=R>0?R:0,j.style.justifyContent="flex-end")}}}o.current=f.scrollTop})})})]})});ns.displayName=rt;var ls="SelectGroup",[Ka,Ga]=Re(ls),Ya=r.forwardRef((t,s)=>{const{__scopeSelect:a,...n}=t,l=ct();return e.jsx(Ka,{scope:a,id:l,children:e.jsx(ue.div,{role:"group","aria-labelledby":l,...n,ref:s})})});Ya.displayName=ls;var os="SelectLabel",is=r.forwardRef((t,s)=>{const{__scopeSelect:a,...n}=t,l=Ga(os,a);return e.jsx(ue.div,{id:l.id,...n,ref:s})});is.displayName=os;var Oe="SelectItem",[Za,cs]=Re(Oe),ds=r.forwardRef((t,s)=>{const{__scopeSelect:a,value:n,disabled:l=!1,textValue:m,...d}=t,c=Se(Oe,a),o=Ce(Oe,a),u=c.value===n,[f,j]=r.useState(m??""),[k,T]=r.useState(!1),S=fe(s,i=>o.itemRefCallback?.(i,n,l)),h=ct(),y=r.useRef("touch"),N=()=>{l||(c.onValueChange(n),c.onOpenChange(!1))};if(n==="")throw new Error("A <Select.Item /> must have a value prop that is not an empty string. This is because the Select value can be set to an empty string to clear the selection and show the placeholder.");return e.jsx(Za,{scope:a,value:n,disabled:l,textId:h,isSelected:u,onItemTextChange:r.useCallback(i=>{j(g=>g||(i?.textContent??"").trim())},[]),children:e.jsx(Ve.ItemSlot,{scope:a,value:n,disabled:l,textValue:f,children:e.jsx(ue.div,{role:"option","aria-labelledby":h,"data-highlighted":k?"":void 0,"aria-selected":u&&k,"data-state":u?"checked":"unchecked","aria-disabled":l||void 0,"data-disabled":l?"":void 0,tabIndex:l?void 0:-1,...d,ref:S,onFocus:re(d.onFocus,()=>T(!0)),onBlur:re(d.onBlur,()=>T(!1)),onClick:re(d.onClick,()=>{y.current!=="mouse"&&N()}),onPointerUp:re(d.onPointerUp,()=>{y.current==="mouse"&&N()}),onPointerDown:re(d.onPointerDown,i=>{y.current=i.pointerType}),onPointerMove:re(d.onPointerMove,i=>{y.current=i.pointerType,l?o.onItemLeave?.():y.current==="mouse"&&i.currentTarget.focu
1s({preventScroll:!0})}),onPointerLeave:re(d.onPointerLeave,i=>{i.currentTarget===document.activeElement&&o.onItemLeave?.()}),onKeyDown:re(d.onKeyDown,i=>{o.searchRef?.current!==""&&i.key===" "||(za.includes(i.key)&&N(),i.key===" "&&i.preventDefault())})})})})});ds.displayName=Oe;var Le="SelectItemText",us=r.forwardRef((t,s)=>{const{__scopeSelect:a,className:n,style:l,...m}=t,d=Se(Le,a),c=Ce(Le,a),o=cs(Le,a),u=Fa(Le,a),[f,j]=r.useState(null),k=fe(s,N=>j(N),o.onItemTextChange,N=>c.itemTextRefCallback?.(N,o.value,o.disabled)),T=f?.textContent,S=r.useMemo(()=>e.jsx("option",{value:o.value,disabled:o.disabled,children:T},o.value),[o.disabled,o.value,T]),{onNativeOptionAdd:h,onNativeOptionRemove:y}=u;return Ne(()=>(h(S),()=>y(S)),[h,y,S]),e.jsxs(e.Fragment,{children:[e.jsx(ue.span,{id:o.textId,...m,ref:k}),o.isSelected&&d.valueNode&&!d.valueNodeHasChildren?Bt.createPortal(m.children,d.valueNode):null]})});us.displayName=Le;var ms="SelectItemIndicator",xs=r.forwardRef((t,s)=>{const{__scopeSelect:a,...n}=t;return cs(ms,a).isSelected?e.jsx(ue.span,{"aria-hidden":!0,...n,ref:s}):null});xs.displayName=ms;var nt="SelectScrollUpButton",ps=r.forwardRef((t,s)=>{const a=Ce(nt,t.__scopeSelect),n=Ct(nt,t.__scopeSelect),[l,m]=r.useState(!1),d=fe(s,n.onScrollButtonChange);return Ne(()=>{if(a.viewport&&a.isPositioned){let c=function(){const u=o.scrollTop>0;m(u)};const o=a.viewport;return c(),o.addEventListener("scroll",c),()=>o.removeEventListener("scroll",c)}},[a.viewport,a.isPositioned]),l?e.jsx(gs,{...t,ref:d,onAutoScroll:()=>{const{viewport:c,selectedItem:o}=a;c&&o&&(c.scrollTop=c.scrollTop-o.offsetHeight)}}):null});ps.displayName=nt;var lt="SelectScrollDownButton",hs=r.forwardRef((t,s)=>{const a=Ce(lt,t.__scopeSelect),n=Ct(lt,t.__scopeSelect),[l,m]=r.useState(!1),d=fe(s,n.onScrollButtonChange);return Ne(()=>{if(a.viewport&&a.isPositioned){let c=function(){const u=o.scrollHeight-o.clientHeight,f=Math.ceil(o.scrollTop)<u;m(f)};const o=a.viewport;return c(),o.addEventListener("scroll",c),()=>o.removeEventListener("scroll",c)}},[a.viewport,a.isPositioned]),l?e.jsx(gs,{...t,ref:d,onAutoScroll:()=>{const{viewport:c,selectedItem:o}=a;c&&o&&(c.scrollTop=c.scrollTop+o.offsetHeight)}}):null});hs.displayName=lt;var gs=r.forwardRef((t,s)=>{const{__scopeSelect:a,onAutoScroll:n,...l}=t,m=Ce("SelectScrollButton",a),d=r.useRef(null),c=He(a),o=r.useCallback(()=>{d.current!==null&&(window.clearInterval(d.current),d.current=null)},[]);return r.useEffect(()=>()=>o(),[o]),Ne(()=>{c().find(f=>f.ref.current===document.activeElement)?.ref.current?.scrollIntoView({block:"nearest"})},[c]),e.jsx(ue.div,{"aria-hidden":!0,...l,ref:s,style:{flexShrink:0,...l.style},onPointerDown:re(l.onPointerDown,()=>{d.current===null&&(d.current=window.setInterval(n,50))}),onPointerMove:re(l.onPointerMove,()=>{m.onItemLeave?.(),d.current===null&&(d.current=window.setInterval(n,50))}),onPointerLeave:re(l.onPointerLeave,()=>{o()})})}),Xa="SelectSeparator",fs=r.forwardRef((t,s)=>{const{__scopeSelect:a,...n}=t;return e.jsx(ue.div,{"aria-hidden":!0,...n,ref:s})});fs.displayName=Xa;var ot="SelectArrow",Qa=r.forwardRef((t,s)=>{const{__scopeSelect:a,...n}=t,l=qe(a),m=Se(ot,a),d=Ce(ot,a);return m.open&&d.position==="popper"?e.jsx(aa,{...l,...n,ref:s}):null});Qa.displayName=ot;var Ja="SelectBubbleInput",bs=r.forwardRef(({__scopeSelect:t,value:s,...a},n)=>{const l=r.useRef(null),m=fe(n,l),d=xa(s);return r.useEffect(()=>{const c=l.current;if(!c)return;const o=window.HTMLSelectElement.prototype,f=Object.getOwnPropertyDescriptor(o,"value").set;if(d!==s&&f){const j=new Event("change",{bubbles:!0});f.call(c,s),c.dispatchEvent(j)}},[d,s]),e.jsx(ue.select,{...a,style:{...Ys,...a.style},ref:m,defaultValue:s})});bs.displayName=Ja;function ys(t){return t===""||t===void 0}function vs(t){const s=Js(t),a=r.useRef(""),n=r.useRef(0),l=r.useCallback(d=>{const c=a.current+d;s(c),(function o(u){a.current=u,window.clearTimeout(n.current),u!==""&&(n.current=window.setTimeout(()=>o(""),1e3))})(c)},[s]),m=r.useCallback(()=>{a.current="",window.clearTimeout(n.current)},[]);return r.useEffect(()=>()=>window.clearTimeout(n.current),[]),[a,l,m]}function js(t,s,a){const l=s.length>1&&Array.from(s).every(u=>u===s[0])?s[0]:s,m=a?t.indexOf(a):-1;let d=er(t,Math.max(m,0));l.length===1&&(d=d.filter(u=>
1u!==a));const o=d.find(u=>u.textValue.toLowerCase().startsWith(l.toLowerCase()));return o!==a?o:void 0}function er(t,s){return t.map((a,n)=>t[(s+n)%t.length])}var tr=Gt,Ns=Zt,sr=Qt,ar=Jt,rr=es,ws=ts,nr=ns,Ss=is,Cs=ds,lr=us,or=xs,ks=ps,Ts=hs,Is=fs;const ir=tr,cr=sr,Ps=r.forwardRef(({className:t,children:s,...a},n)=>e.jsxs(Ns,{ref:n,className:we("flex h-9 w-full items-center justify-between whitespace-nowrap rounded-md border border-input bg-transparent px-3 py-2 text-sm shadow-sm ring-offset-background data-[placeholder]:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-ring disabled:cursor-not-allowed disabled:opacity-50 [&>span]:line-clamp-1",t),...a,children:[s,e.jsx(ar,{asChild:!0,children:e.jsx(dt,{className:"h-4 w-4 opacity-50"})})]}));Ps.displayName=Ns.displayName;const Rs=r.forwardRef(({className:t,...s},a)=>e.jsx(ks,{ref:a,className:we("flex cursor-default items-center justify-center py-1",t),...s,children:e.jsx(ra,{className:"h-4 w-4"})}));Rs.displayName=ks.displayName;const Es=r.forwardRef(({className:t,...s},a)=>e.jsx(Ts,{ref:a,className:we("flex cursor-default items-center justify-center py-1",t),...s,children:e.jsx(dt,{className:"h-4 w-4"})}));Es.displayName=Ts.displayName;const Ls=r.forwardRef(({className:t,children:s,position:a="popper",...n},l)=>e.jsx(rr,{children:e.jsxs(ws,{ref:l,className:we("relative z-50 max-h-[--radix-select-content-available-height] min-w-[8rem] overflow-y-auto overflow-x-hidden rounded-md border bg-popover text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 origin-[--radix-select-content-transform-origin]",a==="popper"&&"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",t),position:a,...n,children:[e.jsx(Rs,{}),e.jsx(nr,{className:we("p-1",a==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"),children:s}),e.jsx(Es,{})]})}));Ls.displayName=ws.displayName;const dr=r.forwardRef(({className:t,...s},a)=>e.jsx(Ss,{ref:a,className:we("px-2 py-1.5 text-sm font-semibold",t),...s}));dr.displayName=Ss.displayName;const Us=r.forwardRef(({className:t,children:s,...a},n)=>e.jsxs(Cs,{ref:n,className:we("relative flex w-full cursor-default select-none items-center rounded-sm py-1.5 pl-2 pr-8 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",t),...a,children:[e.jsx("span",{className:"absolute right-2 flex h-3.5 w-3.5 items-center justify-center",children:e.jsx(or,{children:e.jsx(jt,{className:"h-4 w-4"})})}),e.jsx(lr,{children:s})]}));Us.displayName=Cs.displayName;const ur=r.forwardRef(({className:t,...s},a)=>e.jsx(Is,{ref:a,className:we("-mx-1 my-1 h-px bg-muted",t),...s}));ur.displayName=Is.displayName;function As(t){return`${Pe}/storage${t}`}function mr(t,s){const a=t.contentType.toLowerCase();return s==="pdf"?a.includes("pdf")||a.includes("word")||a.includes("document")||a.includes("spreadsheet")||a.includes("sheet")||a.includes("presentation")||a.includes("powerpoint")||a.includes("excel")||a.includes("msword")||a.includes("opendocument"):s==="image"?a.startsWith("image/"):s==="audio"?a.startsWith("audio/"):!0}function xr(t){return t?t<1024*1024?`${(t/1024).toFixed(1)} KB`:`${(t/1024/1024).toFixed(1)} MB`:""}const pr={pdf:{label:"Documents",uploadAccept:".pdf,.doc,.docx,.ppt,.pptx,.xls,.xlsx",uploadMime:["application/pdf","application/msword","application/vnd.openxmlformats-officedocument.wordprocessingml.document","application/vnd.ms-powerpoint","application/vnd.openxmlformats-officedocument.presentationml.presentation","application/vnd.ms-excel","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"],hint:"PDF, Word, Excel, PowerPoint",uploadLabel:"Drag & drop documents here, or click to browse"},image:{label:"Images",uploadAccept:"image/jpeg,image/png,image/gif,image/webp,image/svg+xml",uploadMime:["image/jpeg","image/png","image/gif","
1image/webp","image/svg+xml"],hint:"JPG, PNG, GIF, WebP, SVG",uploadLabel:"Drag & drop images here, or click to browse"},audio:{label:"Audio",uploadAccept:"audio/*",uploadMime:["audio/mpeg","audio/mp3","audio/wav","audio/ogg","audio/mp4","audio/aac","audio/flac"],hint:"MP3, WAV, OGG, AAC, FLAC",uploadLabel:"Drag & drop audio files here, or click to browse"}};function hr({contentType:t,size:s=32}){const a=t.toLowerCase();return a.startsWith("image/")?e.jsx(Me,{size:s,className:"text-sky-400"}):a.startsWith("audio/")?e.jsx(ve,{size:s,className:"text-purple-400"}):a.includes("pdf")?e.jsx(de,{size:s,className:"text-red-400"}):a.includes("word")||a.includes("document")||a.includes("msword")?e.jsx(de,{size:s,className:"text-blue-400"}):a.includes("sheet")||a.includes("excel")?e.jsx(de,{size:s,className:"text-green-500"}):a.includes("presentation")||a.includes("powerpoint")?e.jsx(de,{size:s,className:"text-orange-400"}):e.jsx(de,{size:s,className:"text-gray-900"})}function gr({file:t,onSelect:s,selected:a}){const n=t.contentType.startsWith("image/");return e.jsxs("div",{onClick:()=>s(t),className:`group relative bg-white rounded-xl border overflow-hidden cursor-pointer transition-all hover:border-blue-400 hover:shadow-md ${a?"border-blue-500 ring-2 ring-blue-200":"border-gray-200"}`,children:[e.jsxs("div",{className:"aspect-video bg-gray-50 flex items-center justify-center overflow-hidden relative",children:[n?e.jsx("img",{src:As(t.objectPath),alt:t.name,className:"w-full h-full object-cover",onError:l=>{l.target.style.display="none"}}):e.jsx(hr,{contentType:t.contentType}),a&&e.jsx("div",{className:"absolute top-1.5 right-1.5",children:e.jsx(oa,{size:20,className:"text-blue-500 fill-white"})})]}),e.jsxs("div",{className:"p-2 border-t border-gray-100",children:[e.jsx("p",{className:"text-xs font-medium text-gray-900 leading-tight line-clamp-2 break-words",title:t.name,children:t.name}),t.size>0&&e.jsx("p",{className:"text-[10px] text-gray-900 mt-0.5",children:xr(t.size)})]})]})}function zs({open:t,onClose:s,onSelect:a,type:n}){const[l,m]=r.useState([]),[d,c]=r.useState([]),[o,u]=r.useState(!1),[f,j]=r.useState(""),[k,T]=r.useState(null),[S,h]=r.useState(null),[y,N]=r.useState(!1),i=pr[n];async function g(){u(!0);try{const[x,L]=await Promise.all([fetch(`${Pe}/admin/media/files`,{headers:{Authorization:`Bearer ${Qe()}`}}),fetch(`${Pe}/admin/media/folders`,{headers:{Authorization:`Bearer ${Qe()}`}})]),D=await x.json(),q=await L.json();D.success?m(D.data??[]):ae({title:"Failed to load files",variant:"destructive"}),q.success&&c(q.data??[])}catch{ae({title:"Network error loading media",variant:"destructive"})}finally{u(!1)}}r.useEffect(()=>{t&&(g(),h(null),N(!1),j(""),T(null))},[t]);const R=l.filter(x=>mr(x,n)),E=k===null?R:R.filter(x=>x.folderId===k),H=f?E.filter(x=>x.name.toLowerCase().includes(f.toLowerCase())):E;function P(x){h(x.id),a(As(x.objectPath),x.name),s()}return e.jsx(ft,{open:t,onOpenChange:x=>!x&&s(),children:e.jsxs(bt,{className:"max-w-4xl bg-white border-gray-200 text-gray-900 max-h-[85vh] flex flex-col p-0",children:[e.jsx(yt,{className:"px-5 pt-5 pb-3 border-b border-gray-100 shrink-0",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(vt,{className:"text-gray-900",children:["Choose ",i.label]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(W,{size:"sm",variant:"outline",onClick:()=>N(x=>!x),className:"border-blue-200 text-blue-700 hover:bg-blue-50 gap-1.5",children:[e.jsx(Mt,{size:14})," Upload New"]}),e.jsx(W,{size:"sm",variant:"ghost",onClick:g,className:"text-gray-900 hover:text-gray-700",title:"Refresh",children:e.jsx(na,{size:14,className:o?"animate-spin":""})})]})]})}),e.jsxs("div",{className:"flex flex-1 min-h-0 overflow-hidden",children:[e.jsxs("div",{className:"w-44 border-r border-gray-100 shrink-0 flex flex-col overflow-y-auto p-2 gap-0.5",children:[e.jsxs("button",{onClick:()=>T(null),className:`w-full text-left text-sm px-2.5 py-1.5 rounded-lg flex items-center gap-2 transition-colors ${k===null?"bg-blue-50 text-blue-700 font-medium":"text-gray-900 hover:bg-gray-100"}`,children:[e.jsx(ya,{size:14,className:"shrink-0"}),e.jsx("span",{className:"truncate",children:"All Files"}),e.jsx("span",{className:"ml-auto text-xs text-gray-900",children:R.length})]}),d.map(x=>{const L=R.filter(D=>D.folderId===x.id).length;return e.jsxs("button",{onClick:()=>T(x.id),className:`w-full text-left text-sm px-2.5 py-1.5 rounded-lg flex items-center gap-2 transition-colors ${k===x.id?"bg-blue-50 text-blue-700 font-medium":"text-gray-900 hover:bg-gray-100"}`,children:[e.jsx("span",{className:"w-2.5 h-2.5 rounded-full shrink-0",style:{background:x.color??"#94a3b8"}}),e.jsx("span",{className:"truncate",children:x.name}),e.jsx("span",{className:"ml-auto text-xs text-gray-900",children:L})]},x.id)})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto p-4 space-y-4",children:[y&&e.jsx(va,{accept:i.uploadAccept,acceptMime:i.uploadMime,label:i.uploadLabel,hint:i.hint,isImage:n==="image",folders:d.map(x=>({id:x.id,name:x.name,color:x.color??"#94a3b8"})),defaultFolderId:k,onComplete:()=>{N(!1),g()}}),e.jsxs("div",{className:"relative",children:[e.jsx(la,{size:14,className:"absolute left-3 top-1/2 -translate-y-1/2 text-gray-900"}),e.jsx(B,{value:f,onChange:x=>j(x.target.value),placeholder:`Search ${i.label.toLowerCase()}…`,className:"pl-8 bg-white border-gray-200 text-gray-900 text-sm"})]}),o?e.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 gap-3",children:Array.from({length:8}).map((x,L)=>e.jsx("div",{className:"aspect-video bg-gray-100 rounded-xl animate-pulse"},L))}):H.length===0?e.jsxs("div",{className:"py-14 text-center",children:[n==="image"?e.jsx(Me,{size:36,className:"text-gray-900 mx-auto mb-3"}):n==="audio"?e.jsx(ve,{size:36,className:"text-gray-900 mx-auto mb-3"}):e.jsx(de,{size:36,className:"text-gray-900 mx-auto mb-3"}),e.jsx("p",{className:"text-sm text-gray-900",children:f?`No ${i.label.toLowerCase()} match your search`:k!==null?`No ${i.label.toLowerCase()} in this folder`:`No ${i.label.toLowerCase()} in your library yet`}),!f&&e.jsxs(W,{size:"sm",onClick:()=>N(!0),className:"mt-3 bg-blue-600 hover:bg-blue-700 gap-1.5",children:[e.jsx(Mt,{size:14})," Upload ",i.label]})]}):e.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 gap-3",children:H.map(x=>e.jsx(gr,{file:x,onSelect:P,selected:S===x.id},x.id))})]})]}),e.jsxs("div",{className:"px-5 py-3 border-t border-gray-100 shrink-0 flex items-center justify-between",children:[e.jsxs("p",{className:"text-xs text-gray-900",children:[H.length," ",i.label.toLowerCase()," · click a file to insert"]}),e.jsx(W,{variant:"outline",onClick:s,className:"border-gray-200 text-gray-900",children:"Cancel"})]})]})})}const fr=/^quiz:[a-zA-Z0-9_-]{1,64}$/,br=new Set(["www.youtube.com","youtube.com","www.youtube-nocookie.com","youtube-nocookie.com","player.vimeo.com","vimeo.com","iframe.mediadelivery.net","www.dailymotion.com","dailymotion.com","geo.dailymotion.com","www.google.com","docs.google.com","drive.google.com"]);function Xe(t){return t.replace(/&/g,"&amp;").replace(/"/g,"&quot;").replace(/</g,"&lt;")}function yr(t){try{const s=new URL(t);return s.protocol!=="https:"?null:s.hostname.toLowerCase()}catch{return null}}function vr(t){return!!(br.has(t)||t.endsWith(".youtube.com")||t.endsWith(".google.com"))}const kt="allow-scripts allow-same-origin allow-presentation";function Tt(t){const s=String(t??"").trim();if(!s)return null;if(fr.test(s))return{kind:"quiz",id:s.slice(5)};if(/<script/i.test(s)||/\son\w+\s*=/i.test(s)||/javascript:/i.test(s))return null;const n=(s.match(/\bsrc\s*=\s*"([^"]+)"/i)||s.match(/\bsrc\s*=\s*'([^']+)'/i)||s.match(/\bsrc\s*=\s*([^\s>]+)/i))?.[1]?.trim();if(!n)return null;let l=n;try{l=decodeURIComponent(n)}catch{}const m=yr(l);
1if(!m||!vr(m))return null;const d=s.match(/\bwidth\s*=\s*["']?([^"'>\s]+)/i),c=s.match(/\bheight\s*=\s*["']?([^"'>\s]+)/i);return{kind:"iframe",src:l,width:d?.[1]??"100%",height:c?.[1]??"480"}}function Ms(t){const s=Tt(t);return s?s.kind==="quiz"?`quiz:${s.id}`:`<iframe src="${Xe(s.src)}" width="${Xe(s.width)}" height="${Xe(s.height)}" style="max-width:100%;border:0;" loading="lazy" referrerpolicy="strict-origin-when-cross-origin" sandbox="${kt}" title="Lesson embed" allow="fullscreen; encrypted-media; picture-in-picture"></iframe>`:""}function it(t,s,a={}){if(!t)return"";if(s[t])return s[t];const n=t.match(/iframe\.mediadelivery\.net\/embed\/\d+\/([a-f0-9-]+)/i);if(n){const l=a[n[1]];if(l)return l}try{return decodeURIComponent(t.split("/").filter(Boolean).pop()??"")||"File"}catch{return"File"}}const _s=[{value:"video",label:"Video",icon:xt,color:"text-blue-600",desc:"Embed or link a video (Bunny, R2, YouTube)"},{value:"pdf",label:"PDF",icon:de,color:"text-red-500",desc:"Upload a PDF document"},{value:"image",label:"Image",icon:Me,color:"text-emerald-600",desc:"Upload a single image"},{value:"gallery",label:"Gallery",icon:Ae,color:"text-purple-600",desc:"Multiple images"},{value:"text",label:"Content",icon:ut,color:"text-amber-700",desc:"Rich text with inline images / class notes"},{value:"quiz",label:"Quiz",icon:ht,color:"text-orange-700",desc:"Interactive quiz"},{value:"audio",label:"Audio",icon:ve,color:"text-pink-600",desc:"Audio file or URL"},{value:"embed",label:"Embed",icon:wt,color:"text-cyan-700",desc:"Code or iframe embed"},{value:"link",label:"Link",icon:St,color:"text-indigo-600",desc:"External URL"},{value:"assignment",label:"Assignment",icon:ze,color:"text-amber-700",desc:"Graded assignment step"}];function It({type:t}){const s=_s.find(n=>n.value===t),a=s?.icon??de;return e.jsxs(gt,{variant:"outline",className:`gap-1 text-xs border-gray-200 bg-gray-50 ${s?.color??"text-gray-900"}`,children:[e.jsx(a,{size:12})," ",s?.label??t]})}function he(t,s){const[a,n]=r.useState(null),[l,m]=r.useState(!1),[d,c]=r.useState(!1);return r.useEffect(()=>{if(!t){n(null),m(!1),c(!1);return}if(!ca(t)){n(t),m(!1),c(!1);return}let o=!1;m(!0),c(!1),n(null);const u=localStorage.getItem("lms_token");return fetch(da(t),{headers:u?{Authorization:`Bearer ${u}`}:{}}).then(f=>{if(!f.ok)throw new Error("fetch failed");if(s){const j=f.headers.get("content-type")??"";if(!j.toLowerCase().startsWith(s))throw new Error(`unexpected content-type: ${j}`)}return f.blob()}).then(f=>{if(o)return;const j=URL.createObjectURL(f);n(j),m(!1)}).catch(()=>{o||(c(!0),m(!1))}),()=>{o=!0,n(f=>(f&&URL.revokeObjectURL(f),null))}},[t,s]),{blobUrl:a,loading:l,error:d}}async function Ds(t,s){const a=await fetch(`${s}/storage/uploads/request-url`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${Qe()??""}`},body:JSON.stringify({name:t.name,size:t.size,contentType:t.type})});if(!a.ok)throw new Error("Failed to get upload URL");const{uploadURL:n,objectPath:l}=await a.json();if(!(await fetch(n,{method:"PUT",body:t,headers:{"Content-Type":t.type}})).ok)throw new Error("Upload failed");return l}function jr(t){switch(t.stepType){case"video":return!!(t.videoUrl||t.hlsUrl);case"pdf":return!!t.pdfUrl;case"image":case"gallery":return!!t.imageUrl;case"audio":return!!t.audioUrl;case"text":case"content":return!!t.content;case"embed":return!!t.embedCode;case"link":return!!t.videoUrl;default:return null}}function Nr({step:t,mediaNameMap:s,videoNameMap:a,onPreview:n}){const l=jr(t);if(l===null)return null;if(l){const m=t.stepType==="video"||t.stepType==="link"?t.videoUrl:t.stepType==="pdf"?t.pdfUrl:t.stepType==="image"||t.stepType==="gallery"?t.imageUrl:t.stepType==="audio"?t.audioUrl:"",d=m?it(m,s,a):"Set";return e.jsxs("button",{type:"button",onClick:c=>{c.stopPropagation(),n()},title:d,className:"inline-flex items-center gap-1 text-[10px] font-medium text-emerald-700 bg-emerald-50 border border-emerald-200 rounded-full px-1.5 py-0.5 hover:bg-emerald-100 hover:border-emerald-400 transition-colors max-w-full",children:[e.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-emerald-500 shrink-0"}),e.jsx("span",{className:"truncate",children:d})]})}return e.jsxs("span",{className:"inline-flex items-center gap-1 text-[10px] font-medium text-amber-600 bg-amber-50 border border-amber-200 rounded-full px-1.5 py-0.5 shrink-0",children:[e.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-amber-500 shrink-0"}),"No media"]})}function ye(){return e.jsxs("div",{className:"flex items-center justify-center gap-2 py-12 text-sm text-gray-900",children:[e.jsx("div",{className:"w-4 h-4 rounded-full border-2 border-gray-300 border-t-blue-500 animate-spin"}),"Loading…"]})}function oe({label:t,icon:s}){return e.jsxs("div",{className:"flex flex-col items-center justify-center gap-2 py-12 text-center px-4",children:[s??e.jsx(de,{size:28,className:"text-gray-900"}),e.jsx("p",{className:"text-sm text-gray-900",children:t})]})}function ke({label:t}){return e.jsxs("div",{className:"flex flex-col items-center justify-center gap-2 py-12 text-center px-4",children:[e.jsx(Je,{size:28,className:"text-red-400"}),e.jsx("p",{className:"text-sm text-red-600",children:t})]})}function wr(t){return t?t.split(/\n\s*\n/).map(s=>{const a=s.trim().match(/^!\[([^\]]*)\]\((\S+)\)$/);return a?{type:"image",alt:a[1],url:a[2]}:{type:"text",value:s}}).filter(s=>s.type==="image"||s.value.trim().length>0):[]}function Sr({url:t,alt:s}){const{blobUrl:a,loading:n,error:l}=he(t,"image/");return n?e.jsx(ye,{}):l?e.jsx(ke,{label:"Couldn't load this image — the link may be broken or the file moved."}):a?e.jsx("img",{src:a,alt:s,className:"w-full rounded-lg border border-gray-200 object-contain",style:{maxHeight:420}}):null}function Be({content:t}
1){const s=wr(t);return s.length===0?e.jsx(oe,{label:"No content written yet",icon:e.jsx(ut,{size:28,className:"text-gray-900"})}):e.jsx("div",{className:"space-y-3",children:s.map((a,n)=>a.type==="image"?e.jsx(Sr,{url:a.url,alt:a.alt},n):e.jsx("p",{className:"text-sm text-gray-900 whitespace-pre-wrap leading-relaxed",children:a.value},n))})}function Fs({lessonId:t}){const[s,a]=r.useState(null),[n,l]=r.useState(!0);return r.useEffect(()=>{let m=!1;return l(!0),le.get(`/admin/quizzes-all?lessonId=${t}`).then(d=>{if(m)return;const c=(d.data??[]).map(o=>{let u=[];try{u=JSON.parse(o.options)}catch{u=[]}return{id:o.id,question:o.question,options:u,correctAnswer:o.correctAnswer,explanation:o.explanation}});a(c)}).catch(()=>{m||a([])}).finally(()=>{m||l(!1)}),()=>{m=!0}},[t]),n?e.jsx(ye,{}):!s||s.length===0?e.jsx(oe,{label:"No quiz questions yet",icon:e.jsx(ht,{size:28,className:"text-orange-300"})}):e.jsx("div",{className:"space-y-3",children:s.map((m,d)=>e.jsxs("div",{className:"rounded-lg border border-gray-200 p-3 bg-white",children:[e.jsxs("p",{className:"text-sm font-medium text-gray-900 mb-2",children:[d+1,". ",m.question]}),e.jsx("div",{className:"space-y-1.5",children:m.options.map((c,o)=>{const u=c===m.correctAnswer;return e.jsxs("div",{className:`text-xs px-2.5 py-1.5 rounded-md border flex items-center gap-2 ${u?"border-emerald-300 bg-emerald-50 text-emerald-800 font-medium":"border-gray-200 bg-gray-50 text-gray-900"}`,children:[u&&e.jsx(jt,{size:12,className:"shrink-0 text-emerald-600"}),c]},o)})}),m.explanation&&e.jsxs("p",{className:"text-[11px] text-gray-900 mt-2 italic",children:["Explanation: ",m.explanation]})]},m.id))})}function Cr({step:t,onClose:s}){const{blobUrl:a,loading:n,error:l}=he(t.pdfUrl,"application/pdf"),{blobUrl:m,loading:d,error:c}=he(t.imageUrl,"image/"),{blobUrl:o}=he(t.audioUrl),u=r.useRef(null),[f,j]=r.useState(!1),[k,T]=r.useState(0),[S,h]=r.useState(0);r.useEffect(()=>{const i=u.current;if(!i)return;const g=()=>T(i.currentTime),R=()=>h(i.duration),E=()=>j(!1);return i.addEventListener("timeupdate",g),i.addEventListener("loadedmetadata",R),i.addEventListener("ended",E),()=>{i.removeEventListener("timeupdate",g),i.removeEventListener("loadedmetadata",R),i.removeEventListener("ended",E)}},[o]);function y(){const i=u.current;i&&(f?(i.pause(),j(!1)):(i.play(),j(!0)))}function N(i){return!isFinite(i)||isNaN(i)?"0:00":`${Math.floor(i/60)}:${Math.floor(i%60).toString().padStart(2,"0")}`}return e.jsxs("div",{className:"w-full lg:w-[420px] lg:shrink-0 bg-white border border-gray-200 rounded-xl shadow-sm overflow-hidden flex flex-col self-start lg:sticky lg:top-0",children:[e.jsxs("div",{className:"flex items-center justify-between px-3 py-2.5 border-b border-gray-100 bg-gray-50",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsx(It,{type:t.stepType}),e.jsx("span",{className:"text-xs font-semibold text-gray-900 truncate",children:t.title})]}),e.jsx("button",{onClick:s,className:"p-1 text-gray-900 hover:text-gray-700 shrink-0 ml-1",children:e.jsx(mt,{size:14})})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto p-3 space-y-2",children:[t.stepType==="video"&&(t.videoUrl?e.jsx("div",{className:"rounded-lg overflow-hidden border border-gray-200",style:{aspectRatio:"16/9"},children:e.jsx("iframe",{src:t.videoUrl,className:"w-full h-full",allow:"autoplay; encrypted-media",allowFullScreen:!0,style:{border:"none"}})}):e.jsx(oe,{label:"No video URL set",icon:e.jsx(xt,{size:28,className:"text-gray-900"})})),t.stepType==="pdf"&&(n?e.jsx(ye,{}):l?e.jsx(ke,{label:"Couldn't load this PDF — the file may be missing or the link is broken."}):a?e.jsx("div",{className:"rounded-lg overflow-hidden border border-gray-200",style:{height:540},children:e.jsx("iframe",{src:a,className:"w-full h-full",style:{border:"none"},title:"PDF"})}):e.jsx(oe,{label:"No PDF file set",icon:e.jsx(de,{size:28,className:"text-gray-900"})})),(t.stepType==="image"||t.stepType==="gallery")&&(d?e.jsx(ye,{}):c?e.jsx(ke,{label:"Couldn't load this image — the file may be missing or the link is broken."}):m?e.jsx("img",{src:m,alt:"Preview",className:"w-full rounded-lg border border-gray-200 object-contain",style:{maxHeight:380}}):e.jsx(oe,{label:"No image set",icon:e.jsx(Me,{size:28,className:"text-gray-900"})})),t.stepType==="audio"&&(o?e.jsxs("div",{className:"rounded-xl border border-gray-200 p-3 space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-9 h-9 rounded-lg bg-violet-100 flex items-center justify-center shrink-0",children:e.jsx(ve,{size:16,className:"text-violet-500"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-xs font-semibold text-gray-900 truncate",children:t.title}),e.jsx("p",{className:"text-[10px] text-gray-900",children:S>0?N(S):"Loading…"})]})]}),e.jsx("audio",{ref:u,src:o,preload:"metadata"}),e.jsx("div",{className:"flex items-end gap-0.5 h-7",children:Array.from({length:40}).map((i,g)=>{const R=20+Math.sin(g*.7)*10+Math.sin(g*1.3)*8,E=S>0&&g/40*S<k;return e.jsx("div",{className:`flex-1 rounded-sm ${E?"bg-violet-500":"bg-gray-200"}`,style:{height:`${R}%`}},g)})}),e.jsx("input",{type:"range",min:0,max:S||100,value:k,onChange:i=>{const g=Number(i.target.value);u.current&&(u.current.currentTime=g),T(g)},className:"w-full h-1 accent-violet-500 cursor-pointer"}),e.jsxs("div",{className:"flex justify-between text-[10px] font-mono text-gray-900",children:[e.jsx("span",{children:N(k)}),e.jsx("span",{children:N(S)})]}),e.jsx("div",{className:"flex justify-center",children:e.jsx("button",{onClick:y,className:"w-9 h-9 rounded-full bg-violet-600 hover:bg-violet-700 text-white flex items-center justify-center shadow transition-colors pointer-coarse:h-11 pointer-coarse:w-11",children:f?e.jsx(Kt,{size:14,fill:"white"}):e.jsx(Nt,{size:14,fill:"white",className:"ml-0.5"})})})]}):e.jsx(oe,{label:"No audio file set",icon:e.jsx(ve,{size:28,className:"text-gray-900"})})),(t.stepType==="text"||t.stepType==="content")&&e.jsx(Be,{content:t.content}),t.stepType==="embed"&&(()=>{const i=Tt(t.embedCode);return i?.kind==="iframe"?e.jsx("iframe",{src:i.src,width:i.width,height:i.height,style:{maxWidth:"100%",border:0}
1,loading:"lazy",referrerPolicy:"strict-origin-when-cross-origin",sandbox:kt,title:"Lesson embed",allow:"fullscreen; encrypted-media; picture-in-picture",className:"w-full"}):i?.kind==="quiz"?e.jsxs("div",{className:"text-sm text-gray-900",children:["Linked quiz: ",i.id]}):e.jsx(oe,{label:"No embed code set",icon:e.jsx(wt,{size:28,className:"text-gray-900"})})})(),t.stepType==="link"&&(t.videoUrl?e.jsxs("a",{href:t.videoUrl,target:"_blank",rel:"noreferrer",className:"flex items-center gap-2 text-blue-600 text-sm hover:underline break-all",children:[e.jsx(pt,{size:14,className:"shrink-0"}),t.videoUrl]}):e.jsx(oe,{label:"No URL set",icon:e.jsx(St,{size:28,className:"text-gray-900"})})),t.stepType==="quiz"&&e.jsx(Fs,{lessonId:t.id}),t.stepType==="assignment"&&e.jsx(oe,{label:"Assignment — managed in Assignments tab",icon:e.jsx(ze,{size:28,className:"text-amber-300"})})]})]})}function kr({open:t,onClose:s,sections:a,editStep:n,defaultSectionId:l,apiBase:m,onSave:d}){const[c,o]=r.useState(n?.title??""),[u,f]=r.useState(n?.stepType??"video"),[j,k]=r.useState(n?.sectionId??l??a[0]?.id??0),[T,S]=r.useState(n?.videoUrl??""),[h,y]=r.useState(n?.hlsUrl??""),[N,i]=r.useState(n?.pdfUrl??""),[g,R]=r.useState(n?.imageUrl??""),[E,H]=r.useState(n?.audioUrl??""),[P,x]=r.useState(n?.embedCode??""),[L,D]=r.useState(n?.content??""),[q,Q]=r.useState(n?.isRequired??!1),[J,ee]=r.useState(!1),[K,V]=r.useState(!1),[G,Z]=r.useState(!1),[w,M]=r.useState(!1),[I,U]=r.useState("pdf"),[se,b]=r.useState(!1),A=r.useRef(null),[ce,v]=r.useState(!1),[F,X]=r.useState(0),[z,_]=r.useState(0),[Y,C]=r.useState(.8),[te,ne]=r.useState(!1),me=r.useRef(null),[je,_e]=r.useState(!1);function De(p){const $=`
2
3![](${p})
4
5`,ie=me.current;if(ie){const be=ie.selectionStart??L.length,Hs=ie.selectionEnd??L.length,qs=L.slice(0,be)+$+L.slice(Hs);D(qs),requestAnimationFrame(()=>{ie.focus();const Ut=be+$.length;ie.setSelectionRange(Ut,Ut)})}else D(be=>be+$)}async function $s(p){const $=p.target.files?.[0];if($){_e(!0);try{const ie=await Ds($,m);De(ie),ae({title:"Image inserted"})}catch{ae({title:"Image upload failed",variant:"destructive"})}finally{_e(!1),p.target.value=""}}}const{blobUrl:Fe,loading:Pt,error:Rt}=he(N,"application/pdf"),{blobUrl:Ee,loading:Et,error:Lt}=he(g,"image/"),{blobUrl:Os}=he(E);r.useEffect(()=>{const p=A.current;if(!p)return;const $=()=>X(p.currentTime),ie=()=>_(p.duration),be=()=>v(!1);return p.addEventListener("timeupdate",$),p.addEventListener("loadedmetadata",ie),p.addEventListener("ended",be),()=>{p.removeEventListener("timeupdate",$),p.removeEventListener("loadedmetadata",ie),p.removeEventListener("ended",be)}},[E]);function Bs(){const p=A.current;p&&(ce?(p.pause(),v(!1)):(p.play(),v(!0)))}function We(p){if(!isFinite(p)||isNaN(p))return"0:00";const $=Math.floor(p/60),ie=Math.floor(p%60);return`${$}:${ie.toString().padStart(2,"0")}`}r.useEffect(()=>{t&&(o(n?.title??""),f(n?.stepType??"video"),k(n?.sectionId??l??a[0]?.id??0),S(n?.videoUrl??""),y(n?.hlsUrl??""),i(n?.pdfUrl??""),R(n?.imageUrl??""),H(n?.audioUrl??""),x(n?.embedCode??""),D(n?.content??""),Q(n?.isRequired??!1),v(!1),X(0),_(0),ne(!1),b(!1))},[t,n,l,a]);async function Vs(){if(!c.trim()){ae({title:"Step name required",variant:"destructive"});return}ee(!0);try{const p={title:c,stepType:u,sectionId:j,videoUrl:T,hlsUrl:h,pdfUrl:N,imageUrl:g,audioUrl:E,embedCode:Ms(P),content:L,isRequired:q};n?(await le.put(`/admin/steps/${n.id}`,p),ae({title:"Step updated"})):(await le.post(`/admin/sections/${j}/steps`,p),ae({title:"Step created"})),d(),s()}catch{ae({title:"Save failed",variant:"destructive"})}finally{ee(!1)}}const pe="bg-white border-gray-300 text-gray-900 placeholder:text-gray-500";return e.jsx(ft,{open:t,onOpenChange:p=>!p&&s(),children:e.jsxs(bt,{className:"max-w-2xl bg-white border-gray-200 text-gray-900 max-h-[90vh] overflow-y-auto",children:[e.jsx(yt,{children:e.jsx(vt,{className:"text-gray-900",children:n?"Edit Step":"Add Step"})}),e.jsxs("div",{className:"space-y-5 py-2",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx(O,{className:"text-gray-900",children:"Step Name *"}),e.jsx(B,{value:c,onChange:p=>o(p.target.value),placeholder:"e.g. Introduction to Astronomy, Class 1 of 50",className:`${pe} mt-1`})]}),e.jsxs("div",{children:[e.jsx(O,{className:"text-gray-900",children:"Section"}),e.jsxs(ir,{value:String(j),onValueChange:p=>k(Number(p)),children:[e.jsx(Ps,{className:"bg-white border-gray-300 text-gray-900 mt-1",children:e.jsx(cr,{placeholder:"Select section"})}),e.jsx(Ls,{className:"bg-white border-gray-200",children:a.map(p=>e.jsx(Us,{value:String(p.id),className:"text-gray-900",children:p.title},p.id))})]})]})]}),e.jsxs("div",{children:[e.jsx(O,{className:"text-gray-900 mb-2 block",children:"Content Type"}
5),e.jsx("div",{className:"grid grid-cols-5 gap-2",children:_s.map(p=>{const $=p.icon;return e.jsxs("button",{onClick:()=>f(p.value),className:`flex flex-col items-center gap-1.5 p-3 rounded-lg border transition-all text-xs ${u===p.value?`border-blue-400 bg-blue-50 ${p.color}`:"border-gray-200 bg-gray-50 text-gray-900 hover:border-gray-300 hover:bg-gray-100"}`,title:p.desc,children:[e.jsx($,{size:18}),e.jsx("span",{children:p.label})]},p.value)})})]}),e.jsxs("div",{className:"rounded-lg border border-gray-200 bg-gray-50 p-4 space-y-3",children:[u==="video"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center justify-between mb-1",children:[e.jsxs(O,{className:"text-gray-900 text-sm",children:["Video URL ",e.jsx("span",{className:"text-gray-900",children:"(Bunny.net, YouTube, Vimeo)"})]}),e.jsxs("button",{type:"button",onClick:()=>Z(!0),className:"flex items-center gap-1.5 text-xs text-blue-600 hover:text-blue-700 font-medium border border-blue-200 bg-blue-50 hover:bg-blue-100 px-2.5 py-1 rounded-lg transition-colors",children:[e.jsx(Ht,{size:12})," Browse Media Library"]})]}),e.jsx("div",{children:e.jsx(B,{value:T,onChange:p=>S(p.target.value),placeholder:"https://iframe.mediadelivery.net/embed/...",className:`${pe} font-mono text-sm`})}),e.jsxs("div",{children:[e.jsxs(O,{className:"text-gray-900 text-sm",children:["HLS Stream URL ",e.jsx("span",{className:"text-gray-900",children:"(optional — for adaptive streaming)"})]}),e.jsx(B,{value:h,onChange:p=>y(p.target.value),placeholder:"https://vz-abc123.b-cdn.net/video/playlist.m3u8",className:`${pe} mt-1 font-mono text-sm`})]}),T&&e.jsxs("div",{className:"mt-1 space-y-1.5",children:[e.jsx("span",{className:"text-[11px] font-semibold text-gray-900 uppercase tracking-wide",children:"Preview"}),e.jsx("div",{className:"rounded-lg overflow-hidden border border-gray-200",style:{aspectRatio:"16/9",maxWidth:360},children:e.jsx("iframe",{src:T,className:"w-full h-full",allow:"autoplay; encrypted-media",allowFullScreen:!0,style:{border:"none"},title:"Video preview"})})]}),e.jsx(Wt,{open:G,onClose:()=>Z(!1),onSelect:(p,$,ie)=>{S(p),y($),ae({title:"Video selected",description:"URLs filled from Media Library"})}})]}),u==="pdf"&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(O,{className:"text-gray-900 text-sm",children:"PDF File"}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs(W,{type:"button",variant:"outline",className:"border-blue-200 text-blue-700 hover:bg-blue-50 gap-1.5",onClick:()=>{U("pdf"),M(!0)},children:[e.jsx(de,{size:15})," Browse Media Library"]}),N&&e.jsxs("span",{className:"text-xs text-emerald-600 truncate max-w-[220px]",children:["✓ ",decodeURIComponent(N.split("/").pop()??"File selected")]})]}),e.jsx(B,{value:N,onChange:p=>i(p.target.value),placeholder:"or paste URL",className:`${pe} font-mono text-sm`}),N&&e.jsxs("div",{className:"mt-1 space-y-1.5",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-[11px] font-semibold text-gray-900 uppercase tracking-wide",children:"Preview"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{type:"button",className:"text-xs text-blue-600 hover:underline",onClick:()=>b(p=>!p),children:se?"Collapse":"Expand"}),Fe&&e.jsx("a",{href:Fe,target:"_blank",rel:"noreferrer",title:"Open in a new tab",className:"text-gray-900 hover:text-gray-600",children:e.jsx(pt,{size:12})})]})]}),e.jsxs("div",{className:"rounded-lg border border-gray-200 overflow-hidden bg-gray-50 transition-all duration-200",style:{height:se?440:240},children:[Pt&&e.jsxs("div",{className:"w-full h-full flex items-center justify-center gap-2 text-sm text-gray-900",children:[e.jsx("div",{className:"w-4 h-4 rounded-full border-2 border-gray-300 border-t-blue-500 animate-spin"}),"Loading PDF…"]}),Rt&&e.jsxs("div",{className:"w-full h-full flex flex-col items-center justify-center gap-1.5 text-center px-4",children:[e.jsx(Je,{size:20,className:"text-red-400"}),e.jsx("p",{className:"text-xs text-red-600",children:"Couldn't load this PDF — the file may be missing or the link is broken."})]}),Fe&&!Pt&&!Rt&&e.jsx("iframe",{src:Fe,className:"w-full h-full",title:"PDF preview",style:{border:"none"}})]})]})]}),(u==="image"||u==="gallery")&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(O,{className:"text-gray-900 text-sm",children:u==="gallery"?"Images":"Image File"}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs(W,{type:"button",variant:"outline",className:"border-blue-200 text-blue-700 hover:bg-blue-50 gap-1.5",onClick:()=>{U("image"),M(!0)},children:[e.jsx(Ae,{size:15})," Browse Media Library"]}),g&&e.jsx("span",{className:"text-xs text-emerald-600 truncate max-w-[220px]",children:"✓ Image selected"})]}),e.jsx(B,{value:g,onChange:p=>R(p.target.value),placeholder:"or paste image URL",className:`${pe} font-mono text-sm`}),g&&e.jsxs("div",{className:"mt-1 space-y-1.5",children:[e.jsx("span",{className:"text-[11px] font-semibold text-gray-900 uppercase tracking-wide",children:"Preview"}),e.jsxs("div",{className:"relative rounded-lg overflow-hidden border border-gray-200 bg-gray-50 group cursor-zoom-in",style:{aspectRatio:"16/9"},onClick:()=>Ee&&ne(!0),children:[Et&&e.jsxs("div",{className:"w-full h-full flex items-center justify-center gap-2 text-sm text-gray-900",children:[e.jsx("div",{className:"w-4 h-4 rounded-full border-2 border-gray-300 border-t-blue-500 animate-spin"}),"Loading…"]}),Lt&&e.jsxs("div",{className:"w-full h-full flex flex-col items-center justify-center gap-1.5 text-center px-4",children:[e.jsx(Je,{size:20,className:"text-red-400"}),e.jsx("p",{className:"text-xs text-red-600",children:"Couldn't load this image — the file may be missing or the link is broken."})]}),Ee&&!Et&&!Lt&&e.jsxs(e.Fragment,{children:[e.jsx("img",{src:Ee,alt:"Preview",className:"w-full h-full object-cover"}),e.jsx("div",{className:"absolute inset-0 bg-black/0 group-hover:bg-black/20 transition-all flex items-center justify-center",children:e.jsx("div",{className:"opacity-0 group-hover:opacity-100 bg-white/90 rounded-full p-1.5 transition-opacity",children:e.jsx(Ua,{size:15,className:"text-gray-900"})})})]})]})]}),te&&Ee&&e.jsxs("div",{className:"fixed inset-0 z-[200] bg-black/80 flex items-center justify-center p-8",onClick:()=>ne(!1),children:[e.jsx("img",{src:Ee,alt:"Full preview",className:"max-w-full max-h-full rounded-xl shadow-2xl"}),e.jsx("button",{type:"button",className:"absolute top-4 right-4 bg-white/20 hover:bg-white/30 rounded-full p-2",onClick:()=>ne(!1),children:e.jsx(mt,{size:18,className:"text-white"})})]})]}),u==="text"&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(O,{className:"text-gray-900 text-sm",children:"Class Notes / Content"}),e.jsxs("label",{className:"flex items-center gap-1.5 text-xs text-blue-600 hover:text-blue-700 font-medium border border-blue-200 bg-blue-50 hover:bg-blue-100 px-2.5 py-1 rounded-lg transition-colors cursor-pointer",children:[e.jsx(Ae,{size:12})," ",je?"Uploading…":"Insert Image",e.jsx("input",{type:"file",accept:"image/*",className:"hidden",onChange:$s,disabled:je})]})]}),e.jsx(Ue,{ref:me,value:L,onChange:p=>D(p.target.value),placeholder:"Write lesson content, notes, or instructions here... Use Insert Image to add pictures inline.",className:`${pe} min-h-[140px]`}),L&&e.jsxs("div",{className:"rounded-lg border border-gray-200 bg-white p-3",children:[e.jsx("span",{className:"text-[11px] font-semibold text-gray-900 uppercase tracking-wide",children:"Preview"}),e.jsx("div",{className:"mt-2",children:e.jsx(Be,{content:L})})]})]}),u==="audio"&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(O,{className:"text-gray-900 text-sm",children:"Audio File"}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs(W,{type:"button",variant:"outline",className:"border-blue-200 text-blue-700 hover:bg-blue-50 gap-1.5",onClick:()=>{U("audio"),M(!0)},children:[e.jsx(ve,{size:15})," Browse Media Library"]}),E&&e.jsxs("span",{className:"text-xs text-emerald-600 truncate max-w-[220px]",children:["✓ ",decodeURIComponent(E.split("/").pop()??"Audio selected")]})]}),e.jsx(B,{value:E,onChange:p=>{H(p.target.value),v(!1),X(0)},placeholder:"or paste audio URL",className:`${pe} font-mono text-sm`}),E&&e.jsxs("div",{className:"mt-1 space-y-1.5",children:[e.jsx("span",{className:"text-[11px] font-semibold text-gray-900 uppercase tracking-wide",children:"Preview"}),e.jsx("audio",{ref:A,src:Os??void 0,preload:"metadata"}),e.jsxs("div",{className:"bg-white rounded-xl border border-gray-200 p-3.5 space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-9 h-9 rounded-lg bg-violet-100 flex items-center justify-center shrink-0",children:e.jsx(ve,{size:16,className:"text-violet-500"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-sm font-semibold text-gray-900 truncate",children:decodeURIComponent(E.split("/").pop()??"audio")}),e.jsxs("p",{className:"text-xs text-gray-900",children:[z>0?We(z):"Loading…"," · Audio"]})]})]}),e.jsx("div",{className:"flex items-end gap-0.5 h-7",children:Array.from({length:48}).map((p,$)=>{const ie=20+Math.sin($*.7)*10+Math.sin($*1.3)*8,be=z>0&&$/48*z<F;return e.jsx("div",{className:`flex-1 rounded-sm transition-colors ${be?"bg-violet-500":"bg-gray-200"}`,style:{height:`${ie}%`}},$)}
5)}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("input",{type:"range",min:0,max:z||100,value:F,onChange:p=>{const $=Number(p.target.value);A.current&&(A.current.currentTime=$),X($)},className:"w-full h-1 accent-violet-500 cursor-pointer"}),e.jsxs("div",{className:"flex justify-between text-[10px] font-mono text-gray-900",children:[e.jsx("span",{children:We(F)}),e.jsx("span",{children:We(z)})]})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ea,{size:13,className:"text-gray-900"}),e.jsx("input",{type:"range",min:0,max:1,step:.05,value:Y,onChange:p=>{const $=Number(p.target.value);C($),A.current&&(A.current.volume=$)},className:"w-20 h-1 accent-violet-400"})]}),e.jsx("button",{type:"button",onClick:Bs,className:"w-9 h-9 rounded-full bg-violet-600 hover:bg-violet-700 text-white flex items-center justify-center shadow-md transition-colors pointer-coarse:h-11 pointer-coarse:w-11",children:ce?e.jsx(Kt,{size:14,fill:"white"}):e.jsx(Nt,{size:14,fill:"white",className:"ml-0.5"})}),e.jsx("div",{className:"w-24"})]})]})]})]}),u==="embed"&&e.jsxs("div",{children:[e.jsxs(O,{className:"text-gray-900 text-sm",children:["Embed Code ",e.jsx("span",{className:"text-gray-900",children:"(iframe, HTML, or script)"})]}),e.jsx(Ue,{value:P,onChange:p=>x(p.target.value),placeholder:'<iframe src="..." width="100%" height="400"></iframe>',className:`${pe} mt-1 font-mono text-sm min-h-[100px]`})]}),u==="link"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[e.jsx(O,{className:"text-gray-900 text-sm",children:"URL"}),e.jsx(B,{value:T,onChange:p=>S(p.target.value),placeholder:"https://example.com/resource",className:`${pe} mt-1 font-mono text-sm`})]}),e.jsxs("div",{children:[e.jsxs(O,{className:"text-gray-900 text-sm",children:["Description ",e.jsx("span",{className:"text-gray-900",children:"(optional)"})]}),e.jsx(B,{value:L,onChange:p=>D(p.target.value),placeholder:"Resource description",className:`${pe} mt-1`})]})]}),u==="quiz"&&e.jsxs("div",{className:"text-sm text-gray-900 bg-blue-50 rounded-md p-3 border border-blue-100",children:[e.jsx(ht,{size:16,className:"inline mr-2 text-orange-500"}),"Quiz content is managed after saving. Create the step first, then add questions via the course quiz editor."]}),u==="assignment"&&e.jsxs("div",{className:"text-sm text-gray-900 bg-amber-50 rounded-md p-3 border border-amber-100",children:[e.jsx(ze,{size:16,className:"inline mr-2 text-amber-500"}),"This step links to the Assignments section. Create assignment details from the Assignments tab."]})]}),e.jsxs("div",{className:"flex items-center gap-3 p-3 rounded-lg border border-gray-200 bg-gray-50",children:[e.jsx($e,{checked:q,onCheckedChange:Q}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-gray-900",children:"Required to complete"}),e.jsx("p",{className:"text-xs text-gray-900",children:"Students must complete this step before advancing"})]})]})]}),e.jsx(zs,{open:w,type:I,onClose:()=>M(!1),onSelect:(p,$)=>{I==="pdf"?i(p):I==="image"?R(p):I==="audio"&&H(p),ae({title:"File selected",description:$})}}),e.jsxs(qt,{children:[e.jsx(W,{variant:"outline",onClick:s,className:"border-gray-300 text-gray-900",children:"Cancel"}),e.jsx(W,{onClick:Vs,disabled:J||K,className:"bg-blue-600 hover:bg-blue-500",children:J?"Saving...":n?"Save Changes":"Add Step"})]})]})})}function Tr({section:t,isFirst:s,isLast:a,onMoveUp:n,onMoveDown:l,onDelete:m,onRename:d,onAddStep:c,onEditStep:o,onDeleteStep:u,onMoveStepUp:f,onMoveStepDown:j,onPreviewStep:k,onReview:T,mediaNameMap:S,videoNameMap:h}){const[y,N]=r.useState(!0),[i,g]=r.useState(!1),[R,E]=r.useState(t.title);function H(){R.trim()&&d(R.trim()),g(!1)}return e.jsxs("div",{className:"border border-gray-200 rounded-xl overflow-hidden bg-white shadow-sm",children:[e.jsxs("div",{className:"flex items-center gap-2 px-4 py-3 bg-gray-50 border-b border-gray-100",children:[e.jsx($t,{size:16,className:"text-gray-900 shrink-0"}),e.jsx("button",{onClick:()=>N(!y),className:"text-gray-900 hover:text-gray-700 transition-colors shrink-0",children:y?e.jsx(dt,{size:18}):e.jsx(et,{size:18})}),i?e.jsxs("div",{className:"flex items-center gap-2 flex-1",children:[e.jsx(B,{value:R,onChange:P=>E(P.target.value),onKeyDown:P=>{P.key==="Enter"&&H(),P.key==="Escape"&&g(!1)},autoFocus:!0,className:"bg-white border-blue-400 text-gray-900 h-7 text-sm"}),e.jsx("button",{onClick:H,className:"text-emerald-600 hover:text-emerald-500",children:e.jsx(jt,{size:16})}),e.jsx("button",{onClick:()=>g(!1),className:"text-gray-900 hover:text-gray-600",children:e.jsx(mt,{size:16})})]}):e.jsx("span",{className:"font-semibold text-gray-900 flex-1 text-sm",children:t.title}),e.jsxs("div",{className:"flex items-center gap-1 ml-auto shrink-0",children:[e.jsxs("span",{className:"text-xs text-gray-900",children:[t.steps.length," step",t.steps.length!==1?"s":""]}),e.jsxs(W,{size:"sm",variant:"outline",onClick:T,disabled:t.steps.length===0,className:"h-7 text-xs border-blue-200 text-blue-700 hover:bg-blue-50 gap-1 ml-1",children:[e.jsx(Nt,{size:12})," Review"]}),!s&&e.jsx("button",{onClick:n,className:"p-1 text-gray-900 hover:text-blue-600 transition-colors",children:e.jsx(Ft,{size:14})}),!a&&e.jsx("button",{onClick:l,className:"p-1 text-gray-900 hover:text-blue-600 transition-colors",children:e.jsx(Dt,{size:14})}),e.jsx("button",{onClick:()=>g(!0),className:"p-1 text-gray-900 hover:text-blue-600 transition-colors",children:e.jsx(st,{size:14})}),e.jsx("button",{onClick:m,className:"p-1 text-gray-900 hover:text-red-500 transition-colors",children:e.jsx(_t,{size:14})})]})]}),y&&e.jsxs("div",{className:"divide-y divide-gray-50",children:[t.steps.length===0&&e.jsx("div",{className:"px-8 py-4 text-gray-900 text-sm italic",children:"No steps yet — add one below"}),t.steps.map((P,x)=>e.jsxs("div",{className:"flex items-center gap-3 px-8 py-2.5 hover:bg-gray-50 transition-colors group",children:[e.jsx($t,{size:14,className:"text-gray-900 shrink-0"}),e.jsxs("span",{className:"text-xs text-gray-900 w-5 shrink-0",children:[x+1,"."]}
5),e.jsx(It,{type:P.stepType}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("span",{className:"text-sm text-gray-900 block truncate",children:P.title}),e.jsx(Nr,{step:P,mediaNameMap:S,videoNameMap:h,onPreview:()=>k(P)})]}),P.isRequired&&e.jsx(gt,{variant:"outline",className:"text-xs border-orange-200 text-orange-600 bg-orange-50 hidden group-hover:flex shrink-0",children:"Required"}),e.jsxs("div",{className:"flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity shrink-0",children:[x>0&&e.jsx("button",{onClick:()=>f(t,x),className:"p-1 text-gray-900 hover:text-blue-600",children:e.jsx(Ft,{size:13})}),x<t.steps.length-1&&e.jsx("button",{onClick:()=>j(t,x),className:"p-1 text-gray-900 hover:text-blue-600",children:e.jsx(Dt,{size:13})}),e.jsx("button",{onClick:()=>o(P),className:"p-1 text-gray-900 hover:text-blue-600",children:e.jsx(st,{size:13})}),e.jsx("button",{onClick:()=>u(P.id),className:"p-1 text-gray-900 hover:text-red-500",children:e.jsx(_t,{size:13})})]})]},P.id)),e.jsx("div",{className:"px-8 py-3",children:e.jsxs(W,{size:"sm",variant:"ghost",onClick:()=>c(t.id),className:"text-blue-600 hover:text-blue-700 hover:bg-blue-50 h-8 text-xs gap-1.5",children:[e.jsx(tt,{size:14})," Add Step"]})})]})]})}function Ir({step:t,index:s,apiBase:a,mediaNameMap:n,editing:l,onStartEdit:m,onCancelEdit:d,onSaved:c}){const[o,u]=r.useState(t.title),[f,j]=r.useState(t.isRequired),[k,T]=r.useState(t.videoUrl),[S,h]=r.useState(t.hlsUrl),[y,N]=r.useState(t.pdfUrl),[i,g]=r.useState(t.imageUrl),[R,E]=r.useState(t.audioUrl),[H,P]=r.useState(t.embedCode),[x,L]=r.useState(t.content),[D,q]=r.useState(!1),[Q,J]=r.useState(!1),[ee,K]=r.useState(!1),[V,G]=r.useState("pdf"),[Z,w]=r.useState(!1),M=r.useRef(null);r.useEffect(()=>{l&&(u(t.title),j(t.isRequired),T(t.videoUrl),h(t.hlsUrl),N(t.pdfUrl),g(t.imageUrl),E(t.audioUrl),P(t.embedCode),L(t.content))},[l]);function I(C){const te=`
6
7![](${C})
8
9`,ne=M.current;if(ne){const me=ne.selectionStart??x.length,je=ne.selectionEnd??x.length,_e=x.slice(0,me)+te+x.slice(je);L(_e),requestAnimationFrame(()=>{ne.focus();const De=me+te.length;ne.setSelectionRange(De,De)})}else L(me=>me+te)}async function U(C){const te=C.target.files?.[0];if(te){w(!0);try{const ne=await Ds(te,a);I(ne)}catch{ae({title:"Image upload failed",variant:"destructive"})}finally{w(!1),C.target.value=""}}}async function se(){if(!o.trim()){ae({title:"Step name required",variant:"destructive"});return}q(!0);try{await le.put(`/admin/steps/${t.id}`,{title:o,stepType:t.stepType,sectionId:t.sectionId,videoUrl:k,hlsUrl:S,pdfUrl:y,imageUrl:i,audioUrl:R,embedCode:Ms(H),content:x,isRequired:f}),ae({title:"Step updated"}),c()}catch{ae({title:"Save failed",variant:"destructive"})}finally{q(!1)}}const b="bg-white border-gray-300 text-gray-900 placeholder:text-gray-500",{blobUrl:A,loading:ce,error:v}=he(l?y:t.pdfUrl,"application/pdf"),{blobUrl:F,loading:X,error:z}=he(l?i:t.imageUrl,"image/"),{blobUrl:_}=he(l?R:t.audioUrl),Y=t.stepType!=="quiz"&&t.stepType!=="assignment";return e.jsxs("div",{className:"rounded-xl border border-gray-200 overflow-hidden bg-white",children:[e.jsxs("div",{className:"flex items-center gap-2 px-4 py-2.5 bg-gray-50 border-b border-gray-100 flex-wrap",children:[e.jsxs("span",{className:"text-xs text-gray-900 w-5 shrink-0",children:[s+1,"."]}),e.jsx(It,{type:t.stepType}),l?e.jsx(B,{value:o,onChange:C=>u(C.target.value),className:"h-7 text-sm bg-white border-blue-300 flex-1 min-w-[140px]"}):e.jsx("span",{className:"text-sm font-medium text-gray-900 flex-1 min-w-[140px] truncate",children:t.title}),!l&&t.isRequired&&e.jsx(gt,{variant:"outline",className:"text-xs border-orange-200 text-orange-600 bg-orange-50 shrink-0",children:"Required"}),l&&e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[e.jsx($e,{checked:f,onCheckedChange:j}),e.jsx("span",{className:"text-xs text-gray-900",children:"Required"})]}),e.jsx("div",{className:"flex items-center gap-1 shrink-0",children:l?e.jsxs(e.Fragment,{children:[e.jsx(W,{size:"sm",variant:"outline",onClick:d,disabled:D,className:"h-7 text-xs border-gray-300 text-gray-900",children:"Cancel"}),e.jsx(W,{size:"sm",onClick:se,disabled:D,className:"h-7 text-xs bg-blue-600 hover:bg-blue-500",children:D?"Saving…":"Save"})]}):Y?e.jsxs(W,{size:"sm",variant:"ghost",onClick:m,className:"h-7 text-xs text-blue-600 hover:text-blue-700 hover:bg-blue-50 gap-1",children:[e.jsx(st,{size:12})," Edit"]}):null})]}),e.jsxs("div",{className:"p-4",children:[!l&&e.jsxs(e.Fragment,{children:[t.stepType==="video"&&(t.videoUrl?e.jsx("div",{className:"rounded-lg overflow-hidden border border-gray-200",style:{aspectRatio:"16/9",maxWidth:480},children:e.jsx("iframe",{src:t.videoUrl,className:"w-full h-full",allow:"autoplay; encrypted-media",allowFullScreen:!0,style:{border:"none"},title:t.title})}):e.jsx(oe,{label:"No video URL set",icon:e.jsx(xt,{size:24,className:"text-gray-900"})})),t.stepType==="pdf"&&(ce?e.jsx(ye,{}):v?e.jsx(ke,{label:"Couldn't load this PDF — the file may be missing or the link is broken."}):A?e.jsx("div",{className:"rounded-lg overflow-hidden border border-gray-200",style:{height:420},children:e.jsx("iframe",{src:A,className:"w-full h-full",style:{border:"none"},title:"PDF"})}):e.jsx(oe,{label:"No PDF file set",icon:e.jsx(de,{size:24,className:"text-gray-900"})})),(t.stepType==="image"||t.stepType==="gallery")&&(X?e.jsx(ye,{}):z?e.jsx(ke,{label:"Couldn't load this image — the file may be missing or the link is broken."}):F?e.jsx("img",{src:F,alt:"Preview",className:"rounded-lg border border-gray-200 object-contain",style:{maxHeight:320}}):e.jsx(oe,{label:"No image set",icon:e.jsx(Me,{size:24,className:"text-gray-900"})})),t.stepType==="audio"&&(_?e.jsx("audio",{controls:!0,src:_,className:"w-full max-w-md"}):e.jsx(oe,{label:"No audio file set",icon:e.jsx(ve,{size:24,className:"text-gray-900"})})),(t.stepType==="text"||t.stepType==="content")&&e.jsx(Be,{content:t.content}),t.stepType==="embed"&&(()=>{const C=Tt(t.embedCode);return C?.kind==="iframe"?e.jsx("iframe",{src:C.src,width:C.width,height:C.height,style:{maxWidth:"100%",border:0}
9,loading:"lazy",referrerPolicy:"strict-origin-when-cross-origin",sandbox:kt,title:"Lesson embed",allow:"fullscreen; encrypted-media; picture-in-picture",className:"w-full"}):C?.kind==="quiz"?e.jsxs("div",{className:"text-sm text-gray-900",children:["Linked quiz: ",C.id]}):e.jsx(oe,{label:"No embed code set",icon:e.jsx(wt,{size:24,className:"text-gray-900"})})})(),t.stepType==="link"&&(t.videoUrl?e.jsxs("a",{href:t.videoUrl,target:"_blank",rel:"noreferrer",className:"flex items-center gap-2 text-blue-600 text-sm hover:underline break-all",children:[e.jsx(pt,{size:14,className:"shrink-0"}),t.videoUrl]}):e.jsx(oe,{label:"No URL set",icon:e.jsx(St,{size:24,className:"text-gray-900"})})),t.stepType==="quiz"&&e.jsx(Fs,{lessonId:t.id}),t.stepType==="assignment"&&e.jsx(oe,{label:"Assignment — managed in Assignments tab",icon:e.jsx(ze,{size:24,className:"text-amber-300"})})]}),l&&e.jsxs("div",{className:"space-y-3",children:[t.stepType==="video"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(O,{className:"text-gray-900 text-sm",children:"Video URL"}),e.jsxs("button",{type:"button",onClick:()=>J(!0),className:"flex items-center gap-1.5 text-xs text-blue-600 hover:text-blue-700 font-medium border border-blue-200 bg-blue-50 hover:bg-blue-100 px-2.5 py-1 rounded-lg transition-colors",children:[e.jsx(Ht,{size:12})," Browse Media Library"]})]}),e.jsx(B,{value:k,onChange:C=>T(C.target.value),className:`${b} font-mono text-sm`}),e.jsx(O,{className:"text-gray-900 text-sm",children:"HLS URL (optional)"}),e.jsx(B,{value:S,onChange:C=>h(C.target.value),className:`${b} font-mono text-sm`}),k&&e.jsx("div",{className:"rounded-lg overflow-hidden border border-gray-200 mt-1",style:{aspectRatio:"16/9",maxWidth:420},children:e.jsx("iframe",{src:k,className:"w-full h-full",allow:"autoplay; encrypted-media",allowFullScreen:!0,style:{border:"none"},title:"Video preview"})}),e.jsx(Wt,{open:Q,onClose:()=>J(!1),onSelect:(C,te)=>{T(C),h(te)}})]}),t.stepType==="pdf"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs(W,{type:"button",variant:"outline",className:"border-blue-200 text-blue-700 hover:bg-blue-50 gap-1.5",onClick:()=>{G("pdf"),K(!0)},children:[e.jsx(de,{size:15})," Browse Media Library"]}),y&&e.jsxs("span",{className:"text-xs text-emerald-600 truncate max-w-[220px]",children:["✓ ",it(y,n)]})]}),e.jsx(B,{value:y,onChange:C=>N(C.target.value),placeholder:"or paste URL",className:`${b} font-mono text-sm`}),y&&e.jsx("div",{className:"rounded-lg overflow-hidden border border-gray-200",style:{height:320},children:ce?e.jsx(ye,{}):v?e.jsx(ke,{label:"Couldn't load this PDF — the file may be missing or the link is broken."}):A&&e.jsx("iframe",{src:A,className:"w-full h-full",style:{border:"none"},title:"PDF preview"})})]}),(t.stepType==="image"||t.stepType==="gallery")&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs(W,{type:"button",variant:"outline",className:"border-blue-200 text-blue-700 hover:bg-blue-50 gap-1.5",onClick:()=>{G("image"),K(!0)},children:[e.jsx(Ae,{size:15})," Browse Media Library"]}),i&&e.jsx("span",{className:"text-xs text-emerald-600",children:"✓ Image selected"})]}),e.jsx(B,{value:i,onChange:C=>g(C.target.value),placeholder:"or paste image URL",className:`${b} font-mono text-sm`}),i&&(X?e.jsx(ye,{}):z?e.jsx(ke,{label:"Couldn't load this image — the file may be missing or the link is broken."}):F&&e.jsx("img",{src:F,alt:"Preview",className:"rounded-lg border border-gray-200 object-contain",style:{maxHeight:280}}))]}),t.stepType==="audio"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs(W,{type:"button",variant:"outline",className:"border-blue-200 text-blue-700 hover:bg-blue-50 gap-1.5",onClick:()=>{G("audio"),K(!0)},children:[e.jsx(ve,{size:15})," Browse Media Library"]}),R&&e.jsxs("span",{className:"text-xs text-emerald-600 truncate max-w-[220px]",children:["✓ ",it(R,n)]})]}),e.jsx(B,{value:R,onChange:C=>E(C.target.value),placeholder:"or paste audio URL",className:`${b} font-mono text-sm`}),R&&(_?e.jsx("audio",{controls:!0,src:_,className:"w-full max-w-md"}):e.jsx(ye,{}))]}),(t.stepType==="text"||t.stepType==="content")&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(O,{className:"text-gray-900 text-sm",children:"Class Notes / Content"}),e.jsxs("label",{className:"flex items-center gap-1.5 text-xs text-blue-600 hover:text-blue-700 font-medium border border-blue-200 bg-blue-50 hover:bg-blue-100 px-2.5 py-1 rounded-lg transition-colors cursor-pointer",children:[e.jsx(Ae,{size:12})," ",Z?"Uploading…":"Insert Image",e.jsx("input",{type:"file",accept:"image/*",className:"hidden",onChange:U,disabled:Z})]})]}),e.jsx(Ue,{ref:M,value:x,onChange:C=>L(C.target.value),className:`${b} min-h-[120px]`}),e.jsxs("div",{className:"rounded-lg border border-gray-200 bg-gray-50 p-3",children:[e.jsx("span",{className:"text-[11px] font-semibold text-gray-900 uppercase tracking-wide",children:"Preview"}),e.jsx("div",{className:"mt-2",children:e.jsx(Be,{content:x})})]})]}),t.stepType==="embed"&&e.jsx(Ue,{value:H,onChange:C=>P(C.target.value),className:`${b} font-mono text-sm min-h-[100px]`}),t.stepType==="link"&&e.jsxs(e.Fragment,{children:[e.jsx(O,{className:"text-gray-900 text-sm",children:"URL"}),e.jsx(B,{value:k,onChange:C=>T(C.target.value),className:`${b} font-mono text-sm`}),e.jsx(O,{className:"text-gray-900 text-sm",children:"Description"}),e.jsx(B,{value:x,onChange:C=>L(C.target.value),className:b})]}),e.jsx(zs,{open:ee,type:V,onClose:()=>K(!1),onSelect:(C,te)=>{V==="pdf"?N(C):V==="image"?g(C):V==="audio"&&E(C),ae({title:"File selected",description:te})}})]})]})]})}function Pr({open:t,onClose:s,section:a,apiBase:n,mediaNameMap:l,onSave:m}){const[d,c]=r.useState(null);return r.useEffect(()=>{t||c(null)},[t]),e.jsx(ft,{open:t,onOpenChange:o=>{o||s()},children:e.jsxs(bt,{className:"max-w-3xl bg-white border-gray-200 text-gray-900 max-h-[90vh] overflow-y-auto",children:[e.jsx(yt,{children:e.jsxs(vt,{className:"text-gray-900",children:["Review & Edit — ",a?.title]})}),e.jsxs("div",{className:"space-y-4 py-2",children:[a&&a.steps.length===0&&e.jsx("p",{className:"text-sm text-gray-900 italic py-8 text-center",children:"No steps in this section yet."}),a?.steps.map((o,u)=>e.jsx(Ir,{step:o,index:u,apiBase:n,mediaNameMap:l,editing:d===o.id,onStartEdit:()=>c(o.id),onCancelEdit:()=>c(null),onSaved:()=>{c(null),m()}},o.id))]}),e.jsx(qt,{children:e.jsx(W,{variant:"outline",onClick:s,className:"border-gray-300 text-gray-900",children:"Close"})})]})})}function Rr({courseId:t,course:s,onSaved:a}){const[n,l]=r.useState(s?.title??""),[m,d]=r.useState(s?.description??""),[c,o]=r.useState(s?.thumbnail??""),[u,f]=r.useState(null),[j,k]=r.useState(s?.price!=null?String(s.price):""),[T,S]=r.useState(s?.priceLabel??""),[h,y]=r.useState(s?.status??"draft"),[N,i]=r.useState(s?.paceType??"self-paced"),[g,R]=r.useState(s?.duration??"No Time Limit"),[E,H]=r.useState(s?.scheduledStart?s.scheduledStart.split("T")[0]:""),[P,x]=r.useState(s?.scheduledEnd?s.scheduledEnd.split("T")[0]:""),[L,D]=r.useState(s?.lessonCompletionOrder??"any"),[q,Q]=r.useState(s?.videoWatchRequired??!1),[J,ee]=r.useState(s?.videoWatchPercent??80),[K,V]=r.useState(s?.autoplayNext??!1),[G,Z]=r.useState(!1);r.useEffect(()=>{s&&(l(s.title??""),d(s.description??""),o(s.thumbnail??""),k(s.price!=null?String(s.price):""),S(s.priceLabel??""),y(s.status??"draft"),i(s.paceType??"self-paced"),R(s.duration??"No Time Limit"),H(s.scheduledStart?s.scheduledStart.split("T")[0]:""),x(s.scheduledEnd?s.scheduledEnd.split("T")[0]:""),D(s.lessonCompletionOrder??"any"),Q(s.videoWatchRequired??!1),ee(s.videoWatchPercent??80),V(s.autoplayNext??!1))},[s]);async function w(){if(!u)return;const b=new FormData;return b.append("file",u),(await le.upload("/admin/upload",b)).data?.url}
9async function M(){if(!n.trim()){ae({title:"Title is required",variant:"destructive"});return}Z(!0);try{let b=c;const A=await w();A&&(b=A,o(A));const ce={title:n,description:m,thumbnail:b,price:j?Number(j):null,priceLabel:T,status:h,paceType:N,duration:g,scheduledStart:E||null,scheduledEnd:P||null,lessonCompletionOrder:L,videoWatchRequired:q,videoWatchPercent:J,autoplayNext:K},v=await le.patch(`/admin/course/${t}`,ce);ae({title:"Course details saved!"}),v.data&&a(v.data)}catch(b){ae({title:"Save failed",description:b.message,variant:"destructive"})}finally{Z(!1)}}const I="bg-white border-gray-300 text-gray-900 placeholder:text-gray-500",U="text-gray-900 text-sm",se="w-full bg-white border border-gray-300 text-gray-900 text-sm rounded-md px-3 py-2 focus:outline-none focus:ring-2 focus:ring-blue-500";return e.jsxs("div",{className:"space-y-6 max-w-2xl",children:[e.jsxs(Ke,{className:"bg-white border-gray-200 shadow-sm",children:[e.jsx(Ge,{children:e.jsx(Ye,{className:"text-gray-900",children:"Course Info"})}),e.jsxs(Ze,{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx(O,{className:U,children:"Title *"}),e.jsx(B,{value:n,onChange:b=>l(b.target.value),className:`${I} mt-1`,placeholder:"Introduction to Vedic Astrology"})]}),e.jsxs("div",{children:[e.jsx(O,{className:U,children:"Description"}),e.jsx(Ue,{value:m,onChange:b=>d(b.target.value),className:`${I} mt-1`,rows:3,placeholder:"Describe what students will learn..."})]}),e.jsxs("div",{children:[e.jsx(O,{className:U,children:"Thumbnail Image"}),e.jsxs("div",{className:"space-y-2 mt-1",children:[e.jsx(B,{type:"file",accept:"image/*",onChange:b=>{const A=b.target.files?.[0];A&&(f(A),o(URL.createObjectURL(A)))},className:"bg-white border-gray-300 text-gray-900 file:mr-2 file:rounded file:border-0 file:bg-blue-600 file:text-white file:text-xs file:px-2 file:py-1"}),e.jsx("p",{className:"text-xs text-gray-900",children:"Or paste a URL:"}),e.jsx(B,{value:c,onChange:b=>o(b.target.value),className:I,placeholder:"https://..."}),c&&e.jsx("img",{src:c,alt:"thumbnail preview",className:"h-20 rounded-lg object-cover border border-gray-200"})]})]})]})]}),e.jsxs(Ke,{className:"bg-white border-gray-200 shadow-sm",children:[e.jsx(Ge,{children:e.jsx(Ye,{className:"text-gray-900",children:"Publishing & Pricing"})}),e.jsxs(Ze,{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(O,{className:U,children:"Status"}),e.jsxs("select",{value:h,onChange:b=>y(b.target.value),className:`${se} mt-1`,children:[e.jsx("option",{value:"draft",children:"Draft"}),e.jsx("option",{value:"published",children:"Published"}),e.jsx("option",{value:"active",children:"Active"}),e.jsx("option",{value:"ended",children:"Ended"})]})]}),e.jsxs("div",{children:[e.jsx(O,{className:U,children:"Pace Type"}),e.jsxs("select",{value:N,onChange:b=>i(b.target.value),className:`${se} mt-1`,children:[e.jsx("option",{value:"self-paced",children:"Self-Paced"}),e.jsx("option",{value:"scheduled",children:"Scheduled / Batch"})]})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(O,{className:U,children:"Price (₹) — leave blank for free"}),e.jsx(B,{type:"number",value:j,onChange:b=>k(b.target.value),className:`${I} mt-1`,placeholder:"5999",min:"0"})]}),e.jsxs("div",{children:[e.jsx(O,{className:U,children:"Price Label (display text)"}),e.jsx(B,{value:T,onChange:b=>S(b.target.value),className:`${I} mt-1`,placeholder:"₹5,999/month"})]})]}),e.jsxs("div",{children:[e.jsx(O,{className:U,children:"Duration"}),e.jsx(B,{value:g,onChange:b=>R(b.target.value),className:`${I} mt-1`,placeholder:"6 Months / No Time Limit"})]}),N==="scheduled"&&e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(O,{className:U,children:"Batch Start Date"}),e.jsx(B,{type:"date",value:E,onChange:b=>H(b.target.value),className:`${I} mt-1`})]}),e.jsxs("div",{children:[e.jsx(O,{className:U,children:"Batch End Date"}),e.jsx(B,{type:"date",value:P,onChange:b=>x(b.target.value),className:`${I} mt-1`})]})]})]})]}),e.jsxs(Ke,{className:"bg-white border-gray-200 shadow-sm",children:[e.jsxs(Ge,{children:[e.jsx(Ye,{className:"text-gray-900",children:"Content"}),e.jsx("p",{className:"text-sm text-gray-900",children:"Choose how participants complete steps and what they can view."})]}),e.jsxs(Ze,{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-gray-900 mb-3",children:"Step order and visibility"}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("label",{className:`flex items-start gap-3 p-3 rounded-xl border cursor-pointer transition-colors ${L==="any"?"border-blue-400 bg-blue-50":"border-gray-200 hover:border-gray-300"}`,children:[e.jsx("input",{type:"radio",name:"lessonCompletionOrder",value:"any",checked:L==="any",onChange:()=>D("any"),className:"mt-0.5 accent-blue-600"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-gray-900",children:"Any order"}),e.jsx("p",{className:"text-xs text-gray-900 mt-0.5",children:"Participants can complete steps in any order and view all step content."})]})]}),e.jsxs("label",{className:`flex items-start gap-3 p-3 rounded-xl border cursor-pointer transition-colors ${L==="sequential"?"border-blue-400 bg-blue-50":"border-gray-200 hover:border-gray-300"}`,children:[e.jsx("input",{type:"radio",name:"lessonCompletionOrder",value:"sequential",checked:L==="sequential",onChange:()=>D("sequential"),className:"mt-0.5 accent-blue-600"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-gray-900",children:"In order"}),e.jsx("p",{className:"text-xs text-gray-900 mt-0.5",children:"Participants must complete steps one after another. Future steps are locked until previous ones are done."})]})]})]})]}),e.jsx("hr",{className:"border-gray-100"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-gray-900 mb-3",children:"Video step"}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-gray-900",children:"Make watching videos required"}),e.jsx("p",{className:"text-xs text-gray-900 mt-0.5",children:"Students must watch a set percentage before marking complete."}),q&&e.jsxs("div",{className:"mt-2 flex items-center gap-2",children:[e.jsx("input",{type:"range",min:10,max:100,step:5,value:J,onChange:b=>ee(Number(b.target.value)),className:"w-32 accent-blue-600"}),e.jsxs("span",{className:"text-sm font-semibold text-blue-600 w-10",children:[J,"%"]})]})]}),e.jsx($e,{checked:q,onCheckedChange:Q})]}),e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-gray-900",children:"Autoplay next video step"}),e.jsx("p",{className:"text-xs text-gray-900 mt-0.5",children:"When a video step ends, the next one starts automatically."})]}),e.jsx($e,{checked:K,onCheckedChange:V})]})]})]})]})]}),e.jsx(W,{onClick:M,disabled:G,className:"w-full bg-blue-600 hover:bg-blue-700 h-11 text-base",children:G?"Saving...":"Save Changes"})]})}function sn(){const{id:t}=ia(),s=Number(t),[a,n]=r.useState(null),[l,m]=r.useState([]),[d,c]=r.useState(!0),[o,u]=r.useState(!1),[f,j]=r.useState(""),[k,T]=r.useState({open:!1}),[S,h]=r.useState("curriculum"),[y,N]=r.useState(null),[i,g]=r.useState(null),[R,E]=r.useState({}),[H,P]=r.useState({});async function x(){try{const[w,M,I,U]=await Promise.all([le.get(`/courses/${s}`),le.get(`/admin/courses/${s}/sections`),le.get("/admin/media/files").catch(()=>({data:[]})),le.get("/admin/media/videos").catch(()=>({data:null}))]);n(w.data??null),m(M.data??[]);const se={};
9(I.data??[]).forEach(A=>{se[`${Pe}/storage${A.objectPath}`]=A.name}),E(se);const b={};(U.data?.items??[]).forEach(A=>{A.guid&&A.title&&(b[A.guid]=A.title)}),P(b)}finally{c(!1)}}r.useEffect(()=>{x()},[s]);async function L(){f.trim()&&(await le.post(`/admin/courses/${s}/sections`,{title:f.trim()}),j(""),u(!1),x())}async function D(w,M){await le.put(`/admin/sections/${w}`,{title:M}),x()}async function q(w){confirm("Delete this section and all its steps?")&&(await le.delete(`/admin/sections/${w}`),x())}async function Q(w,M){const I=[...l],U=M==="up"?w-1:w+1;[I[w],I[U]]=[I[U],I[w]],await le.post("/admin/sections/reorder",{items:I.map((se,b)=>({id:se.id,sectionOrder:b}))}),x()}async function J(w){confirm("Delete this step?")&&(await le.delete(`/admin/steps/${w}`),x())}async function ee(w,M,I){const U=[...w.steps],se=I==="up"?M-1:M+1;[U[M],U[se]]=[U[se],U[M]],await le.post(`/admin/sections/${w.id}/steps/reorder`,{items:U.map((b,A)=>({id:b.id,lessonOrder:A}))}),x()}const K=l.reduce((w,M)=>w+M.steps.length,0),V="flex items-center gap-2 px-4 py-2 rounded-lg text-sm font-medium transition-colors",G="bg-blue-600 text-white shadow-sm",Z="text-gray-900 hover:text-gray-700 hover:bg-gray-100";return e.jsxs(ua,{children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm text-gray-900 mb-4",children:[e.jsx(zt,{href:"/admin/courses",children:e.jsx("span",{className:"hover:text-blue-600 cursor-pointer text-gray-900",children:"Courses"})}),e.jsx(et,{size:14}),e.jsx("span",{className:"text-gray-900 truncate max-w-xs",children:a?.title??"..."}),e.jsx(et,{size:14}),e.jsx("span",{className:"text-blue-600 font-medium",children:S==="curriculum"?"Builder":"Course Details"})]}),e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3 mb-5",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("h1",{className:"text-2xl font-bold text-gray-900 truncate",children:a?.title??"Course Manager"}),e.jsxs("p",{className:"text-gray-900 text-sm mt-1",children:[l.length," section",l.length!==1?"s":""," · ",K," step",K!==1?"s":""]})]}),e.jsx("div",{className:"flex gap-2 shrink-0",children:e.jsx(zt,{href:`/admin/courses/${s}/assignments`,children:e.jsxs(W,{variant:"outline",className:"border-gray-200 text-gray-900 hover:bg-gray-50 gap-2",children:[e.jsx(ze,{size:16})," Assignments"]})})})]}),e.jsxs("div",{className:"flex gap-1 p-1 bg-gray-100 rounded-xl w-fit mb-6",children:[e.jsxs("button",{onClick:()=>h("curriculum"),className:`${V} ${S==="curriculum"?G:Z}`,children:[e.jsx(ja,{size:15})," Curriculum"]}),e.jsxs("button",{onClick:()=>h("details"),className:`${V} ${S==="details"?G:Z}`,children:[e.jsx(ma,{size:15})," Course Details"]})]}),S==="curriculum"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsx("p",{className:"text-sm text-gray-900",children:"Add sections to organise your course, then add steps inside each section."}),e.jsxs(W,{onClick:()=>u(!0),className:"bg-blue-600 hover:bg-blue-500 gap-2",children:[e.jsx(tt,{size:16})," Add Section"]})]}),o&&e.jsx("div",{className:"bg-white border border-gray-200 rounded-xl p-4 mb-4 shadow-sm",children:e.jsxs("div",{className:"flex gap-3",children:[e.jsx(B,{value:f,onChange:w=>j(w.target.value),onKeyDown:w=>{w.key==="Enter"&&L(),w.key==="Escape"&&(u(!1),j(""))},placeholder:"Section title, e.g. Introduction and Revision",autoFocus:!0,className:"bg-white border-gray-300 text-gray-900"}),e.jsx(W,{onClick:L,className:"bg-blue-600 hover:bg-blue-500 shrink-0",children:"Add"}),e.jsx(W,{variant:"outline",onClick:()=>{u(!1),j("")},className:"border-gray-300 text-gray-900 shrink-0",children:"Cancel"})]})}),d?e.jsx("div",{className:"space-y-3",children:[1,2,3].map(w=>e.jsx(ba,{className:"h-20 bg-gray-100 rounded-xl"},w))}):l.length===0?e.jsx("div",{className:"bg-white border border-gray-200 rounded-xl shadow-sm",children:e.jsxs("div",{className:"py-16 text-center",children:[e.jsx(ut,{size:40,className:"text-gray-900 mx-auto mb-3"}),e.jsx("p",{className:"text-gray-900 mb-4",children:"No sections yet. Add your first section to start building the course."}),e.jsxs(W,{onClick:()=>u(!0),className:"bg-blue-600 hover:bg-blue-500 gap-2",children:[e.jsx(tt,{size:16})," Add First Section"]})]})}):e.jsxs("div",{className:"flex flex-col lg:flex-row gap-4 items-start",children:[e.jsx("div",{className:"flex-1 min-w-0 space-y-4",children:l.map((w,M)=>e.jsx(Tr,{section:w,isFirst:M===0,isLast:M===l.length-1,onMoveUp:()=>Q(M,"up"),onMoveDown:()=>Q(M,"down"),onDelete:()=>q(w.id),onRename:I=>D(w.id,I),onAddStep:I=>T({open:!0,sectionId:I}),onEditStep:I=>T({open:!0,editStep:I,sectionId:I.sectionId??w.id}),onDeleteStep:J,onMoveStepUp:(I,U)=>ee(I,U,"up"),onMoveStepDown:(I,U)=>ee(I,U,"down"),onPreviewStep:I=>N(U=>U?.id===I.id?null:I),onReview:()=>g(w.id),mediaNameMap:R,videoNameMap:H},w.id))}),y&&e.jsx(Cr,{step:y,onClose:()=>N(null)})]})]}),S==="details"&&e.jsx(Rr,{courseId:s,course:a,onSaved:w=>n(w)}),e.jsx(kr,{open:k.open,onClose:()=>T({open:!1}),sections:l,editStep:k.editStep,defaultSectionId:k.sectionId,apiBase:Pe,onSave:x}),e.jsx(Pr,{open:i!==null,onClose:()=>g(null),section:l.find(w=>w.id===i)??null,apiBase:Pe,mediaNameMap:R,onSave:x})]})}export{sn 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.