1"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[21629],{11469:(e,t,i)=>{i.d(t,{A:()=>s});let s=(0,i(41285).A)("FileArchive",[["path",{d:"M10 12v-1",key:"v7bkov"}],["path",{d:"M10 18v-2",key:"1cjy8d"}],["path",{d:"M10 7V6",key:"dljcrl"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["path",{d:"M15.5 22H18a2 2 0 0 0 2-2V7l-5-5H6a2 2 0 0 0-2 2v16a2 2 0 0 0 .274 1.01",key:"gkbcor"}],["circle",{cx:"10",cy:"20",r:"2",key:"1xzdoj"}]])},16477:(e,t,i)=>{i.d(t,{A:()=>s});let s=(0,i(41285).A)("File",[["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"}]])},17606:(e,t,i)=>{i.d(t,{A:()=>s});let s=(0,i(41285).A)("Volume2",[["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"}]])},17687:(e,t,i)=>{i.d(t,{A:()=>s});let s=(0,i(41285).A)("LoaderCircle",[["path",{d:"M21 12a9 9 0 1 1-6.219-8.56",key:"13zald"}]])},21629:(e,t,i)=>{i.r(t),i.d(t,{default:()=>_});var s=i(95818),n=i(16418),r=i(72313),a=i(97350),l=i(3004),o=i(62249),d=i(29661),c=i(18821),u=i(58451),h=i(22293),m=i(73511),p=i(57647),x=i(85498),v=i(73160),f=i(58622),g=i(11469),y=i(42343),b=i(16477),k=i(34771),w=i(51661);let j=(0,i(41285).A)("VolumeX",[["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"}],["line",{x1:"22",x2:"16",y1:"9",y2:"15",key:"1ewh16"}],["line",{x1:"16",x2:"22",y1:"9",y2:"15",key:"5ykzw1"}]]);var N=i(17606),S=i(70686),E=i(17687),M=i(98300),T=i(59022),A=i(41447);let I={female:"vi-VN-HoaiMyNeural",male:"vi-VN-NamMinhNeural"},C=new Map,L=new Map;function V(e,t){var i,s;let n=t[0],r=t[t.length-1];return"".concat(e,"|").concat(t.length,"|").concat(null!==(i=null==n?void 0:n.startMs)&&void 0!==i?i:0,"|").concat(null!==(s=null==r?void 0:r.endMs)&&void 0!==s?s:0,"|").concat(((null==n?void 0:n.text)||"").slice(0,48))}class P{async start(){var e,t;if(this.destroyed||!this.cues.length)return;this.audio.pause(),this.active=!1;let i=this.cues.every((e,t)=>this.hasCached(t));if(this.bindTransport(),i)this.hydrateFromSession();else{if(!await this.preloadHead()||this.destroyed)return;this.preloadRest()}this.active=!0,this.nativeVolume=this.outputVolume,this.applyOutput(),this.syncMute(),this.lastObservedTime=this.video.currentTime,null===(e=this.onStatus)||void 0===e||e.call(this,""),null===(t=this.onReady)||void 0===t||t.call(this);let s=Math.max(0,this.findIndexAtTime());this.playSegment(s),this.emitTranscript(),!this.isUserPaused()&&this.video.paused&&this.video.play().catch(()=>void 0)}warmup(){this.destroyed||!this.cues.length||this.active||this.preparing||this.preloadHead().then(e=>{if(!this.destroyed){if(e&&!this.active){var t,i;null===(t=this.onStatus)||void 0===t||t.call(this,"Sẵn s\xe0ng lá»ng tiếng"),null===(i=this.onReady)||void 0===i||i.call(this)}this.preloadRest()}})}stop(){var e,t;this.preloadGen+=1,this.preparing=!1,this.active=!1,this.audio.pause(),this.unbindTransport(),this.video.volume=this.outputVolume,this.currentIndex=-1,this.pendingIndex=-1,null===(e=this.onSubtitle)||void 0===e||e.call(this,""),null===(t=this.onStatus)||void 0===t||t.call(this,"")}setVoice(e){if(e===this.voice)return;this.voice=e,this.cacheKey=V(e,this.cues);let t=this.active;this.clearPool(),t&&this.start()}setDuckVolume(e){this.duckVolume=Math.min(1,Math.max(0,e)),this.active&&this.applyOutput()}setOutputVolume(e){this.outputVolume=Math.min(1,Math.max(0,e)),this.nativeVolume=this.outputVolume,this.applyOutput()}destroy(){this.stop(),this.clearPool(),this.audio.removeEventListener("ended",this.onAudioEnded),this.destroyed=!0}markUserPaused(e){this.video.hpkUserPaused=e}isUserPaused(){return!!this.video.hpkUserPaused}pauseSelf(){this.ignorePauseUntil=performance.now()+400,this.video.pause()}bindTransport(){this.unbindTransport(),this.video.addEventListener("timeupdate",this.onTimeUpdate),this.video.addEventListener("seeking",this.onSeeking),this.video.addEventListener("seeked",this.onSeeked),this.video.addEventListener("pause",this.onPause),this.video.addEventListener("play",this.onPlay),this.video.addEventListener("volumechange",this.onVolumeChange)}unbindTransport(){this.video.removeEventListener("timeupdate",this.onTimeUpdate),this.video.removeEventListener("seeking",this.onSeeking),this.video.removeEventListener("seeked",this.onSeeked),this.video.removeEventListener("pause",this.onPause),this.video.removeEventListener("play",this.onPlay),this.video.removeEventListener("volumechange",this.onVolumeChange)}headCount(){let e=0;for(let t of this.cues)if((e+=1)>=8&&t.startMs>=2e4)break;return Math.min(this.cues.length,Math.max(e,1))}async preloadHead(){return this.preloadSpan(0,this.headCount(),!1)}async preloadRest(){let e=this.headCount();e>=this.cues.length||await this.preloadSpan(e,this.cues.length,!1)}async preloadSpan(e,t,i){var s,n,r,a,l;let o=++this.preloadGen;this.hydrateFromSession(),this.preparing=i;let d=()=>{this.preparing&&this.pauseSelf()};i&&(this.pauseSelf(),this.video.addEventListener("play",d));let c=this.cues.length;try{for(let a=e;a<t;a+=40){if(this.destroyed||o!==this.preloadGen)return!1;let e=Math.min(t,a+40),l=this.cues.slice(a,e).map((e,t)=>({cue:e,index:a+t})).filter(e=>{var t;let{index:i}=e;return!(null===(t=this.pool.get(i))||void 0===t?void 0:t.src)&&!this.skipped.has(i)});if(0===l.length){i&&(null===(s=this.onStatus)||void 0===s||s.call(this,"Äang dá»ch ".concat(e,"/").concat(c,"â¦")));continue}try{let e=await fetch("/api/learn/dub/synthesize",{method:"POST",credentials:"same-origin",headers:{"Content-Type":"application/json"},body:JSON.stringify({voice:this.voice,items:l.map(e=>{let{cue:t,index:i}=e;return{idx:i,text:t.text||""}})})});if(e.ok)for(let t of(await e.json()).items||[]){if(t.skip||!t.audio
1Base64){this.skipped.add(t.idx);continue}this.putAudio(t.idx,function(e,t){let i=atob(e),s=new Uint8Array(i.length);for(let e=0;e<i.length;e++)s[e]=i.charCodeAt(e);return new Blob([s],{type:t})}(t.audioBase64,"audio/mpeg")),(null===(n=t.text)||void 0===n?void 0:n.trim())&&this.rememberSub(t.idx,t.text)}else for(let{index:e}of l){if(this.destroyed||o!==this.preloadGen)return!1;await this.ensureAudio(e)}}catch(e){for(let{index:e}of l){if(this.destroyed||o!==this.preloadGen)return!1;await this.ensureAudio(e)}}o===this.preloadGen&&!this.destroyed&&i&&(null===(r=this.onStatus)||void 0===r||r.call(this,"Äang dá»ch ".concat(e,"/").concat(c,"â¦")))}}finally{i&&(this.video.removeEventListener("play",d),this.preparing=!1)}return!this.destroyed&&o===this.preloadGen&&(i&&0===[...this.pool.values()].filter(e=>e.src).length?(null===(a=this.onStatus)||void 0===a||a.call(this,"Kh\xf4ng tạo ÄÆ°á»£c giá»ng cho b\xe0i n\xe0y."),null===(l=this.onFail)||void 0===l||l.call(this),!1):(this.emitTranscript(),!0))}hasCached(e){var t,i,s,n;return!!this.skipped.has(e)||null!==(t=this.pool.get(e))&&void 0!==t&&!!t.src||!(null===(s=this.cues[e])||void 0===s?void 0:null===(i=s.text)||void 0===i?void 0:i.trim())||!!(null===(n=C.get(this.cacheKey))||void 0===n?void 0:n.has(e))}hydrateFromSession(){let e=C.get(this.cacheKey),t=L.get(this.cacheKey);if(t)for(let[e,i]of t)this.viText.set(e,i);if(e)for(let t=0;t<this.cues.length;t++){var i;let s=e.get(t);!s||(null===(i=this.pool.get(t))||void 0===i?void 0:i.src)||this.putAudio(t,s,!1)}}rememberSub(e,t){let i=t.trim();if(!i)return;this.viText.set(e,i);let s=L.get(this.cacheKey);s||(s=new Map,L.set(this.cacheKey,s)),s.set(e,i)}emitTranscript(){var e;let t=L.get(this.cacheKey);if(t)for(let[e,i]of t)this.viText.set(e,i);let i=[];for(let e=0;e<this.cues.length;e++){let t=this.viText.get(e);t&&i.push(t)}i.length&&(null===(e=this.onTranscript)||void 0===e||e.call(this,i))}rememberBlob(e,t){let i=C.get(this.cacheKey);i||(i=new Map,C.set(this.cacheKey,i)),i.set(e,t)}putAudio(e,t){let i=!(arguments.length>2)||void 0===arguments[2]||arguments[2],s=this.pool.get(e);(null==s?void 0:s.src.startsWith("blob:"))&&URL.revokeObjectURL(s.src),i&&this.rememberBlob(e,t);let n=new Audio(URL.createObjectURL(t));n.preload="auto",this.pool.set(e,n),this.skipped.delete(e)}findIndexAtTime(e){let t=null!=e?e:1e3*this.video.currentTime;for(let e=0;e<this.cues.length;e++){let i=this.cues[e],s=this.cues[e+1],n=s?s.startMs:i.endMs;if(t>=i.startMs&&t<n)return e}return this.cues.length&&t>=this.cues[this.cues.length-1].startMs?this.cues.length-1:-1}handleTimeUpdate(){if(this.lastObservedTime=this.video.currentTime,!this.active||this.preparing||-1!==this.loadingIndex)return;let e=this.findIndexAtTime();e<0||e===this.currentIndex||this.playSegment(e)}handleSeeking(){this.audio.pause(),this.pendingIndex=-1}handlePlay(){if(this.resumeGuardUntil=performance.now()+600,!this.active||this.preparing)return;let e=this.findIndexAtTime();if(e>=0&&e===this.currentIndex&&this.audio.src&&!this.audio.ended){this.audio.play().catch(()=>void 0);return}e>=0&&this.playSegment(e)}handleSeeked(){if(!this.active||this.preparing)return;let e=this.video.currentTime,t=Math.abs(e-this.lastObservedTime)>=.8;if(this.lastObservedTime=e,!t||performance.now()<this.resumeGuardUntil){!this.video.paused&&this.audio.paused&&this.audio.src&&!this.audio.ended&&this.currentIndex>=0&&this.audio.play().catch(()=>void 0);return}this.audio.pause(),this.pendingIndex=-1,this.currentIndex=-1;let i=this.findIndexAtTime();i<0||this.playSegment(i)}handleAudioEnded(){}async playSegment(e){var t,i,s,n,r;if(!this.active||this.destroyed||this.preparing||e<0||e>=this.cues.length||e===this.currentIndex&&this.audio.src&&!this.audio.paused&&!this.audio.ended)return;this.currentIndex=e,this.loadingIndex=e;let a=this.cues[e].startMs/1e3,l=Math.max(0,this.video.currentTime-a);try{let n=null!==(i=this.pool.get(e))&&void 0!==i?i:null;if((null==n?void 0:n.src)||this.skipped.has(e)||(n=await this.ensureAudio(e)),!this.active||this.destroyed||this.currentIndex!==e)return;if(!n){let t=e+1;t<this.cues.length&&this.playSegment(t);return}if(this.detachSwap(n),null===(t=this.onSubtitle)||void 0===t||t.call(this,this.viText.get(e)||""),n.readyState<1&&await new Promise(e=>{n.addEventListener("loadedmetadata",()=>e(),{once:!0})}),!this.active||this.destroyed||this.currentIndex!==e)return;let r=Number.isFinite(n.duration)?n.duration:0,a=r>0?Math.min(l,Math.max(0,r-.05)):0;n.currentTime=a,await n.play(),this.firstReady||(this.firstReady=!0,null===(s=this.onStatus)||void 0===s||s.call(this,""))}catch(i){let t=e+1;t<this.cues.length&&this.active&&!this.destroyed?this.playSegment(t):(null===(n=this.onStatus)||void 0===n||n.call(this,"Kh\xf4ng ph\xe1t ÄÆ°á»£c giá»ng."),null===(r=this.onFail)||void 0===r||r.call(this))}finally{this.loadingIndex===e&&(this.loadingIndex=-1)}}async ensureAudio(e){let t=this.pool.get(e);if(null==t?void 0:t.src)return t;if(this.skipped.has(e))return null;if(this.fetching.has(e))return(await new Promise(e=>setTimeout(e,120)),this.destroyed)?null:this.ensureAudio(e);this.fetching.add(e);try{var i;let t=this.cues[e];if(!(null===(i=t.text)||void 0===i?void 0:i.trim()))return this.skipped.add(e),null;let s=await fetch("/api/learn/dub/synthesize",{method:"POST",credentials:"same-origin",headers:{"Content-Type":"application/json"},body:JSON.stringify({text:t.text,voice:this.voice})});if(!s.ok||204===s.status)return this.skipped.add(e),null;let n=await s.blob();if(!n.size)return this.skipped.add(e),null;return this.putAudio(e,n),this.pool.get(e)||null}catch(t){return this.skipped.add(e),null}finally{this.fetching.delete(e)}}applyOutput(){for(let e of(this.video.volume=this.active?this.outputVolume*this.duckVolume:this.outputVolume,this.audio.volume=this.outputVolume,this.pool.values())
1)e.volume=this.outputVolume}syncMute(){let e=this.video.muted;for(let t of(this.audio.muted=e,this.pool.values()))t.muted=e}detachSwap(e){let t=this.audio;t.removeEventListener("ended",this.onAudioEnded),t!==e&&t.pause(),this.audio=e,this.audio.volume=this.outputVolume,this.audio.muted=this.video.muted,this.audio.addEventListener("ended",this.onAudioEnded)}clearPool(){for(let e of(this.preloadGen+=1,this.pool.values()))e.pause(),e.src.startsWith("blob:")&&URL.revokeObjectURL(e.src),e.src="";this.pool.clear(),this.skipped.clear(),this.audio.pause(),this.audio.src="",this.firstReady=!1}constructor(e){var t;this.viText=new Map,this.audio=new Audio,this.pool=new Map,this.skipped=new Set,this.fetching=new Set,this.currentIndex=-1,this.pendingIndex=-1,this.loadingIndex=-1,this.nativeVolume=1,this.outputVolume=1,this.active=!1,this.preparing=!1,this.firstReady=!1,this.destroyed=!1,this.preloadGen=0,this.resumeGuardUntil=0,this.lastObservedTime=0,this.ignorePauseUntil=0,this.onTimeUpdate=()=>this.handleTimeUpdate(),this.onSeeking=()=>this.handleSeeking(),this.onSeeked=()=>this.handleSeeked(),this.onPause=()=>{this.audio.pause(),performance.now()>this.ignorePauseUntil&&this.markUserPaused(!0)},this.onPlay=()=>{this.preparing||this.markUserPaused(!1),this.handlePlay()},this.onVolumeChange=()=>this.syncMute(),this.onAudioEnded=()=>this.handleAudioEnded(),this.video=e.video,this.cues=e.cues,this.voice=e.voice,this.duckVolume=null!==(t=e.duckVolume)&&void 0!==t?t:.2,this.onStatus=e.onStatus,this.onReady=e.onReady,this.onFail=e.onFail,this.onSubtitle=e.onSubtitle,this.onTranscript=e.onTranscript,this.cacheKey=V(e.voice,e.cues),this.audio.volume=1,this.audio.addEventListener("ended",this.onAudioEnded)}}let U=new Map;class R{destroy(){var e,t;this.destroyed=!0,window.clearTimeout(this.sliceTimer),null===(e=this.probe)||void 0===e||e.pause(),null===(t=this.probe)||void 0===t||t.remove(),this.probe=null}async build(){var e,t,i,s;let n=U.get(this.opts.src);if(null==n?void 0:n.length)return n.map((e,t)=>({...e,idx:t}));let r=this.opts.duration;if(!Number.isFinite(r)||r<=0)throw Error("Chưa biết Äá» d\xe0i video.");let a=Math.max(1,Math.ceil(r/24)),l=[],o=[];for(let e=0;e<a;e+=1){let t=24*e,i=Math.min(24,Math.max(.4,r-t)),s=await this.readSliceCache(t);s?l[e]=s:o.push({index:e,start:t,len:i})}if(!o.length){let e=l.flat().map((e,t)=>({...e,idx:t}));if(!e.length)throw Error("Kh\xf4ng nháºn ÄÆ°á»£c lá»i thoại từ video.");return U.set(this.opts.src,e),e}let d=document.createElement("video");if(d.src=this.opts.src,d.preload="auto",d.playsInline=!0,d.volume=0,d.style.cssText="position:fixed;left:-9999px;width:2px;height:2px;opacity:0;pointer-events:none",document.body.appendChild(d),this.probe=d,await (e="loadeddata",new Promise((t,i)=>{let s=()=>{d.removeEventListener(e,s),d.removeEventListener("error",n),t()},n=()=>{d.removeEventListener(e,s),d.removeEventListener("error",n),i(Error("Kh\xf4ng má» ÄÆ°á»£c audio cá»§a video."))};d.addEventListener(e,s,{once:!0}),d.addEventListener("error",n,{once:!0})})),this.destroyed)return[];let c="function"==typeof d.captureStream?d.captureStream.bind(d):"function"==typeof d.mozCaptureStream?d.mozCaptureStream.bind(d):null;if(!c)throw Error("Tr\xecnh duyá»t kh\xf4ng lấy ÄÆ°á»£c audio Äá» dá»±ng script.");let u=o.length;for(let e=0;e<o.length;e+=1){if(this.destroyed)return[];let n=o[e],r=n.start,a=n.len;null===(t=(i=this.opts).onStatus)||void 0===t||t.call(i,"Äang lấy script ".concat(e+1,"/").concat(u));let h=[],m=await this.recordSlice(d,c,r,a);if(!m||m.size<1500||this.destroyed)continue;let p=new FormData;p.append("file",m,"slice.webm"),p.append("timed","1"),this.opts.assetId&&(p.append("assetId",this.opts.assetId),p.append("startSec",String(r)));let x=await fetch("/api/learn/dub/transcribe",{method:"POST",credentials:"same-origin",body:p}),v=await x.json().catch(()=>({}));if(!x.ok)throw Error(v.error||"Kh\xf4ng lấy ÄÆ°á»£c script.");let f=v.segments||[];if(f.length)for(let e of f){let t=String(e.text||"").trim(),i=r+(Number(e.start)||0),s=r+(Number(e.end)||0);t&&!(s<=i)&&h.push({idx:h.length,startMs:Math.round(1e3*i),endMs:Math.round(1e3*s),text:t})}else(null===(s=v.text)||void 0===s?void 0:s.trim())&&h.push({idx:0,startMs:Math.round(1e3*r),endMs:Math.round((r+a)*1e3),text:v.text.trim()});l[n.index]=h}d.pause(),d.remove(),this.probe=null;let h=l.flat().map((e,t)=>({...e,idx:t}));if(!h.length)throw Error("Kh\xf4ng nháºn ÄÆ°á»£c lá»i thoại từ video.");return U.set(this.opts.src,h),h}async readSliceCache(e){if(!this.opts.assetId)return null;let t=await fetch("/api/learn/dub/transcribe?assetId=".concat(encodeURIComponent(this.opts.assetId),"&startSec=").concat(e),{credentials:"same-origin"});if(!t.ok)return null;let i=await t.json().catch(()=>null);return(null==i?void 0:i.cached)&&i.cues?i.cues.map((e,t)=>({idx:t,startMs:Number(e.startMs)||0,endMs:Number(e.endMs)||0,text:String(e.text||"")})):null}recordSlice(e,t,i,s){return new Promise(n=>{let r=t=>{window.clearTimeout(this.sliceTimer);try{e.pause()}catch(e){}n(t)};e.pause();let a=()=>{let i,n;e.removeEventListener("seeked",a);try{i=t()}catch(e){r(null);return}let l=i.getAudioTracks();if(!l.length){r(null);return}let o=function(){for(let e of["audio/webm;codecs=opus","audio/webm","audio/mp4"])if("undefined"!=typeof MediaRecorder&&MediaRecorder.isTypeSupp
1orted(e))return e;return""}();try{let e=new MediaStream(l);n=o?new MediaRecorder(e,{mimeType:o}):new MediaRecorder(e)}catch(e){r(null);return}let d=[];n.ondataavailable=e=>{var t;(null===(t=e.data)||void 0===t?void 0:t.size)&&d.push(e.data)},n.onerror=()=>r(null),n.onstop=()=>{r(d.length?new Blob(d,{type:n.mimeType||"audio/webm"}):null)};try{n.start(),e.play()}catch(e){r(null);return}this.sliceTimer=window.setTimeout(()=>{if("recording"===n.state)try{n.stop()}catch(e){r(null)}},Math.max(400,1e3*s))};e.addEventListener("seeked",a),e.currentTime=i})}constructor(e){this.opts=e,this.destroyed=!1,this.probe=null,this.sliceTimer=0}}var F=i(93957),z=i(62233);let K=(0,F.default)(()=>Promise.all([i.e(573),i.e(47045)]).then(i.bind(i,47045)),{loadableGenerated:{webpack:()=>[47045]},ssr:!1,loading:()=>(0,s.jsx)(z.SkeletonPanel,{className:"min-h-48"})}),O="learn-dub-voice";function H(e){if(!Number.isFinite(e)||e<0)return"0:00";let t=Math.floor(e%60),i=Math.floor(e/60),s=Math.floor(i/60);return s>0?"".concat(s,":").concat(String(i%60).padStart(2,"0"),":").concat(String(t).padStart(2,"0")):"".concat(i,":").concat(String(t).padStart(2,"0"))}function B(){let e=new URLSearchParams(window.location.search),t="male"===e.get("ldubVoice")?"male":"female";return{categoryId:e.get("lcat"),courseId:e.get("lcourse"),lessonId:e.get("llesson"),dub:"0"!==e.get("ldub"),voice:t}}function D(e){let t=new URL(window.location.href),i=t.searchParams;void 0!==e.categoryId&&(e.categoryId?i.set("lcat",e.categoryId):i.delete("lcat")),void 0!==e.courseId&&(e.courseId?i.set("lcourse",e.courseId):i.delete("lcourse")),void 0!==e.lessonId&&(e.lessonId?i.set("llesson",e.lessonId):i.delete("llesson")),void 0!==e.dub&&(e.dub?i.delete("ldub"):i.set("ldub","0")),void 0!==e.voice&&("male"===e.voice?i.set("ldubVoice","male"):i.delete("ldubVoice"));let s="".concat(t.pathname).concat(i.toString()?"?".concat(i.toString()):"").concat(t.hash);window.history.replaceState(null,"",s)}function G(e){let{space:t,noteTypes:i}=e,[r,v]=(0,n.useState)([]),[f,g]=(0,n.useState)({categories:0,courses:0,lessons:0}),[y,b]=(0,n.useState)(""),[k,w]=(0,n.useState)(""),[j,N]=(0,n.useState)(!1),[S,E]=(0,n.useState)(new Set),[M,T]=(0,n.use
1State)(null),[A,I]=(0,n.useState)(null),[C,L]=(0,n.useState)([]),[V]=(0,n.useState)(()=>B().dub),[P]=(0,n.useState)(()=>B().voice),[U,R]=(0,n.useState)(!1),F=(0,n.useRef)(!1);(0,n.useEffect)(()=>{let e=window.setTimeout(()=>w(y.trim()),320);return()=>window.clearTimeout(e)},[y]);let K=(0,n.useCallback)(async()=>{N(!0);try{let e=await (0,l.QD)({search:k||void 0}),t=e.items||[];v(t),g({categories:e.totalCategories||0,courses:e.totalCourses||0,lessons:e.totalLessons||0}),E(e=>{let i=new Set(e);if(k||0===i.size){for(let e of t.slice(0,6))if(i.add("c:".concat(e.id)),k)for(let t of e.courses.slice(0,10))i.add("o:".concat(t.id))}return i})}catch(e){a.W.error(e instanceof Error?e.message:"Kh\xf4ng tải kh\xf3a há»c.")}finally{N(!1)}},[k]);(0,n.useEffect)(()=>{K()},[K]);let O=(0,n.useCallback)(async(e,t,i)=>{T({kind:"lesson",category:e,course:t,lesson:i}),E(i=>new Set(i).add("c:".concat(e.id)).add("o:".concat(t.id))),D({categoryId:"_none"===e.id?null:e.id,courseId:t.id,lessonId:i.id});try{let[{course:e},i]=await Promise.all([(0,l.E0)(t.id),(0,l.TT)(t.id)]);I(e),L(i.items)}catch(e){a.W.error(e instanceof Error?e.message:"Kh\xf4ng má» b\xe0i.")}},[]),H=(0,n.useCallback)(async(e,t)=>{T({kind:"course",category:e,course:t}),R(!1),I(null),L([]),E(i=>new Set(i).add("c:".concat(e.id)).add("o:".concat(t.id))),D({categoryId:"_none"===e.id?null:e.id,courseId:t.id,lessonId:null});try{let[{course:e},i]=await Promise.all([(0,l.E0)(t.id),(0,l.TT)(t.id)]);I(e),L(i.items)}catch(e){a.W.error(e instanceof Error?e.message:"Kh\xf4ng má» kh\xf3a.")}},[]),G=(0,n.useCallback)(e=>{T({kind:"category",category:e}),R(!1),I(null),L([]),E(t=>new Set(t).add("c:".concat(e.id))),D({categoryId:"_none"===e.id?null:e.id,courseId:null,lessonId:null})},[]);(0,n.useEffect)(()=>{if(F.current||0===r.length)return;let{categoryId:e,courseId:t,lessonId:i}=B();if(!e&&!t){F.current=!0;return}for(let s of(F.current=!0,r))if(!e||s.id===e||t&&!e){for(let n of s.courses)if(!t||n.id===t){if(!t&&e&&s.id===e){T({kind:"category",category:s}),E(e=>new Set(e).add("c:".concat(s.id)));return}if(t===n.id){if(i){let e=n.lessons.find(e=>e.id===i);if(e){O(s,n,e);return}}H(s,n);return}}if(e&&s.id===e){T({kind:"category",category:s}),E(e=>new Set(e).add("c:".concat(s.id)));return}}},[r,H,O]);let q=e=>{E(t=>{let i=new Set(t);return i.has(e)?i.delete(e):i.add(e),i})},_=(0,n.useMemo)(()=>M?"category"===M.kind?[{label:M.category.title}]:"course"===M.kind?[{label:M.category.title,onClick:()=>G(M.category)},{label:M.course.title}]:[{label:M.category.title,onClick:()=>G(M.category)},{label:M.course.title,onClick:()=>void H(M.category,M.course)},{label:M.lesson.title}]:[],[M,G,H]),Z=(null==M?void 0:M.kind)==="lesson"&&C.find(e=>e.id===M.lesson.id)||null;return(0,s.jsxs)("div",{className:"flex h-full min-h-0 flex-col gap-2",children:[(null==M?void 0:M.kind)==="lesson"?null:(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)("div",{className:"relative shrink-0",children:[(0,s.jsx)("input",{value:y,onChange:e=>b(e.target.value),placeholder:"T\xecm loại / kh\xf3a / b\xe0iâ¦",className:"w-full rounded-lg border border-border bg-background px-3 py-2 pr-8 text-sm"}),y?(0,s.jsx)("button",{type:"button",className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground",onClick:()=>b(""),"aria-label":"X\xf3a t\xecm",children:(0,s.jsx)(o.A,{className:"h-3.5 w-3.5"})}):null]}),(0,s.jsx)("p",{className:"shrink-0 text-xs text-muted-foreground",children:j?(0,s.jsx)(z.Z1,{className:"inline-block h-3 w-40 align-middle"}):"".concat(f.categories," loại \xb7 ").concat(f.courses," kh\xf3a \xb7 ").concat(f.lessons," b\xe0i")})]}),(0,s.jsxs)("div",{className:"grid min-h-0 flex-1 ".concat(U?"lg:grid-cols-1":(null==M?void 0:M.kind)==="lesson"?"lg:grid-cols-[minmax(0,1fr)_minmax(260px,320px)]":"lg:grid-cols-[minmax(200px,260px)_minmax(0,1fr)]"),children:[(0,s.jsxs)("div",{className:"flex min-h-0 flex-col overflow-hidden border-border bg-background ".concat(U?"hidden":(null==M?void 0:M.kind)==="lesson"?"order-2 border-l":"border-r"),children:[(0,s.jsx)("div",{className:"border-b border-border px-2.5 py-2 text-[10px] font-semibold uppercase tracking-wide text-muted-foreground",children:"C\xe2y path"}),(0,s.jsx)("div",{className:"min-h-0 flex-1 overflow-y-auto p-1.5",children:j&&0===r.length?(0,s.jsx)(z.iH,{rows:8,className:"[&>div]:border-0 [&>div]:bg-transparent [&>div]:p-2"}):0===r.length?(0,s.jsx)("p",{className:"p-2 text-xs text-muted-foreground",children:k?"Kh\xf4ng khá»p.":"Chưa ÄÆ°á»£c g\xe1n kh\xf3a há»c."}):r.map(e=>{let t="c:".concat(e.id),i=S.has(t),n=(null==M?void 0:M.kind)==="category"&&M.category.id===e.id;return(0,s.jsxs)("div",{className:"mb-0.5",children:[(0,s.jsxs)("div",{className:"flex items-center gap-0.5 rounded-lg ".concat(n?"bg-primary/15 text-primary":"hover:bg-muted/50"),children:[(0,s.jsx)("button",{type:"button",className:"shrink-0 rounded p-1 text-muted-foreground",onClick:()=>q(t),children:i?(0,s.jsx)(d.A,{className:"h-3.5 w-3.5"}):(0,s.jsx)(c.A,{className:"h-3.5 w-3.5"})}),(0,s.jsxs)("button",{type:"button",className:"flex min-w-0 flex-1 items-center gap-1.5 py-1.5 pr-2 text-left text-sm",onClick:()=>{T({kind:"category",category:e}),R(!1),I(null),D({categoryId:"_none"===e.id?null:e.id,courseId:null,lessonId:null}),i||q(t)},children:[(0,s.jsx)(u.A,{className:"h-3.5 w-3.5 shrink-0 opacity-70"}),(0,s.jsx)("span",{className:"truncate font-medium",children:e.title}),(0,s.jsx)("span",{className:"ml-auto shrink-0 text-[10px] text-muted-foreground",children:e.courseCount})]})]}),i?e.courses.map(t=>{let i="o:".concat(t.id),n=S.has(i),r=(null==M?void 0:M.kind)==="course"&&M.course.id===t.id;return(0,s.jsxs)("div",{className:"ml-3 border-l border-border pl-1",children:[(0,s.jsxs)("div",{className:"flex items-center gap-0.5 rounded-lg ".concat(r?"bg-primary/15 text-primary":"hover:bg-muted/50"),children:[(0,s.jsx)("button",{type:"button",className:"shrink-0 rounded p-1 text-muted-foreground",onClick:()=>q(i),children:n?(0,s.jsx)(d.A,{className:"h-3.5 w-3.5"}):(0,s.jsx)(c.A,{className:"h-3.5 w-3.5"})}),(0,s.jsxs)("button",{type:"button",className:"flex min-w-0 flex-1 items-center gap-1.5 py-1.5 pr-2 text-left text-sm",onClick:()=>void H(e,t),children:[(0,s.jsx)(h.A,{className:"h-3.5 w-3.5 shrink-0 opacity-70"}),(0,s.jsx)("span",{className:"truncate",children:t.title}),(0,s.jsx)("span",{className:"ml-auto shrink-0 text-[10px] text-muted-foreground",children:t.lessonCount})]})]}),n?t.lessons.map(i=>{let n=(null==M?void 0:M.kind)==="lesson"&&M.lesson.id===i.id;return(0,s.jsxs)("button",{type:"button",className:"ml-3 flex w-[calc(100%-0.75rem)] items-center gap-1.5 rounded-lg border-l border-border py-1.5 pl-2.5 pr-2 text-left text-sm ".concat(n?"bg-primary/15 text-primary":"hover:bg-muted/50"),onClick:()=>void O(e,t,i),children:[(0,s.jsx)(m.A,{className:"h-3.5 w-3.5 shrink-0 opacity-70"}),(0,s.jsx)("span",{className:"min-w-0 flex-1 truncate",children:i.title})]},i.id)}):null]},t.id)}):null]},e.id)})})]}),(0,s.jsx)("div",{className:"flex min-h-0 flex-col overflow-hidden ".concat((null==M?void 0:M.kind)!=="lesson"||U?"":"order-1"),children:M?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)("div",{className:"flex shrink-0 flex-wrap items-center gap-2 border-b border-border px-3 py-1.5",children:[(0,s.jsx)("nav",{className:"flex min-w-0 flex-1 flex-wrap items-center gap-1 text-xs text-muted-foreground",children:_.map((e,t)=>(0,s.jsxs)("span",{className:"inline-flex min-w-0 items-center gap-1",children:[t>0?(0,s.jsx)(c.A,{className:"h-3 w-3 shrink-0 opacity-50"}):null,e.onClick?(0,s.jsx)("button",{type:"button",onClick:e.onClick,className:"max-w-[10rem] truncate rounded px-0.5 text-left hover:text-primary hover:underline",title:e.label,children:e.label}):(0,s.jsx)("span",{className:"max-w-[14rem] truncate font-semibold text-foreground",title:e.label,children:e.label})]},"".concat(t,"-").concat(e.label)))}),(0,s.jsx)("button",{type:"button",onClick:()=>R(e=>!e),className:"inline-flex shrink-0 items-center gap-1 rounded-lg border border-border px-2.5 py-1.5 text-xs font-semibold",title:U?"Hiá»n c\xe2y path":"Thu c\xe2y path",children:U?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(p.A,{className:"h-3.5 w-3.5"})," Hiá»n c\xe2y"]}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(x.A,{className:"h-3.5 w-3.5"})," Thu c\xe2y"]})})]}),(0,s.jsxs)("div",{className:"min-h-0 flex-1 ".concat("lesson"===M.kind?"overflow-hidden":"overflow-y-auto p-3"),children:["category"===M.kind?(0,s.jsx)("div",{className:"grid gap-2 sm:grid-cols-2",children:M.category.courses.map(e=>(0,s.jsxs)("button",{type:"button",onClick:()=>void H(M.category,e),className:"rounded-xl border border-border bg-background p-2.5 text-left hover:border-primary/40",children:[(0,s.jsx)("div",{className:"mb-2 flex aspect-video items-center justify-center rounded-lg bg-muted/40",children:(0,s.jsx)(h.A,{className:"h-8 w-8 text-muted-foreground"})}),(0,s.jsx)("p",{className:"truncate text-sm font-semibold",children:e.title}),(0,s.jsxs)("p",{className:"text-[10px] text-muted-foreground",children:[e.lessonCount," b\xe0i"]})]},e.id))}):null,"course"===M.kind?(0,s.jsx)("div",{className:"grid gap-2 sm:grid-cols-2",children:0===M.course.lessons.length?(0,s.jsx)("p",{className:"text-xs text-muted-foreground",children:"Chưa c\xf3 b\xe0i."}):M.course.lessons.map(e=>(0,s.jsxs)("button",{type:"button",onClick:()=>void O(M.category,M.course,e),className:"rounded-xl border border-border bg-background p-2.5 text-left hover:border-primary/40",children:[(0,s.jsx)("div",{className:"mb-2 flex aspect-video items-center justify-center overflow-hidden rounded-lg bg-muted/40",children:e.primaryVideoId?(0,s.jsx)("video",{src:(0,l.gl)(e.primaryVideoId),className:"h-full w-full object-cover",muted:!0,preload:"metadata",playsInl
1ine:!0}):(0,s.jsx)(m.A,{className:"h-8 w-8 text-muted-foreground"})}),(0,s.jsx)("p",{className:"truncate text-sm font-semibold",children:e.title}),(0,s.jsxs)("p",{className:"text-[10px] text-muted-foreground",children:[e.videoCount," video \xb7 ",e.assetCount," file"]})]},e.id))}):null,"lesson"===M.kind&&A&&Z?(0,s.jsx)("div",{className:"h-full min-h-0",children:(0,s.jsx)(W,{spaceId:t.id,noteTypes:i,course:A,lesson:Z,lessons:C,initialDub:V,initialVoice:P,embedded:!0,onBack:()=>{R(!1),H(M.category,M.course)},onSelectLesson:e=>{let t=M.course.lessons.find(t=>t.id===e.id);t&&O(M.category,M.course,t)}})}):"lesson"===M.kind?(0,s.jsx)(z.SkeletonPanel,{className:"min-h-[16rem]"}):null]})]}):(0,s.jsx)("div",{className:"flex flex-1 items-center justify-center p-6",children:(0,s.jsx)("p",{className:"text-sm text-muted-foreground",children:"Chá»n loại / kh\xf3a / b\xe0i b\xean tr\xe1i."})})})]})]})}function W(e){let{spaceId:t,noteTypes:i,course:r,lesson:o,lessons:d,initialDub:c,initialVoice:u,embedded:m,onBack:p,onSelectLesson:x}=e,C=(0,n.useRef)(null),L=(0,n.useRef)(null),V=(0,n.useRef)(null),[U,F]=(0,n.useState)([]),[B,G]=(0,n.useState)(null),[W,q]=(0,n.use
1State)([]),[_,Z]=(0,n.useState)(c),[J,Q]=(0,n.useState)(!1),[X,Y]=(0,n.useState)("tailieu"),[$,ee]=(0,n.useState)(null),[et,ei]=(0,n.useState)(!0),[es,en]=(0,n.useState)(()=>{let e=window.localStorage.getItem(O);return"male"===e||"female"===e?e:u}),[er,ea]=(0,n.useState)(20),[el,eo]=(0,n.useState)(""),[ed,ec]=(0,n.useState)(""),[eu,eh]=(0,n.useState)(null),[em,ep]=(0,n.useState)(null),ex=(0,n.useRef)(!1),ev=(0,n.useRef)(null),[ef,eg]=(0,n.useState)({playing:!1,time:0,duration:0,muted:!1}),[ey,eb]=(0,n.useState)(1),ek=d.findIndex(e=>e.id===o.id),ew=ek>0?d[ek-1]:null,ej=ek>=0&&ek<d.length-1?d[ek+1]:null,eN=U.filter(e=>"VIDEO"!==e.type&&"SUBTITLE"!==e.type),eS=W.length>0,eE=el.startsWith("Äang dá»ch")||el.startsWith("Äang lấy"),eM=(0,n.useCallback)(e=>{ec(e.trim())},[]),eT=(0,n.useCallback)(e=>{let t=e.map(e=>e.trim()).filter(Boolean);ec(t[t.length-1]||"")},[]),eA=(0,n.useCallback)(async()=>{try{let{items:e}=await (0,l.Sw)(o.id);F(e);let t=e.find(e=>"VIDEO"===e.type&&e.isPrimary)||e.find(e=>"VIDEO"===e.type);G(t||null);let i=e.find(e=>"SUBTITLE"===e.type);if(i){let{items:e}=await (0,l.ln)(i.id);q(e)}else q([])}catch(e){a.W.error(e instanceof Error?e.message:"Kh\xf4ng tải asset.")}},[o.id]);(0,n.useEffect)(()=>{eA(),(0,l.Ky)(o.id).then(e=>{let{progress:t}=e;(null==t?void 0:t.lastPosition)&&C.current&&(C.current.currentTime=t.lastPosition),(null==t?void 0:t.dubEnabled)&&Z(!0)}).catch(()=>void 0)},[o.id,eA]),(0,n.useEffect)(()=>{let e=!1;return ei(!0),ee(null),(0,l.Tc)({spaceId:t,lessonId:o.id,lessonTitle:o.title}).then(t=>{e||ee(t.id)}).catch(t=>{e||a.W.error(t instanceof Error?t.message:"Kh\xf4ng má» ÄÆ°á»£c ghi ch\xfa.")}).finally(()=>{e||ei(!1)}),()=>{e=!0}},[t,o.id,o.title]),(0,n.useEffect)(()=>{D({dub:_,voice:es})},[_,es]),(0,n.useEffect)(()=>{Q(!1),ec("")},[null==B?void 0:B.id]),(0,n.useEffect)(()=>{let e=C.current;if(!e)return;let t=()=>{let t=ev.current,i=e.currentTime||0;null!=t&&.75>Math.abs(i-t)&&(ev.current=null,ep(null)),eg(t=>({playing:!e.paused&&!e.ended,time:ex.current||null!=ev.current?t.time:i,duration:Number.isFinite(e.duration)?e.duration:t.duration,muted:e.muted}))};return t(),e.addEventListener("play",t),e.addEventListener("pause",t),e.addEventListener("timeupdate",t),e.addEventListener("seeked",t),e.addEventListener("loadedmetadata",t),e.addEventListener("durationchange",t),e.addEventListener("volumechange",t),e.addEventListener("ended",t),()=>{e.removeEventListener("play",t),e.removeEventListener("pause",t),e.removeEventListener("timeupdate",t),e.removeEventListener("seeked",t),e.removeEventListener("loadedmetadata",t),e.removeEventListener("durationchange",t),e.removeEventListener("volumechange",t),e.removeEventListener("ended",t)}},[null==B?void 0:B.id]),(0,n.useEffect)(()=>{var e;if(null===(e=V.current)||void 0===e||e.destroy(),V.current=null,eo(""),!C.current||!J)return;let t=C.current;if(eS){let e=new P({video:t,cues:W.map(e=>({idx:e.idx,startMs:e.startMs,endMs:e.endMs,text:e.text})),voice:I[es],duckVolume:er/100,onStatus:eo,onFail:()=>Z(!1),onSubtitle:eM,onTranscript:eT});return V.current=e,_&&(t.pause(),e.start()),()=>{e.destroy()}}let i=()=>{t.pause()};t.pause(),t.addEventListener("play",i);let s=new R({src:t.currentSrc||t.src,assetId:(null==B?void 0:B.id)||"",duration:t.duration,onStatus:eo}),n=null,r=!1;return s.build().then(e=>{if(!r&&e.length)return t.removeEventListener("play",i),V.current=n=new P({video:t,cues:e,voice:I[es],duckVolume:er/100,onStatus:eo,onFail:()=>Z(!1),onSubtitle:eM,onTranscript:eT}),n.start()}).catch(e=>{eo(""),Z(!1),a.W.error(e instanceof Error?e.message:"Kh\xf4ng dá»±ng ÄÆ°á»£c lá»i thoại.")}),()=>{r=!0,t.removeEventListener("play",i),s.destroy(),null==n||n.destroy()}},[_,W,eS,es,null==B?void 0:B.id,J,eM,eT]),(0,n.useEffect)(()=>{var e;null===(e=V.current)||void 0===e||e.setDuckVolume(er/100)},[er]),(0,n.useEffect)(()=>{var e;window.localStorage.setItem(O,es),null===(e=V.current)||void 0===e||e.setVoice(I[es])},[es]),(0,n.useEffect)(()=>{let e=C.current;if(!e)return;let t=0,i=()=>{let i=Date.now();!(i-t<15e3)&&(eE||(t=i,(0,l.Li)({nodeId:o.id,assetId:null==B?void 0:B.id,position:e.currentTime,duration:e.duration||0,dubEnabled:_}).catch(()=>void 0)))};return e.addEventListener("timeupdate",i),()=>e.removeEventListener("timeupdate",i)},[o.id,null==B?void 0:B.id,_,eE]);let eI=async e=>{try{await (0,l.cL)(o.id,e,e.type.startsWith("video/")),a.W.success("Ä\xe3 tải l\xean."),await eA()}catch(e){a.W.error(e instanceof Error?e.message:"Upload thất bại.")}},eC=async e=>{if(!eu){eh(e.id);try{let{blob:t,filename:i}=await (0,l.jM)(e);(0,l.Qv)(t,i)}catch(e){a.W.error(e instanceof Error?e.message:"Kh\xf4ng tải ÄÆ°á»£c file.")}finally{eh(null)}}},eL=async()=>{let e=L.current||C.current;if(e)try{if(document.fullscreenElement){await document.exitFullscreen();return}await e.requestFullscreen()}catch(e){a.W.info("Tr\xecnh duyá»t kh\xf4ng há» trợ to\xe0n m\xe0n h\xecnh.")}};return(0,s.jsxs)("div",{className:"flex h-full min-h-0 flex-col",children:[(0,s.jsxs)("div",{ref:L,className:"relative aspect-video w-full max-h-[58%] shrink-0 overflow-hidden bg-black",children:[B?(0,s.jsx)("video",{ref:C,controlsList:"nodownload",disablePictureInPicture:!0,playsInl
1ine:!0,className:"absolute inset-0 h-full w-full bg-black object-contain",src:(0,l.gl)(B.id),preload:"auto",onClick:()=>{let e=C.current;e&&(e.paused?e.play():e.pause())},onLoadedData:()=>Q(!0),onCanPlay:()=>Q(!0),onContextMenu:e=>e.preventDefault()},B.id):(0,s.jsx)("div",{className:"flex h-full min-h-[12rem] items-center justify-center text-sm text-muted-foreground",children:"Chưa c\xf3 video."}),ed&&!eE?(0,s.jsx)("div",{className:"pointer-events-none absolute inset-x-0 bottom-14 z-10 flex justify-center px-4",children:(0,s.jsx)("p",{className:"max-w-[92%] rounded-lg border border-border bg-background/75 px-3 py-1.5 text-center text-sm font-medium leading-snug text-foreground backdrop-blur-md",children:ed})}):null,B?(0,s.jsxs)("div",{className:"absolute inset-x-0 bottom-0 z-30 flex items-center gap-2 border-t border-border bg-card/95 px-2 py-1.5",onClick:e=>e.stopPropagation(),children:[(0,s.jsx)("button",{type:"button",onClick:()=>{let e=C.current;e&&(e.paused?e.play():e.pause())},className:"rounded-lg p-1.5 text-foreground","aria-label":ef.playing?"Tạm dừng":"Ph\xe1t",children:ef.playing?(0,s.jsx)(k.A,{className:"h-4 w-4"}):(0,s.jsx)(w.A,{className:"h-4 w-4"})}),(0,s.jsxs)("span",{className:"w-[5.5rem] shrink-0 font-mono text-[10px] text-muted-foreground",children:[H(null!=em?em:ef.time)," / ",H(ef.duration)]}),(0,s.jsx)("input",{type:"range",min:0,max:ef.duration||0,step:.05,value:Math.min(null!=em?em:ef.time,ef.duration||0),onPointerDown:()=>{ex.current=!0},onInput:e=>{ex.current=!0,ep(Number(e.target.value))},onChange:e=>{let t=C.current,i=Number(e.target.value);ex.current=!1,ev.current=i,ep(i),t&&Number.isFinite(i)&&("function"==typeof t.fastSeek?t.fastSeek(i):t.currentTime=i)},onPointerCancel:()=>{ex.current=!1},className:"h-1 min-w-0 flex-1 cursor-pointer accent-primary","aria-label":"Thanh tua"}),(0,s.jsxs)("div",{className:"group/vol relative flex items-center",children:[(0,s.jsx)("div",{className:"absolute bottom-full left-1/2 z-30 hidden -translate-x-1/2 pb-1 group-hover/vol:block group-focus-within/vol:block",children:(0,s.jsx)("div",{className:"rounded-lg border border-border bg-card px-1.5 py-2",children:(0,s.jsx)("input",{type:"range",min:0,max:100,step:1,value:Math.round(100*ey),onChange:e=>{var t;let i=Number(e.target.value)/100;eb(i);let s=C.current;s&&(s.volume=i,s.muted=0===i),null===(t=V.current)||void 0===t||t.setOutputVolume(i)},className:"h-24 w-4 cursor-pointer accent-primary [direction:rtl] [writing-mode:vertical-lr]","aria-label":"\xc2m lượng"})})}),(0,s.jsx)("button",{type:"button",onClick:()=>{let e=C.current;if(e&&(e.muted=!e.muted,!e.muted&&0===ey)){var t;eb(1),e.volume=1,null===(t=V.current)||void 0===t||t.setOutputVolume(1)}},className:"rounded-lg p-1.5 text-foreground","aria-label":ef.muted||0===ey?"Báºt tiếng":"Tắt tiếng",children:ef.muted||0===ey?(0,s.jsx)(j,{className:"h-4 w-4"}):(0,s.jsx)(N.A,{className:"h-4 w-4"})})]}),(0,s.jsx)("button",{type:"button",onClick:()=>void eL(),className:"rounded-lg p-1.5 text-foreground","aria-label":"To\xe0n m\xe0n h\xecnh",children:(0,s.jsx)(S.A,{className:"h-4 w-4"})})]}):null,eE?(0,s.jsx)("div",{className:"pointer-events-none absolute inset-x-0 bottom-12 z-20 flex justify-center px-4",children:(0,s.jsxs)("div",{className:"flex max-w-sm flex-col items-center gap-2 text-center",children:[(0,s.jsx)(E.A,{className:"h-6 w-6 animate-spin text-primary"}),(0,s.jsx)("p",{className:"text-sm font-semibold text-white",children:"Äang dá»±ng lá»i thoại"}),(0,s.jsx)("p",{className:"text-xs text-white/80",children:el})]})}):null]}),(0,s.jsxs)("div",{className:"shrink-0 border-t border-border bg-card",children:[(0,s.jsxs)("div",{className:"flex flex-wrap items-center gap-2 px-3 py-2",children:[m?null:(0,s.jsxs)("button",{type:"button",onClick:p,className:"inline-flex items-center gap-1 rounded-lg border border-border px-2.5 py-1.5 text-xs font-semibold",children:[(0,s.jsx)(M.A,{className:"h-3.5 w-3.5"})," ",r.title]}),(0,s.jsx)("h2",{className:"min-w-0 flex-1 truncate text-sm font-semibold text-foreground",children:o.title}),(0,s.jsx)("button",{type:"button",disabled:!ew,onClick:()=>ew&&x(ew),className:"rounded-lg border border-border px-2.5 py-1.5 text-xs font-semibold disabled:opacity-50",children:"â B\xe0i trưá»c"}),(0,s.jsx)("button",{type:"button",disabled:!ej,onClick:()=>ej&&x(ej),className:"rounded-lg border border-border px-2.5 py-1.5 text-xs font-semibold disabled:opacity-50",children:"B\xe0i sau â"})]}),(0,s.jsxs)("div",{className:"flex flex-wrap items-center gap-2 px-3 pb-2",children:[(0,s.jsx)("button",{type:"button",onClick:()=>Z(e=>!e),className:"rounded-lg border px-3 py-1.5 text-xs font-semibold ".concat(_?"border-primary bg-primary/15 text-primary":"border-border text-muted-foreground"),title:eS?"Báºt/tắt lá»ng tiếng VI theo phụ Äá»":"Kh\xf4ng c\xf3 SRT â live STT + TTS (cần cấu h\xecnh STT)",children:"Lá»ng tiếng VI"}),(0,s.jsxs)("div",{className:"inline-flex overflow-hidden rounded-lg border border-border text-xs",children:[(0,s.jsx)("button",{type:"button",onClick:()=>en("female"),className:"px-2.5 py-1.5 font-semibold ".concat("female"===es?"bg-primary/15 text-primary":"text-muted-foreground"),children:"Nữ"}),(0,s.jsx)("button",{type:"button",onClick:()=>en("male"),className:"border-l border-border px-2.5 py-1.5 font-semibold ".concat("male"===es?"bg-primary/15 text-primary":"text-muted-foreground"),children:"Nam"})]}),(0,s.jsxs)("label",{className:"flex w-full items-center gap-2 text-xs text-muted-foreground",children:["\xc2m gá»c",(0,s.jsx)("input",{type:"range",min:0,max:100,value:er,onCh
1ange:e=>ea(Number(e.target.value)),className:"min-w-0 flex-1",disabled:!_}),(0,s.jsxs)("span",{className:"w-8 shrink-0 font-mono",children:[er,"%"]})]}),B?(0,s.jsxs)("button",{type:"button",onClick:()=>void eL(),className:"inline-flex items-center gap-1 rounded-lg border border-border px-2.5 py-1.5 text-xs font-semibold",children:[(0,s.jsx)(S.A,{className:"h-3.5 w-3.5"})," To\xe0n m\xe0n h\xecnh"]}):null,el?(0,s.jsx)("span",{className:"text-xs text-muted-foreground",children:el}):null,(0,s.jsx)("button",{type:"button",onClick:()=>{var e,t;(0,l.Li)({nodeId:o.id,assetId:null==B?void 0:B.id,position:(null===(e=C.current)||void 0===e?void 0:e.currentTime)||0,duration:(null===(t=C.current)||void 0===t?void 0:t.duration)||0,completed:!0,dubEnabled:_}).then(()=>a.W.success("Ä\xe3 Ä\xe1nh dấu xong."))},className:"rounded-lg border border-border px-2.5 py-1.5 text-xs font-semibold",children:"Ä\xe1nh dấu xong"}),(0,s.jsxs)("label",{className:"inline-flex cursor-pointer items-center gap-1 rounded-lg border border-border px-2.5 py-1.5 text-xs font-semibold",children:[(0,s.jsx)(T.A,{className:"h-3.5 w-3.5"})," Tải file",(0,s.jsx)("input",{type:"file",className:"hidden",onChange:e=>{var t;let i=null===(t=e.target.files)||void 0===t?void 0:t[0];i&&eI(i),e.target.value=""}})]})]}),(0,s.jsxs)("div",{className:"mx-3 mb-2 inline-flex overflow-hidden rounded-lg border border-border text-xs",children:[(0,s.jsxs)("button",{type:"button",onClick:()=>Y("tailieu"),className:"px-3 py-1.5 font-semibold ".concat("tailieu"===X?"bg-primary/15 text-primary":"text-muted-foreground"),children:["T\xe0i liá»u (",eN.length,")"]}),(0,s.jsx)("button",{type:"button",onClick:()=>Y("ghichu"),className:"border-l border-border px-3 py-1.5 font-semibold ".concat("ghichu"===X?"bg-primary/15 text-primary":"text-muted-foreground"),children:"Ghi ch\xfa"})]})]}),(0,s.jsx)("div",{className:"min-h-0 flex-1 overflow-hidden border-t border-border bg-background",children:"tailieu"===X?0===eN.length?(0,s.jsx)("p",{className:"p-3 text-xs text-muted-foreground",children:"Chưa c\xf3 t\xe0i liá»u k\xe8m."}):(0,s.jsx)("div",{className:"grid grid-cols-2 gap-2 overflow-y-auto p-2 sm:grid-cols-3 md:grid-cols-4",children:eN.map(e=>{var t,i;let n=(0,l.iI)(e),r="IMAGE"===(t=e.type)?v.A:"VIDEO"===t?h.A:"AUDIO"===t?f.A:"ARCHIVE"===t?g.A:"DOCUMENT"===t||"SOURCE_CODE"===t||"SUBTITLE"===t?y.A:b.A,a=eu===e.id,o=(i=e.sizeBytes)&&!(i<0)?i<1024?"".concat(i," B"):i<1048576?"".concat((i/1024).toFixed(1)," KB"):"".concat((i/1048576).toFixed(1)," MB"):"";return(0,s.jsxs)("button",{type:"button",disabled:a,onClick:()=>void eC(e),title:"Tải ".concat(n),className:"flex flex-col items-center gap-2 rounded-xl border border-border bg-card p-3 text-center hover:border-primary/50 disabled:opacity-50",children:[(0,s.jsx)(r,{className:"h-8 w-8 text-primary"}),(0,s.jsx)("span",{className:"line-clamp-2 w-full text-xs font-semibold text-foreground",children:n}),(0,s.jsxs)("span",{className:"inline-flex items-center gap-1 text-[10px] text-muted-foreground",children:[(0,s.jsx)(A.A,{className:"h-3 w-3"}),a?"Äang tảiâ¦":o||"Tải"]})]},e.id)})}):et?(0,s.jsxs)("div",{className:"space-y-3 p-3","aria-busy":"true",children:[(0,s.jsx)(z.Z1,{className:"h-8 w-full rounded-lg"}),(0,s.jsx)(z.Z1,{className:"h-40 w-full rounded-xl"})]}):$?(0,s.jsx)("div",{className:"h-full min-h-0 overflow-y-auto",children:(0,s.jsx)(K,{noteId:$,noteTypes:i,onSaved:()=>void 0,onDeleted:()=>ee(null),onNoteTypeCreated:()=>void 0,compact:!0})}):(0,s.jsx)("p",{className:"p-3 text-xs text-muted-foreground",children:"Kh\xf4ng tạo ÄÆ°á»£c ghi ch\xfa."})})]})}let q="Ghi ch\xfa video";function _(){return(0,s.jsx)(r.Ay,{hint:"ÄÄng nháºp Äá» xem kh\xf3a há»c video.",authNext:"/courses",children:(0,s.jsx)(Z,{})})}function Z(){let[e,t]=(0,n.useState)(null),[i,r]=(0,n.useState)([]),[o,d]=(0,n.useState)(!0),[c,u]=(0,n.use
1State)(!1);return((0,n.useEffect)(()=>{let e=!1;return(async()=>{try{await (0,l.So)({limit:1,offset:0});let[i,s]=await Promise.all([(0,l.Ew)(),(0,l.iF)({limit:50,offset:0})]);if(e)return;r(i);let n=s.items.find(e=>e.name===q);if(n){t(n);return}let a=await (0,l.bz)({name:q,description:"Ghi ch\xfa gắn b\xe0i há»c video"});e||t(a)}catch(t){if(e)return;if(403===(null==t?void 0:t.status)){u(!0);return}a.W.error(t instanceof Error?t.message:"Kh\xf4ng má» ÄÆ°á»£c kh\xf3a há»c."),u(!0)}finally{e||d(!1)}})(),()=>{e=!0}},[]),o)?(0,s.jsx)(z.SkeletonPanel,{className:"min-h-[20rem]"}):c||!e?(0,s.jsx)("div",{className:"p-2.5",children:(0,s.jsx)("p",{className:"text-sm text-muted-foreground",children:"Kh\xf4ng c\xf3 quyá»n truy cáºp."})}):(0,s.jsx)("div",{className:"flex h-[calc(100dvh-8rem)] min-h-[28rem] flex-col",children:(0,s.jsx)(G,{space:e,noteTypes:i})})}},22293:(e,t,i)=>{i.d(t,{A:()=>s});let s=(0,i(41285).A)("Film",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M7 3v18",key:"bbkbws"}],["path",{d:"M3 7.5h4",key:"zfgn84"}],["path",{d:"M3 12h18",key:"1i2n21"}],["path",{d:"M3 16.5h4",key:"1230mu"}],["path",{d:"M17 3v18",key:"in4fa5"}],["path",{d:"M17 7.5h4",key:"myr1c1"}],["path",{d:"M17 16.5h4",key:"go4c1d"}]])},34771:(e,t,i)=>{i.d(t,{A:()=>s});let s=(0,i(41285).A)("Pause",[["rect",{x:"14",y:"4",width:"4",height:"16",rx:"1",key:"zuxfzm"}],["rect",{x:"6",y:"4",width:"4",height:"16",rx:"1",key:"1okwgv"}]])},41447:(e,t,i)=>{i.d(t,{A:()=>s});let s=(0,i(41285).A)("Download",[["path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4",key:"ih7n3h"}],["polyline",{points:"7 10 12 15 17 10",key:"2ggqvy"}],["line",{x1:"12",x2:"12",y1:"15",y2:"3",key:"1vk2je"}]])},42343:(e,t,i)=>{i.d(t,{A:()=>s});let s=(0,i(41285).A)("FileText",[["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"}],["path",{d:"M10 9H8",key:"b1mrlr"}],["path",{d:"M16 13H8",key:"t4e002"}],["path",{d:"M16 17H8",key:"z1uh3a"}]])},51661:(e,t,i)=>{i.d(t,{A:()=>s});let s=(0,i(41285).A)("Play",[["polygon",{points:"6 3 20 12 6 21 6 3",key:"1oa8hb"}]])},57647:(e,t,i)=>{i.d(t,{A:()=>s});let s=(0,i(41285).A)("PanelLeft",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M9 3v18",key:"fh3hqa"}]])},58451:(e,t,i)=>{i.d(t,{A:()=>s});let s=(0,i(41285).A)("Folder",[["path",{d:"M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z",key:"1kt360"}]])},58622:(e,t,i)=>{i.d(t,{A:()=>s});let s=(0,i(41285).A)("Music",[["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"}]])},59022:(e,t,i)=>{i.d(t,{A:()=>s});let s=(0,i(41285).A)("Upload",[["path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4",key:"ih7n3h"}],["polyline",{points:"17 8 12 3 7 8",key:"t8dd8p"}],["line",{x1:"12",x2:"12",y1:"3",y2:"15",key:"widbto"}]])},70686:(e,t,i)=>{i.d(t,{A:()=>s});let s=(0,i(41285).A)("Maximize2",[["polyline",{points:"15 3 21 3 21 9",key:"mznyad"}],["polyline",{points:"9 21 3 21 3 15",key:"1avn1i"}],["line",{x1:"21",x2:"14",y1:"3",y2:"10",key:"ota7mn"}],["line",{x1:"3",x2:"10",y1:"21",y2:"14",key:"1atl0r"}]])},72313:(e,t,i)=>{i.d(t,{Ay:()=>c,MI:()=>o,zm:()=>d});var s=i(95818),n=i(61003),r=i.n(n),a=i(5208),l=i(62233);function o(){return(0,s.jsx)(l.SkeletonPanel,{className:"py-8",children:(0,s.jsxs)("div",{className:"mx-auto max-w-md space-y-3",children:[(0,s.jsx)(l.Z1,{className:"h-5 w-40"}),(0,s.jsx)(l.rr,{lines:3})]})})}function d(e){let{hint:t,authNext:i}=e;return(0,s.jsxs)("div",{className:"rounded-xl border border-border bg-card px-4 py-8 text-center text-sm text-muted-foreground",children:[(0,s.jsx)("p",{children:t}),(0,s.jsx)(r(),{href:"/auth?next=".concat(encodeURIComponent(i)),className:"mt-3 inline-flex rounded-lg border border-primary bg-accent px-3 py-1.5 text-xs font-semibold text-primary",children:"ÄÄng nháºp"})]})}function c(e){let{hint:t,authNext:i,children:n}=e,{user:r,isPending:l}=function(){var e;let{data:t,isPending:i}=(0,a.wV)();return{session:t,user:null==t?void 0:t.user,userId:null==t?void 0:null===(e=t.user)||void 0===e?void 0:e.id,isPending:i}}();return l?(0,s.jsx)(o,{}):r?(0,s.jsx)(s.Fragment,{children:n}):(0,s.jsx)(d,{hint:t,authNext:i})}},73160:(e,t,i)=>{i.d(t,{A:()=>s});let s=(0,i(41285).A)("Image",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",ry:"2",key:"1m3agn"}],["circle",{cx:"9",cy:"9",r:"2",key:"af1f0g"}],["path",{d:"m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21",key:"1xmnt7"}]])},73511:(e,t,i)=>{i.d(t,{A:()=>s});let s=(0,i(41285).A)("FileVideo",[["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"}],["path",{d:"m10 11 5 3-5 3v-6Z",key:"7ntvm4"}]])},85498:(e,t,i)=>{i.d(t,{A:()=>s});let s=(0,i(41285).A)("PanelLeftClose",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M9 3v18",key:"fh3hqa"}],["path",{d:"m16 15-3-3 3-3",key:"14y99z"}]])}}]);
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.