import{s as l}from"./video.module.f0db40bb.js";import{d as b,ah as k,ag as A,aY as F,r as q,R as L,Z as I,$ as M,m as N,b3 as B,c as i,L as H,q as x,B as O,f as j,be as J}from"./index.3b0304e1.js";import{P as _}from"./plyr.min.22fd58dd.js";/* empty css */import{u as y,b as $}from"./index.d39bcb3f.js";var K=b({name:"pre-register",setup(){const f=k(),E=A(),V=F(),C=sessionStorage.getItem("active-open-id"),c=y(1e3,{controls:!0});c.pause();const e=q({coverImg:"",introductionVideo:"",introductionVideoTime:0,videoBrowsePoint:0,saveId:f.query.saveId,orchestraId:f.query.id,openId:f.query.openId||C,loading:!1,player:null,playerSpeed:1,intervalFnRef:null,videoDetails:[],pointVideo:{},pointVideoTime:0,videoSelectId:null,isPageHide:!1,parentConferencesNotes:"",orchestraRegisterType:"",status:""}),r=y(1e3,{controls:!0});r.pause();const g=o=>{const a=[];o.sort((s,n)=>s[0]-n[0]);let t=o[0];for(let s=1;s=n[0]?t[1]=Math.max(n[1],t[1]):(a.push(t),t=n)}return a.push(t),P(a)},P=o=>{const a=[],t=e.pointVideo.startNode,s=e.pointVideo.endNode;return o.forEach(n=>{n[0]>=t&&n[1]<=s&&a.push(n),n[0]>=t&&n[1]<=s&&n[1]>=s&&a.push([n[0],s]),n[0]t&&n[1]{const a=g(o);console.log(a,"afterIntervals");let t=0;return a.forEach(s=>{t+=s[1]-s[0]}),t},u=o=>{e.videoDetails.forEach(a=>{a.startNode<=o&&o<=a.endNode&&(e.videoSelectId=a.id)})},S=()=>{const a={controls:["play-large","play","progress","captions","current-time","duration","settings","fullscreen"],settings:["speed"],speed:{selected:1,options:[.5,1,1.5,2]},i18n:{speed:"\u901F\u5EA6",normal:"\u9ED8\u8BA4"},autoplay:!1,invertTime:!1};j().iPhone&&(a.fullscreen={enabled:!0,fallback:"force",iosNative:!0});const t=[];e.videoDetails.forEach(s=>{t.push({time:s.startNode,label:s.desc})}),a.markers={enabled:!0,points:t},e.player=new _("#register-video",a),e.player.on("ready",s=>{console.log("ready",s)}),e.player.on("loadedmetadata",()=>{console.log("loadedmetadata"),e.loading=!1,e.player.currentTime=e.videoBrowsePoint,u(e.player.currentTime)}),e.player.on("ratechange",()=>{e.playerSpeed=e.playerSpeed{console.log("seeking"),r.isActive.value&&r.pause()}),e.player.on("seeked",()=>{console.log("seeked"),r.isActive.value&&r.pause()}),e.player.on("waiting",()=>{r.isActive.value&&r.pause()}),e.player.on("timeupdate",()=>{console.log("timeupdate",e.player.currentTime),u(e.player.currentTime),!r.isActive.value&&e.player.currentTime>0&&e.player.playing&&r.resume()}),e.player.on("ended",()=>{e.player.pause()}),e.player.on("play",()=>{console.log("play"),r.resume()}),e.player.on("pause",()=>{console.log("pause",r.isActive.value),r.pause()}),e.player.on("enterfullscreen",()=>{console.log("fullscreen");const s=document.createElement("i");s.id="fullscreen-back",s.className="van-icon van-icon-arrow-left video-back",s.addEventListener("click",()=>{e.player.fullscreen.exit()}),console.log(document.getElementsByClassName("plyr")),document.getElementsByClassName("plyr")[0].appendChild(s)}),e.player.on("exitfullscreen",()=>{console.log("exitfullscreen");const s=document.getElementById("fullscreen-back");s&&s.remove()}),u(0)},v=L([]);let d=[];const p=y(1e3,{controls:!0});I(()=>r.isActive.value,o=>{m(o)});const m=o=>{if(o?d[0]=Math.floor(e.player.currentTime):d[1]=Math.floor(e.player.currentTime),d.length>=2){const a=d[1]-d[0]-p.counter.value*e.playerSpeed>2;d[1]>=d[0]&&!a&&v.value.push(d),d=[],p.counter.value=0}};I(V,o=>{console.log("watch",o),o=="hidden"&&e.player.pause()});const h=async(o=10)=>{try{const a=v.value.length>0?g(v.value):[],t=a.length>0?R(a):0,s=Math.floor(t/Math.floor(e.pointVideoTime)*100);await N.post("/api-student/open/studentBrowseRecord/updateStat",{data:{id:e.saveId,pageBrowseTime:o,videoBrowseData:JSON.stringify(a),videoBrowseDataTime:t||0,videoBrowsePercentage:s||0,videoBrowseTime:r==null?void 0:r.counter.value,videoBrowsePoint:Math.floor(e.player.currentTime||0)}})}catch{}},D=async()=>{var o,a;try{e.player.pause(),(o=e.intervalFnRef)==null||o.pause(),p.pause(),r.pause(),c.pause(),m(r.isActive.value),await h(),console.log(e.orchestraRegisterType),e.orchestraRegisterType==="PARENT_CONFERENCES"?window.location.href=window.location.origin+window.location.pathname+`/#/preApply?id=${e.orchestraId}`:window.location.href=window.location.origin+window.location.pathname+"/project/preRegister.html?"+J.stringify({orchestraId:e.orchestraId,openId:e.openId})}catch(t){console.log(t,"e"),(a=e.intervalFnRef)==null||a.resume(),c.resume(),p.resume()}};M(async()=>{try{const{data:o}=await N.get("/api-student/open/studentBrowseRecord/query",{params:{openId:e.openId,orchestraId:e.orchestraId}});e.videoBrowsePoint=o.videoBrowsePoint||0,e.player&&(e.player.currentTime=o.videoBrowsePoint||0),e.introductionVideo=o.introductionVideo,e.introductionVideoTime=o.introductionVideoTime,e.coverImg=o.coverImg,v.value=o.videoBrowseData?JSON.parse(o.videoBrowseData):[],e.parentConferencesNotes=o.parentConferencesNotes,e.orchestraRegisterType=o.orchestraRegisterType,(o.videoDetails||[]).forEach(t=>{e.videoDetails.push({startNode:t.startNode,endNode:t.endNode,desc:t.desc,id:t.id}),t.pointFlag&&(e.pointVideo=t,e.pointVideoTime=t.endNode-t.startNode)}),S(),e.intervalFnRef=$(async()=>{c.counter.value=0,c.resume(),await h(),r.counter.value=0},1e4)}catch{}}),B(()=>{var o;(o=e.intervalFnRef)==null||o.pause(),p.pause(),c.pause()}),e.openId||E.replace({path:"/pre-register-video",query:{id:e.orchestraId}});const w=()=>{console.log(e.isPageHide,"showInfo"),e.isPageHide&&window.location.reload()};window.addEventListener("pageshow",w);const T=()=>{console.log(e.isPageHide,"showInfo"),e.isPageHide=!0};return window.addEventListener("pagehide",T),B(()=>{window.removeEventListener("pageshow",w),window.removeEventListener("pagehide",T)}),()=>i("div",{class:l["pre-register-video"]},[i("div",{class:l.videoContainer},[i("div",{class:l["video-content"]},[i("video",{id:"register-video",class:l.video,src:e.introductionVideo,playsinline:!0,poster:e.coverImg,preload:"auto"},null),e.loading&&i("div",{class:l.loadingVideo},[i(H,{size:36,color:"#FF8057",vertical:!0,style:{height:"100%",justifyContent:"center"}},{default:()=>[x("\u52A0\u8F7D\u4E2D...")]})])])]),i("div",{class:l.videoCount},[i("div",{class:l.videoCountContent},[e.videoDetails.map(o=>i("span",{class:[o.id===e.videoSelectId?l.active:""],onClick:()=>{e.player.currentTime=o.startNode,e.player.play(),e.videoBrowsePoint=o.startNode,u(e.player.currentTime)}},[o.desc]))])]),i("div",{class:l.messageContainer},[i("div",{class:l.messageContent},[i("div",{innerHTML:e.parentConferencesNotes},null),i(O,{class:l.submitBtn,onClick:D},null)])])])}});export{K as default};