1import{a as e}from"./rolldown-runtime-CCT_m2FY.js";import{d as t,f as r}from"./react-Fyjr9G8a.js";import{At as s,E as n,F as a,M as l,S as o,Z as i,at as c,dt as u,h as d,i as m,kt as x,l as p,ot as f,r as b,vt as h,x as y,z as v}from"./lucide-Du5NTjuW.js";import{l as g}from"./motion-DIT2RfQy.js";import{n as w}from"./utils-CbNGOHui.js";import{l as j,p as N}from"./api-CDoApT6I.js";var k=e(s(),1),C=g(),S=[.25,.5,.75,1,1.25,1.5,1.75,2];function T(e){const t=Math.floor(e/3600),r=Math.floor(e%3600/60),s=Math.floor(e%60);return t>0?`${t}:${r.toString().padStart(2,"0")}:${s.toString().padStart(2,"0")}`:`${r}:${s.toString().padStart(2,"0")}`}function z(e,t,r){return Math.max(t,Math.min(r,e))}function E({videoId:e,title:t,description:r}){const[s,i]=(0,k.useState)(!1),[c,u]=(0,k.useState)(!1),[x,p]=(0,k.useState)(!1),[f,h]=(0,k.useState)(0),[g,j]=(0,k.useState)(0),[N,E]=(0,k.useState)(1),[R,L]=(0,k.useState)(!0),[I,M]=(0,k.useState)(!1),[D,F]=(0,k.useState)(!1),[$,P]=(0,k.useState)(!1),[Y,A]=(0,k.useState)(!1),[B,_]=(0,k.useState)(0),[U,V]=(0,k.useState)(null),[X,q]=(0,k.useState)(!1),G=(0,k.useRef)(null),K=(0,k.useRef)(null),W=(0,k.useRef)(null),H=(0,k.useRef)(null),Q=(0,k.useRef)(null),Z=(0,k.useRef)(null),J=(0,k.useRef)(null),O=(0,k.useRef)(null),ee=(0,k.useRef)(!1),te=(0,k.useRef)(!0),re=(0,k.useRef)(0),se=(0,k.useRef)(null),ne=(0,k.useRef)(0),ae=(0,k.useRef)(!1),le=(0,k.useRef)(!1);(0,k.useEffect)(()=>{ne.current=g},[g]),(0,k.useEffect)(()=>{ae.current=c},[c]),(0,k.useEffect)(()=>{le.current=Y},[Y]);const oe=(0,k.useCallback)(()=>{Q.current||(Q.current=setInterval(()=>{te.current&&G.current&&!le.current&&h(G.current.getCurrentTime())},100))},[]),ie=(0,k.useCallback)(()=>{Q.current&&(clearInterval(Q.current),Q.current=null)},[]),ce=(0,k.useCallback)((e=3e3)=>{L(!0),Z.current&&clearTimeout(Z.current),Z.current=setTimeout(()=>{te.current&&L(!1)},e)},[]),ue=(0,k.useCallback)(()=>{te.current=!1,ie();for(const e of[Z,J,se,O])e.current&&(clearTimeout(e.current),e.current=null);if(document.body.classList.remove("fullscreen-active"),G.current?.destroy){try{G.current.destroy()}catch{}G.current=null}},[ie]),de=(0,k.useCallback)(()=>{K.current&&!G.current&&window.YT?.Player&&(G.current=new window.YT.Player(K.current,{height:"100%",width:"100%",videoId:e,host:"https://www.youtube.com",playerVars:{controls:0,rel:0,modestbranding:1,fs:0,cc_load_policy:0,iv_load_policy:3,playsinline:1,enablejsapi:1,disablekb:1,autoplay:0,origin:"https://logic.lk"},events:{onReady:e=>{if(!te.current)return;const t=e.target;i(!0),j(t.getDuration())},onStateChange:e=>{if(!te.current)return;const t=e.data===window.YT.PlayerState.PLAYING,r=e.data===window.YT.PlayerState.BUFFERING,s=e.data===window.YT.PlayerState.ENDED;if((t||r)&&(O.current&&(clearTimeout(O.current),O.current=null),ee.current=!0,q(!1)),u(t),P(s),t){P(!1),oe();const e=G.current?.getDuration()??0;e>0&&j(e)}else ie()},onError:e=>{te.current&&(2!==e.data&&5!==e.data&&100!==e.data&&101!==e.data&&150!==e.data||q(!0))}}}))},[e,oe,ie]);(0,k.useEffect)(()=>{if(te.current=!0,window.YT?.Player)return de(),ue;const e=setInterval(()=>{window.YT?.Player&&(clearInterval(e),de())},100);if(!document.querySelector('script[src*="youtube.com/iframe_api"]')){const e=document.createElement("script");e.src="https://www.youtube.com/iframe_api",document.head.appendChild(e)}return window.onYouTubeIframeAPIReady=()=>{clearInterval(e),de()},()=>{clearInterval(e),ue()}},[de,ue]),(0,k.useEffect)(()=>{const e=()=>{const e=!!document.fullscreenElement;M(e),e||document.body.classList.remove("fullscreen-active")};return document.addEventListener("fullscreenchange",e),document.addEventListener("webkitfullscreenchange",e),()=>{document.removeEventListener("fullscreenchange",e),document.removeEventListener("webkitfullscreenchange",e)}},[]),(0,k.useEffect)(()=>{if(!D)return;const e=e=>{e.target.closest(".menu-panel")||F(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[D]);const me=(0,k.useCallback)(e=>{if(!H.current)return 0;const t=H.current.getBoundingClientRect();return z((e-t.left)/t.width,0,1)*ne.current},[]);(0,k.useEffect)(()=>
1{if(!Y)return;const e=e=>{_(me(e.clientX))},t=e=>{const t=me(e.clientX);G.current?.seekTo(t,!0),h(t),A(!1),ae.current&&oe()};return window.addEventListener("mousemove",e),window.addEventListener("mouseup",t),()=>{window.removeEventListener("mousemove",e),window.removeEventListener("mouseup",t)}},[Y,me,oe]);const xe=(0,k.useCallback)(()=>{G.current&&(ae.current?G.current.pauseVideo():(G.current.playVideo(),ee.current||(O.current&&clearTimeout(O.current),O.current=setTimeout(()=>{te.current&&!ee.current&&q(!0)},8e3))))},[]),pe=(0,k.useCallback)(()=>{G.current&&(G.current.isMuted()?(G.current.unMute(),p(!1)):(G.current.mute(),p(!0)))},[]),fe=(0,k.useCallback)(e=>{if(!G.current)return;const t=z(G.current.getCurrentTime()+e,0,ne.current);G.current.seekTo(t,!0),h(t),V(e>0?"fwd":"bwd"),J.current&&clearTimeout(J.current),J.current=setTimeout(()=>{te.current&&V(null)},900)},[]),be=(0,k.useCallback)(e=>{G.current&&(G.current.setPlaybackRate(e),E(e),F(!1))},[]),he=(0,k.useCallback)(async()=>{const e=W.current;if(e)if(w()||"function"!=typeof e.requestFullscreen)M(e=>{const t=!e;return document.body.classList.toggle("fullscreen-active",t),t});else try{document.fullscreenElement?(document.body.classList.remove("fullscreen-active"),await document.exitFullscreen()):(document.body.classList.add("fullscreen-active"),await e.requestFullscreen())}catch(t){document.body.classList.remove("fullscreen-active")}},[]),ye=(0,k.useCallback)(()=>{G.current&&(G.current.seekTo(0,!0),G.current.playVideo(),P(!1),h(0))},[]),ve=(0,k.useCallback)(()=>{if(O.current&&(clearTimeout(O.current),O.current=null),G.current?.destroy){try{G.current.destroy()}catch{}G.current=null}ee.current=!1,q(!1),i(!1),u(!1),P(!1),h(0),de()},[de]);(0,k.useEffect)(()=>{const e=e=>{if(!G.current)return;const t=e.target;"INPUT"!==t.tagName&&"TEXTAREA"!==t.tagName&&(D||("Space"===e.code?(e.preventDefault(),xe()):"ArrowRight"===e.code?(e.preventDefault(),fe(10)):"ArrowLeft"===e.code?(e.preventDefault(),fe(-10)):"KeyF"===e.code?(e.preventDefault(),he()):"KeyM"===e.code&&(e.preventDefault(),pe())))};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[D,xe,fe,he,pe]);const ge=(0,k.useCallback)(e=>{const t=e.target;if(t.closest("button")||t.closest(".menu-panel"))return;const r=Date.now(),s=r-re.current;if(se.current&&(clearTimeout(se.current),se.current=null),s<350&&s>30)return re.current=0,fe(10),void ce();re.current=r,se.current=setTimeout(()=>{te.current&&(R?xe():ce())},300)},[fe,ce,R,xe]),we=Y?B:f,je=g>0?we/g*100:0;return(0,C.jsx)("div",{className:"w-full bg-black",children:(0,C.jsxs)("div",{ref:W,className:"relative w-full bg-black overflow-hidden select-none",style:I?{position:"fixed",inset:0,zIndex:9999,width:"100vw",height:"100dvh"}:{paddingTop:"56.25%"},onMouseMove:()=>ce(),onMouseLeave:()=>{Z.current&&clearTimeout(Z.current),c&&L(!1)},children:[(0,C.jsx)("div",{ref:K,className:"absolute inset-0 w-full h-full",style:{pointerEvents:X?"auto":"none"}}),!X&&(0,C.jsx)("div",{className:"absolute top-0 left-0 right-0 h-14 bg-gradient-to-b from-black/70 to-transparent z-10 pointer-events-none"}),!s&&!X&&(0,C.jsx)("div",{className:"absolute inset-0 flex items-center justify-center bg-black z-10",children:(0,C.jsx)("div",{className:"size-10 rounded-full border-4 border-white/10 border-t-primary animate-spin"})}),X&&(0,C.jsx)("div",{className:"absolute top-0 left-0 right-0 z-50 bg-black/85 backdrop-blur-sm border-b border-white/10 px-3 py-2 sm:px-4 sm:py-3 pointer-events-none",children:(0,C.jsxs)("div",{className:"flex items-center gap-2 sm:gap-3",children:[(0,C.jsx)(d,{className:"size-4 sm:size-5 text-white/80 shrink-0"}),(0,C.jsx)("p",{className:"flex-1 min-w-0 text-white text-[11px] sm:text-xs leading-snug",children:"YouTube is asking to verify your account. Sign in in a new tab, then come back and tap Retry."}),(0,C.jsxs)("button",{type:"button",onClick:()=>window.open("https://accounts.google.com/ServiceLogin?service=youtube&continue=https%3A%2F%2Fwww.youtube.com%2F","_blank","noopener,noreferrer"),className:"shrink-0 inline-flex items-center gap-1 sm:gap-1.5 px-2.5 sm:px-3 py-1 sm:py-1.5 rounded-md text-white text-[11px] sm:text-xs font-semibold transition-transform active:scale-95 pointer-events-auto bg-white/10 hover:bg-white/20 border border-white/20",children:[(0,C.jsx)(v,{className:"size-3 sm:size-3.5"}),"Sign in"]}),(0,C.jsxs)("button",{type:"button",onClick:ve,className:"shrink-0 inline-flex items-center gap-1 sm:gap-1.5 px-2.5 sm:px-3 py-1 sm:py-1.5 rounded-md text-white text-[11px] sm:text-xs font-semibold transition-transform active:scale-95 pointer-events-auto",style:{backgroundColor:"var(--color-primary)"},children:[(0,C.jsx)(y,{className:"size-3 sm:size-3.5"}),"Retry"]})]})}),$&&!X&&(0,C.jsxs)("div",{className:"absolute inset-0 z-40 bg-black flex flex-col items-center justify-center gap-4",children:[(0,C.jsx)("button",{type:"button",onClick:ye,className:"size-20 rounded-full flex items-center justify-center shadow-2xl transition-transform active:scale-95 hover:scale-105",style:{backgroundColor:"var(--color-primary)"},children:(0,C.jsx)(o,{className:"size-10 text-white fill-white ml-1.5"})}),(0,C.jsx)("span",{className:"text-white/70 text-sm font-medium",children:"Replay"})]}),!X&&(0,C.jsx)(C.Fragment,{children:(0,C.jsx)("div",{className:"absolute inset-0 z-20 cursor-pointer",onClick:ge,style:{backgroundColor:"transparent"}})}),U&&(0,C.jsx)("div",{className:"absolute inset-0 flex items-center justify-center z-30 pointer-events-none",children:(0,C.jsx)("div",{className:"bg-black/70 backdrop-blur-sm rounded-2xl px-5 py-3 flex items-center gap-2 animate-pulse",children:(0,C.jsx)("span",{className:"text-white font-bold text-lg",children:"fwd"===U?"+10s":"â10s"})})}),!X&&(0,C.jsxs)("div",{className:"absolute inset-0 z-30 flex flex-col justify-end transition-opacity duration-300 "+(R?"opacity-100":"opacity-0 pointer-events-none"),onClick:ge,children:[(t||r)&&(0,C.jsxs)("div",{className:"absolute top-0 left-0 right-0 bg-gradient-to-b from-black/80 to-transparent px-4 pt-3 pb-8",children:[t&&(0,C.jsx)("p",{className:"text-white text-sm font-medium line-clamp-1",children:t}),r&&(0,C.jsx)("p",{className:"text-white/70 text-xs line-clamp-1 mt-0.5",children:r})]}
1),!c&&s&&!$&&(0,C.jsx)("div",{className:"absolute inset-0 flex items-center justify-center pointer-events-none",children:(0,C.jsx)("button",{type:"button",onClick:xe,className:"size-16 rounded-full flex items-center justify-center shadow-2xl transition-transform active:scale-95 pointer-events-auto",style:{backgroundColor:"var(--color-primary)"},children:(0,C.jsx)(o,{className:"size-8 text-white fill-white ml-1"})})}),(0,C.jsxs)("div",{className:"bg-gradient-to-t from-black/90 via-black/50 to-transparent pt-10 pb-[max(0.5rem,env(safe-area-inset-bottom))] px-3",children:[(0,C.jsx)("div",{className:"mb-2 px-1",children:(0,C.jsxs)("div",{ref:H,className:"relative h-1.5 bg-white/20 rounded-full cursor-pointer group/bar hover:h-2.5 transition-all",onMouseDown:e=>{ie();const t=me(e.clientX);_(t),h(t),A(!0)},children:[(0,C.jsx)("div",{className:"absolute inset-y-0 left-0 bg-white/20 rounded-full",style:{width:"100%"}}),(0,C.jsx)("div",{className:"absolute inset-y-0 left-0 rounded-full transition-none",style:{width:`${je}%`,backgroundColor:"var(--color-primary)"}}),(0,C.jsx)("div",{className:"absolute top-1/2 -translate-y-1/2 size-3 rounded-full border-2 border-white opacity-0 group-hover/bar:opacity-100 transition-opacity",style:{left:`${je}%`,transform:"translate(-50%, -50%)",backgroundColor:"var(--color-primary)"}})]})}),(0,C.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,C.jsxs)("div",{className:"flex items-center gap-1",children:[(0,C.jsx)("button",{type:"button",onClick:xe,className:"p-2 text-white hover:text-primary transition-colors",children:c?(0,C.jsx)(n,{className:"size-5"}):(0,C.jsx)(o,{className:"size-5 fill-white"})}),(0,C.jsx)("button",{type:"button",onClick:pe,className:"p-2 text-white hover:text-primary transition-colors",children:x?(0,C.jsx)(b,{className:"size-5"}):(0,C.jsx)(m,{className:"size-5"})}),(0,C.jsxs)("span",{className:"text-white/80 text-xs font-mono tabular-nums ml-1 whitespace-nowrap",children:[T(we),g>0&&(0,C.jsxs)("span",{className:"text-white/40",children:[" / ",T(g)]})]})]}),(0,C.jsxs)("div",{className:"flex items-center gap-1",children:[(0,C.jsxs)("div",{className:"relative menu-panel",children:[(0,C.jsxs)("button",{type:"button",onClick:()=>F(e=>!e),className:"px-2 py-1 text-white hover:text-primary transition-colors text-xs font-semibold",children:[N,"Ã"]}),D&&(0,C.jsx)("div",{className:"absolute bottom-full right-0 mb-2 bg-black/95 border border-white/10 rounded-xl py-1.5 min-w-[72px] z-50 menu-panel shadow-2xl",children:S.map(e=>(0,C.jsxs)("button",{type:"button",onClick:()=>be(e),className:"w-full px-4 py-2 text-xs text-left transition-colors "+(e===N?"font-semibold":"text-white hover:bg-white/10"),style:e===N?{color:"var(--color-primary)"}:void 0,children:[e,"Ã"]},e))})]}),(0,C.jsx)("button",{type:"button",onClick:he,className:"p-2 text-white hover:text-primary transition-colors",children:I?(0,C.jsx)(l,{className:"size-4"}):(0,C.jsx)(a,{className:"size-4"})})]})]})]})]})]})})}function R(e){const t=Math.floor(e/60),r=e%60;return t>0?`${t}h ${r}m`:`${r}m`}function L({icon:e,label:t}){return(0,C.jsxs)("div",{className:"flex items-center gap-2 bg-primary/5 border border-primary/10 px-3 py-1.5 rounded-full",children:[(0,C.jsx)(e,{className:"size-3.5 text-primary"}),(0,C.jsx)("span",{className:"text-[11px] font-semibold text-primary",children:t})]})}function I(){return(0,C.jsxs)("div",{className:"space-y-6 animate-pulse",children:[(0,C.jsx)("div",{className:"w-32 h-4 bg-gray-200 rounded-full"}),(0,C.jsx)("div",{className:"w-full aspect-video bg-gray-200 rounded-2xl"}),(0,C.jsxs)("div",{className:"space-y-3 pt-2",children:[(0,C.jsx)("div",{className:"w-3/4 h-6 bg-gray-200 rounded-full"}),(0,C.jsx)("div",{className:"w-1/2 h-4 bg-gray-100 rounded-full"})]})]})}function M(){const{id:e,recordingId:s}=r(),n=t(),[a,l]=(0,k.useState)(null),[d,m]=(0,k.useState)(!0),[b,y]=(0,k.useState)(null),[v,g]=(0,k.useState)(!1),[w,S]=(0,k.useState)(!1);(0,k.useEffect)(()=>{if(!s||!e)return;let t=!1;return async function(){try{const r=await j.getById(e,s);t||l(r.recording)}catch{t||y("Failed to load recording.")}finally{t||m(!1)}}(),async function(){if(e)try{const r=await N.getWatchedForClass(e);!t&&r.success&&g(r.watchedIds.includes(s))}catch{}}(),()=>{t=!0}},[s,e]);const T=()=>n(`/classes/${e}`);if(d)return(0,C.jsx)("div",{className:"max-w-4xl mx-auto",children:(0,C.jsx)(I,{})});
1if(b||!a)return(0,C.jsxs)("div",{className:"max-w-4xl mx-auto space-y-6",children:[(0,C.jsxs)("button",{type:"button",onClick:T,className:"inline-flex items-center gap-2 text-sm font-semibold text-gray-500 hover:text-primary transition-colors group",children:[(0,C.jsx)(x,{className:"size-4 transition-transform group-hover:-translate-x-1"}),"Back to Class"]}),(0,C.jsxs)("div",{className:"bg-white rounded-[1.5rem] border border-gray-100 p-12 flex flex-col items-center gap-4 text-center",children:[(0,C.jsx)("div",{className:"size-14 rounded-2xl bg-red-50 flex items-center justify-center",children:(0,C.jsx)(p,{className:"size-7 text-primary"})}),(0,C.jsx)("h2",{className:"text-lg font-semibold text-gray-900",children:"Recording not found"}),(0,C.jsx)("p",{className:"text-sm text-gray-400 max-w-xs",children:b??"This recording may have been removed or is unavailable."}),(0,C.jsx)("button",{type:"button",onClick:T,className:"mt-2 px-5 py-2.5 bg-primary text-white rounded-xl text-sm font-semibold hover:opacity-90 transition-all",children:"Back to Class"})]})]});const z="YouTube"===a.videoType?function(e){for(const t of[/[?&]v=([\w-]{11})/,/youtu\.be\/([\w-]{11})/,/\/embed\/([\w-]{11})/,/\/live\/([\w-]{11})/,/\/shorts\/([\w-]{11})/]){const r=e.match(t);if(r?.[1])return r[1]}return null}(a.videoUrl):null;return(0,C.jsxs)("div",{className:"space-y-6 animate-in fade-in duration-150 motion-reduce:animate-none",children:[(0,C.jsxs)("button",{type:"button",onClick:T,className:"inline-flex items-center gap-2 text-sm font-semibold text-gray-500 hover:text-primary transition-colors group",children:[(0,C.jsx)(x,{className:"size-4 transition-transform group-hover:-translate-x-1"}),"Back to Class"]}),(0,C.jsxs)("div",{className:"bg-white rounded-[1.5rem] border border-gray-100 overflow-hidden",children:[(0,C.jsx)("div",{className:"w-full",children:z?(0,C.jsx)(E,{videoId:z,title:a.title,description:a.description}):(0,C.jsx)("div",{className:"relative w-full",style:{paddingTop:"56.25%"},children:(0,C.jsx)("iframe",{className:"absolute inset-0 w-full h-full",src:a.videoUrl,title:a.title,allow:"autoplay; fullscreen; encrypted-media",allowFullScreen:!0})})}),(0,C.jsxs)("div",{className:"p-6 md:p-8 space-y-5",children:[(0,C.jsxs)("div",{className:"space-y-2",children:[(0,C.jsx)("h1",{className:"text-xl md:text-2xl font-semibold text-gray-900 leading-snug",children:a.title}),a.description&&(0,C.jsx)("p",{className:"text-sm text-gray-500 leading-relaxed",children:a.description})]}),(0,C.jsxs)("div",{className:"flex flex-wrap gap-2",children:[a.duration&&(0,C.jsx)(L,{icon:c,label:R(a.duration)}),(0,C.jsx)(L,{icon:h,label:(M=a.createdAt,M?new Date(M).toLocaleDateString("en-US",{year:"numeric",month:"short",day:"numeric"}):"â")}),a.videoType&&(0,C.jsx)(L,{icon:o,label:"dyntube"===a.videoType?"Protected":a.videoType}),(0,C.jsx)(L,{icon:i,label:"HD Quality"}),(0,C.jsxs)("button",{type:"button",onClick:async()=>{if(!w&&s&&e){S(!0);try{const t=await N.toggle(s,e);t.success&&g(t.watched)}finally{S(!1)}}},disabled:w,className:`flex items-center gap-2 px-3 py-1.5 rounded-full text-[11px] font-semibold border transition-all ${v?"bg-emerald-50 border-emerald-200 text-emerald-700 hover:bg-emerald-100":"bg-gray-50 border-gray-200 text-gray-500 hover:border-primary/20 hover:text-primary"} ${w?"opacity-50 cursor-not-allowed":""}`,children:[v?(0,C.jsx)(u,{className:"size-3.5"}):(0,C.jsx)(f,{className:"size-3.5"}),v?"Watched":"Mark as watched"]})]})]})]})]});var M}export{M 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.