import{j as e}from"./query-vendor-CZu0EHPe.js";import{R as X,r as a,k as ge,j as be,N as ve}from"./react-vendor-0bvDbF03.js";import{B as ye}from"./BreadcrumbNavigation-DBHDLpC2.js";import{P as R,B as Z,V as je}from"./VideoCard-BfQJBxSx.js";import{c as N,b,I as G,V as w,k as ke,e as Q,Y as A,Z as we,_ as ee,S as Ne,$ as Pe,a0 as Ce,U as Se,a1 as O,a2 as Te,y as Me}from"./index-C-Kzd2Hj.js";import{u as D}from"./i18n-vendor-Bg2yf_Zw.js";import{P as J}from"./play-Z9FaJ7qr.js";import{P as Ee,V as $e}from"./volume-x-5zATKzb6.js";import{V as Ve}from"./volume-2-CwV3X8s2.js";import"./supabase-vendor-CNV44oIa.js";import"./helmet-vendor-NlTFkN97.js";/**
* @license lucide-react v0.554.0 - ISC
*
* This source code is licensed under the ISC license.
* See the LICENSE file in the root directory of this source tree.
*/const Ie=[["path",{d:"M10.5 5H19a2 2 0 0 1 2 2v8.5",key:"jqtk4d"}],["path",{d:"M17 11h-.5",key:"1961ue"}],["path",{d:"M19 19H5a2 2 0 0 1-2-2V7a2 2 0 0 1 2-2",key:"1keqsi"}],["path",{d:"m2 2 20 20",key:"1ooewy"}],["path",{d:"M7 11h4",key:"1o1z6v"}],["path",{d:"M7 15h2.5",key:"1ina1g"}]],De=N("captions-off",Ie);/**
* @license lucide-react v0.554.0 - ISC
*
* This source code is licensed under the ISC license.
* See the LICENSE file in the root directory of this source tree.
*/const _e=[["rect",{width:"18",height:"14",x:"3",y:"5",rx:"2",ry:"2",key:"12ruh7"}],["path",{d:"M7 15h4M15 15h2M7 11h2M13 11h4",key:"1ueiar"}]],Le=N("captions",_e);/**
* @license lucide-react v0.554.0 - ISC
*
* This source code is licensed under the ISC license.
* See the LICENSE file in the root directory of this source tree.
*/const Re=[["path",{d:"M8 3H5a2 2 0 0 0-2 2v3",key:"1dcmit"}],["path",{d:"M21 8V5a2 2 0 0 0-2-2h-3",key:"1e4gt3"}],["path",{d:"M3 16v3a2 2 0 0 0 2 2h3",key:"wsl5sc"}],["path",{d:"M16 21h3a2 2 0 0 0 2-2v-3",key:"18trek"}]],Oe=N("maximize",Re);/**
* @license lucide-react v0.554.0 - ISC
*
* This source code is licensed under the ISC license.
* See the LICENSE file in the root directory of this source tree.
*/const Ue=[["path",{d:"M8 3v3a2 2 0 0 1-2 2H3",key:"hohbtr"}],["path",{d:"M21 8h-3a2 2 0 0 1-2-2V3",key:"5jw1f3"}],["path",{d:"M3 16h3a2 2 0 0 1 2 2v3",key:"198tvr"}],["path",{d:"M16 21v-3a2 2 0 0 1 2-2h3",key:"ph8mxp"}]],Ae=N("minimize",Ue);/**
* @license lucide-react v0.554.0 - ISC
*
* This source code is licensed under the ISC license.
* See the LICENSE file in the root directory of this source tree.
*/const Be=[["path",{d:"M21 9V6a2 2 0 0 0-2-2H4a2 2 0 0 0-2 2v10c0 1.1.9 2 2 2h4",key:"daa4of"}],["rect",{width:"10",height:"7",x:"12",y:"13",rx:"2",key:"1nb8gs"}]],ze=N("picture-in-picture-2",Be);/**
* @license lucide-react v0.554.0 - ISC
*
* This source code is licensed under the ISC license.
* See the LICENSE file in the root directory of this source tree.
*/const Fe=[["path",{d:"M2.5 17a24.12 24.12 0 0 1 0-10 2 2 0 0 1 1.4-1.4 49.56 49.56 0 0 1 16.2 0A2 2 0 0 1 21.5 7a24.12 24.12 0 0 1 0 10 2 2 0 0 1-1.4 1.4 49.55 49.55 0 0 1-16.2 0A2 2 0 0 1 2.5 17",key:"1q2vi4"}],["path",{d:"m10 15 5-3-5-3z",key:"1jp15x"}]],He=N("youtube",Fe),U=[.75,1,1.25,1.5],qe=2600,te=X.forwardRef(({src:l,poster:o,title:c,subtitles:d=[],className:h,onTimeUpdate:u,onFirstPlay:p},i)=>{const{t:s}=D("watch"),r=a.useRef(null),P=a.useRef(null),j=a.useRef(),M=a.useRef(!1),[v,m]=a.useState(!1),[C,x]=a.useState(!1),[E,se]=a.useState(0),[y,ae]=a.useState(0),[ne,re]=a.useState(0),[B,le]=a.useState(!1),[oe,ce]=a.useState(1),[z,ie]=a.useState(1),[$,ue]=a.useState(!1),[_,L]=a.useState(!0),[F,de]=a.useState(!1),[S,me]=a.useState(!1);X.useImperativeHandle(i,()=>({seekTo:(t,n)=>{const f=r.current;if(!f)return;const k=()=>{f.currentTime=t,n?.play!==!1&&f.play().catch(()=>{})};f.readyState>=1?k():f.addEventListener("loadedmetadata",k,{once:!0})}}));const g=a.useCallback(()=>{L(!0),clearTimeout(j.current),r.current&&!r.current.paused&&(j.current=setTimeout(()=>L(!1),qe))},[]);a.useEffect(()=>()=>clearTimeout(j.current),[]);const V=a.useCallback(()=>{const t=r.current;t&&(t.paused?(x(!0),t.play().catch(()=>x(!1))):(t.pause(),x(!1)))},[]),H=a.useCallback(t=>{const n=r.current;n&&(n.currentTime=Math.min(Math.max(n.currentTime+t,0),n.duration||0),g())},[g]),q=a.useCallback(t=>{const n=r.current;if(!n)return;const f=Math.min(Math.max(n.volume+t,0),1);n.volume=f,n.muted=f===0,g()},[g]);a.useEffect(()=>{const t=r.current;if(!t||d.length===0)return;const n=()=>{const I=Array.from(t.textTracks);de(I.some(xe=>(xe.cues?.length??0)>0))};Array.from(t.textTracks).forEach(I=>{I.mode==="disabled"&&(I.mode="hidden")});const f=setInterval(n,400),k=setTimeout(()=>clearInterval(f),6e3);return n(),()=>{clearInterval(f),clearTimeout(k)}},[d.length,l]);const W=a.useCallback(()=>{const t=r.current;if(!t)return;const n=!S;Array.from(t.textTracks).forEach((f,k)=>{f.mode=n&&k===0?"showing":"hidden"}),me(n),g()},[S,g]),Y=a.useCallback(()=>{const t=P.current;t&&(document.fullscreenElement?document.exitFullscreen().catch(()=>{}):t.requestFullscreen().catch(()=>{}))},[]);a.useEffect(()=>{const t=()=>ue(!!document.fullscreenElement);return document.addEventListener("fullscreenchange",t),()=>document.removeEventListener("fullscreenchange",t)},[]);const he=a.useCallback(()=>{const t=r.current;t&&(document.pictureInPictureElement?document.exitPictureInPicture().catch(()=>{}):document.pictureInPictureEnabled&&t.requestPictureInPicture().catch(()=>{}))},[]),pe=t=>{const n=t.target?.dataset?.scrubber==="true";switch(t.key){case" ":case"k":t.preventDefault(),V();break;case"ArrowLeft":if(n)return;t.preventDefault(),H(-5);break;case"ArrowRight":if(n)return;t.preventDefault(),H(5);break;case"ArrowUp":t.preventDefault(),q(.1);break;case"ArrowDown":t.preventDefault(),q(-.1);break;case"m":t.preventDefault(),r.current&&(r.current.muted=!r.current.muted);break;case"f":t.preventDefault(),Y();break;case"c":F&&(t.preventDefault(),W());break}},K=y>0?E/y*100:0,fe=y>0?ne/y*100:0,T="inline-flex h-9 w-9 items-center justify-center rounded-full text-white/90 transition-colors hover:bg-white/15 hover:text-white focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-white/70";return e.jsxs("div",{ref:P,className:b("relative aspect-video w-full overflow-hidden rounded-2xl bg-ink/90",!$&&"mx-auto max-w-[calc((100dvh-11rem)*16/9)]","focus-within:ring-2 focus-within:ring-nature-coral/60",$&&"rounded-none",h),onMouseMove:g,onKeyDown:pe,onPointerDown:g,role:"region","aria-label":c,tabIndex:-1,children:[e.jsx("video",{ref:r,src:l,poster:o,preload:"metadata",controlsList:"nodownload noplaybackrate",disablePictureInPicture:!0,playsInline:!0,className:"h-full w-full bg-ink object-contain",onClick:V,onPlay:()=>{m(!0),g(),M.current||(M.current=!0,p?.())},onPlaying:()=>x(!1),onWaiting:()=>x(!0),onStalled:()=>x(!0),onSeeking:()=>{r.current?.paused||x(!0)},onSeeked:()=>x(!1),onError:()=>x(!1),onPause:()=>{m(!1),x(!1),L(!0),clearTimeout(j.current)},onLoadedMetadata:t=>ae(t.currentTarget.duration||0),onTimeUpdate:t=>{const n=t.currentTarget;se(n.currentTime),u?.(n.currentTime),n.buffered.length>0&&re(n.buffered.end(n.buffered.length-1))},onVolumeChange:t=>{le(t.currentTarget.muted),ce(t.currentTarget.volume)},children:d.map(t=>e.jsx("track",{kind:"subtitles",src:t.src,srcLang:t.srcLang,label:t.label},t.srcLang))}),!v&&e.jsx("button",{type:"button",onClick:V,"aria-label":s(C?"player.loading":"player.play"),"aria-busy":C,className:"absolute inset-0 flex touch-manipulation items-center justify-center bg-ink/25 transition-colors hover:bg-ink/35 focus-visible:outline-none active:bg-ink/40",children:e.jsx("span",{className:b("-mt-4 flex h-14 w-14 items-center justify-center rounded-full bg-nature-coral shadow-lg transition-transform md:mt-0 md:h-20 md:w-20",C?"scale-95":"hover:scale-105 active:scale-95"),children:C?e.jsx(G,{className:"h-6 w-6 animate-spin text-white md:h-9 md:w-9"}):e.jsx(J,{className:"ml-0.5 h-6 w-6 text-white md:ml-1 md:h-9 md:w-9",fill:"currentColor"})})}),v&&C&&e.jsx("span",{className:"pointer-events-none absolute inset-0 flex items-center justify-center",children:e.jsx(G,{className:"h-12 w-12 animate-spin text-white drop-shadow-lg"})}),e.jsxs("div",{className:b("pointer-events-none absolute inset-x-0 bottom-0 bg-gradient-to-t from-ink/90 via-ink/60 to-transparent px-3 pb-2 pt-8 transition-opacity duration-200 md:px-4",_?"opacity-100":"opacity-0"),children:[e.jsxs("div",{className:b("relative h-5",_&&"pointer-events-auto"),children:[e.jsxs("div",{className:"pointer-events-none absolute inset-x-0 top-1/2 h-1.5 -translate-y-1/2 overflow-hidden rounded-full bg-white/25",children:[e.jsx("div",{className:"absolute inset-y-0 left-0 bg-white/35",style:{width:`${fe}%`}}),e.jsx("div",{className:"absolute inset-y-0 left-0 bg-nature-coral",style:{width:`${K}%`}})]}),e.jsx("div",{className:"pointer-events-none absolute top-1/2 h-3.5 w-3.5 -translate-y-1/2 rounded-full bg-nature-coral shadow",style:{left:`calc(${K}% - 7px)`}}),e.jsx("input",{"data-scrubber":"true",type:"range",min:0,max:y||0,step:.1,value:E,onChange:t=>{const n=r.current;n&&(n.currentTime=Number(t.target.value))},"aria-label":s("player.seek"),"aria-valuetext":`${w(E)} / ${w(y)}`,className:"absolute inset-0 h-full w-full cursor-pointer appearance-none bg-transparent opacity-0"})]}),e.jsxs("div",{className:b("mt-1 flex items-center gap-1",_&&"pointer-events-auto"),children:[e.jsx("button",{type:"button",onClick:V,className:T,"aria-label":s(v?"player.pause":"player.play"),children:v?e.jsx(Ee,{className:"h-5 w-5"}):e.jsx(J,{className:"h-5 w-5"})}),e.jsx("button",{type:"button",onClick:()=>{const t=r.current;t&&(t.muted=!t.muted)},className:T,"aria-label":s(B?"player.unmute":"player.mute"),children:B||oe===0?e.jsx($e,{className:"h-5 w-5"}):e.jsx(Ve,{className:"h-5 w-5"})}),e.jsxs("span",{className:"ml-1 select-none font-mono text-xs tabular-nums text-white/90",children:[w(E)," / ",w(y)]}),e.jsx("div",{className:"flex-1"}),e.jsxs("button",{type:"button",onClick:()=>{const t=U[(U.indexOf(z)+1)%U.length];r.current&&(r.current.playbackRate=t),ie(t),g()},className:"inline-flex h-9 min-w-9 items-center justify-center rounded-full px-2 text-xs font-semibold text-white/90 transition-colors hover:bg-white/15 hover:text-white focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-white/70","aria-label":s("player.speed"),children:[z,"×"]}),F&&e.jsx("button",{type:"button",onClick:W,className:b(T,S&&"bg-white/20 text-white"),"aria-label":s("player.captions"),"aria-pressed":S,children:S?e.jsx(Le,{className:"h-5 w-5"}):e.jsx(De,{className:"h-5 w-5"})}),typeof document<"u"&&document.pictureInPictureEnabled&&e.jsx("button",{type:"button",onClick:he,className:b(T,"hidden md:inline-flex"),"aria-label":s("player.pip"),children:e.jsx(ze,{className:"h-5 w-5"})}),e.jsx("button",{type:"button",onClick:Y,className:T,"aria-label":s($?"player.exitFullscreen":"player.fullscreen"),children:$?e.jsx(Ae,{className:"h-5 w-5"}):e.jsx(Oe,{className:"h-5 w-5"})})]})]})]})});te.displayName="VideoPlayer";const We=l=>{const o=l.trim().split(":").map(Number);return o.some(Number.isNaN)?NaN:o.length===3?o[0]*3600+o[1]*60+o[2]:o.length===2?o[0]*60+o[1]:NaN},Ye=l=>{const o=[];for(const c of l.replace(/\r/g,"").split(`
`)){const d=c.split(`
`).filter(Boolean),h=d.findIndex(i=>i.includes("-->"));if(h===-1)continue;const u=We(d[h].split("-->")[0]),p=d.slice(h+1).join(" ").replace(/<[^>]+>/g,"").trim();!Number.isNaN(u)&&p&&o.push({start:u,text:p})}return o},Ke=({src:l,onSeek:o})=>{const{t:c}=D("watch"),[d,h]=a.useState([]),[u,p]=a.useState(!1);return a.useEffect(()=>{let i=!1;return h([]),fetch(l).then(s=>s.ok?s.text():Promise.reject(new Error(String(s.status)))).then(s=>{i||h(Ye(s))}).catch(()=>{}),()=>{i=!0}},[l]),d.length===0?null:e.jsxs("section",{className:"page-card p-4 md:p-6",children:[e.jsxs("button",{type:"button",onClick:()=>p(i=>!i),"aria-expanded":u,className:"flex w-full items-center justify-between gap-3 text-left",children:[e.jsx("h2",{className:"text-base lg:text-lg font-bold text-ink",children:c("video.transcript")}),e.jsxs("span",{className:"flex items-center gap-2 text-sm text-nature-forest",children:[c(u?"video.hideTranscript":"video.showTranscript"),e.jsx(ke,{className:b("h-4 w-4 transition-transform",u&&"rotate-180"),"aria-hidden":"true"})]})]}),e.jsx("div",{className:b("mt-4 space-y-2",!u&&"sr-only"),children:d.map((i,s)=>e.jsxs("p",{className:"flex gap-3 text-sm leading-relaxed",children:[e.jsx("button",{type:"button",onClick:()=>o(i.start),className:"shrink-0 font-mono text-xs tabular-nums text-nature-coral hover:underline",children:w(i.start)}),e.jsx("span",{className:"text-ink",children:i.text})]},`${i.start}-${s}`))})]})},Xe=({video:l,title:o,description:c})=>{const{t:d}=D("watch"),{currentLanguage:h}=Q(),u=`/watch/${l.slug}`,p=Pe(u,h),i={"@context":"https://schema.org","@type":"VideoObject",name:o,description:c,thumbnailUrl:[A(l)],uploadDate:`${l.uploadDate}T00:00:00+00:00`,duration:we(l.seconds),contentUrl:ee(l),url:p,publisher:{"@type":"Organization",name:"StorySparkle",url:"https://storysparkle.org",logo:{"@type":"ImageObject",url:"https://cdn.storysparkle.org/logo_assets/favicon_512x512.png"}},hasPart:l.chapters.map((s,r)=>({"@type":"Clip",name:d(`videos.${l.slug}.chapters.${s.id}`),startOffset:Math.round(s.at),endOffset:Math.round(r+1<l.chapters.length?l.chapters[r+1].at:l.seconds),url:`${p}?t=${Math.round(s.at)}`}))};return e.jsx(Ne,{title:o,description:c,canonical:u,ogImage:A(l),ogType:"video.other",structuredData:i})},ot=()=>{const{slug:l}=ge(),[o]=be(),{t:c,i18n:d}=D("watch"),{getLocalizedPath:h,currentLanguage:u}=Q(),p=a.useRef(null),i=Number(o.get("t"));a.useEffect(()=>{Number.isFinite(i)&&i>0&&p.current?.seekTo(i,{play:!1})},[i,l]);const s=Ce(l);if(!s)return e.jsx(ve,{to:h("/watch"),replace:!0});const r=c(`videos.${s.slug}.title`),P=c(`videos.${s.slug}.description`),j=Se.filter(m=>m.slug!==s.slug),M=[{srcLang:u,label:d.language,src:O(s,u)},...u!=="en"?[{srcLang:"en",label:"English",src:O(s,"en")}]:[]],v=m=>p.current?.seekTo(m);return e.jsxs(e.Fragment,{children:[e.jsx(Xe,{video:s,title:r,description:P}),e.jsxs("div",{className:"min-h-screen bg-page-surface pt-4 pb-6 md:pt-6 md:pb-8 overflow-x-clip",children:[e.jsx(R,{children:e.jsx(ye,{items:[{name:c("breadcrumb"),path:"/watch"},{name:r,path:`/watch/${s.slug}`}]})}),e.jsx("section",{className:"py-8 md:py-10",children:e.jsxs(R,{children:[e.jsx("h1",{className:"text-[22px] lg:text-[32px] font-bold mb-4 text-ink",children:e.jsx(Z,{children:r})}),e.jsxs("div",{className:"grid grid-cols-1 gap-6 lg:grid-cols-3 lg:items-start",children:[e.jsxs("div",{className:"space-y-6 lg:col-span-2",children:[e.jsx(te,{ref:p,src:ee(s),poster:A(s),title:r,subtitles:M,onFirstPlay:()=>Te.trackEvent("watch_video_play",{slug:s.slug})}),e.jsx("p",{className:"text-sm lg:text-base leading-relaxed text-ink",children:e.jsx(Z,{children:P})}),e.jsx(Ke,{src:O(s,u),onSeek:v})]}),e.jsxs("aside",{className:"space-y-6",children:[e.jsxs("section",{className:"page-card p-4 md:p-6",children:[e.jsx("h2",{className:"mb-3 text-base lg:text-lg font-bold text-ink",children:c("video.chapters")}),e.jsx("ol",{className:"max-h-[22rem] space-y-1 overflow-y-auto lg:max-h-[26rem]",children:s.chapters.map(m=>e.jsx("li",{children:e.jsxs("button",{type:"button",onClick:()=>v(m.at),className:"flex w-full gap-3 rounded-md px-2 py-1.5 text-left text-sm transition-colors hover:bg-nature-forest/10 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-nature-coral",children:[e.jsx("span",{className:"shrink-0 font-mono text-xs tabular-nums text-nature-coral",children:w(m.at)}),e.jsx("span",{className:"text-ink",children:c(`videos.${s.slug}.chapters.${m.id}`)})]})},m.id))})]}),e.jsxs("section",{className:"page-card flex flex-col items-start gap-3 p-4 md:p-6",children:[e.jsx("h2",{className:"text-base lg:text-lg font-bold text-ink",children:c("video.nextStep")}),e.jsx(Me,{to:h(s.feature),variant:"primary",children:c(`cta.${s.slug}`)}),s.youtube&&e.jsxs("a",{href:s.youtube,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-2 text-sm text-nature-forest hover:underline",children:[e.jsx(He,{className:"h-4 w-4","aria-hidden":"true"}),c("video.watchOnYouTube")]})]})]})]})]})}),e.jsx("section",{className:"pb-12 md:pb-16",children:e.jsxs(R,{children:[e.jsx("h2",{className:"mb-6 text-lg lg:text-2xl font-bold text-ink",children:c("video.moreVideos")}),e.jsx("div",{className:"grid grid-cols-1 gap-6 sm:grid-cols-2 lg:grid-cols-3",children:j.map(m=>e.jsx(je,{video:m},m.slug))})]})})]})]})};export{ot as default};