(()=>{"use strict";var e={};// The module cache
var t={};// The require function
function r(o){// Check if module is in cache
var s=t[o];if(s!==undefined){return s.exports}// Create a new module (and put it into the cache)
var a=t[o]={exports:{}};// Execute the module function
e[o](a,a.exports,r);// Return the exports of the module
return a.exports}// webpack/runtime/rspack_version
(()=>{r.rv=()=>"1.6.5"})();// webpack/runtime/rspack_unique_id
(()=>{r.ruid="bundler=rspack@1.6.5"})();// CONCATENATED MODULE: external "wp.i18n"
const o=wp.i18n;// CONCATENATED MODULE: ../tutor/assets/core/ts/constant.ts
var s={TAB_CHANGE:"tutor-tab-change",MODAL_OPEN:"tutor-modal-open",MODAL_UPDATE:"tutor-modal-update",MODAL_CLOSE:"tutor-modal-close",MODAL_CLOSED:"tutor-modal-closed",TOAST_SHOW:"tutor-toast-show",TOAST_CLEAR:"tutor-toast-clear",FORM_REGISTER:"tutor-form-register",FORM_UNREGISTER:"tutor-form-unregister",FORM_STATE_CHANGE:"tutor-form-state-change",FORM_RESET:"tutor-form-reset",WP_EDITOR_FOCUS:"wp-editor-focus",TUTOR_PLAYER_READY:"tutor-player-ready",COMMENT_REPLIED:"tutor:comment:replied",LESSON_PLAYER_READY:"tutorLessonPlayerReady",QUIZ_TIME_EXPIRED:"tutor-quiz-time-expired",QUIZ_ABANDON_REQUESTED:"tutor-quiz-abandon-requested",QUIZ_ATTEMPT_COMPLETED:"tutor-quiz-attempt-completed",CONTENT_CHANGED:"tutor_content_changed_event"};// CONCATENATED MODULE: ./assets/src/js/notes/learning-area-notes.ts
var a="tutor-lesson-note-";var n="tutor-note-content-";var i="tutor-create-lesson-note-form";var l="tutor-edit-lesson-note-form-";var d="delete-note-modal";var u={NOTE_ITEM:"tutor-lesson-note"};var h={NOTE_SAVED:"tutor-note-saved",NOTE_DELETED:"tutor-note-deleted"};/**
 * LearningArea Notes Page Component
 */var c=function(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:0;var{query:r,form:c,modal:_,toast:m}=window.TutorCore;var{wpPost:f}=window.TutorCore.api;var{convertToErrorMessage:E}=window.TutorCore.error;return{query:r,lessonId:e||null,editingId:null,totalNotes:t,currentPage:1,loading:false,hasMore:true,currentOrder:"DESC",currentType:"",isReloading:false,isEmpty:false,$el:null,$refs:{},createMutation:null,deleteMutation:null,updateMutation:null,init(){// Initialize order from URL.
var e=new URL(window.location.href);var t=e.searchParams.get("order");this.currentOrder=t==="ASC"?"ASC":"DESC";var r=e.searchParams.get("type");this.currentType=r||"";this.currentPage=1;var s=this.$refs.noteList.querySelectorAll(":scope > .".concat(u.NOTE_ITEM)).length;this.hasMore=this.totalNotes>s;this.isEmpty=s===0;this.initInfiniteScroll();// Listen for tutor-note-saved event to reload the list
document.addEventListener(h.NOTE_SAVED,()=>{this.reloadNotes()});// Listen for tutor-note-deleted event to reload the list
document.addEventListener(h.NOTE_DELETED,()=>{this.reloadNotes()});this.handleInitialPlayTime();// Setup create note mutation
this.createMutation=this.query.useMutation(this.createNote,{onSuccess:e=>{m.success(e.message||(0,o.__)("Note created successfully","tutor-pro"));var t=e.data;if(t===null||t===void 0?void 0:t.html){if(this.currentOrder==="DESC"){this.$refs.noteList.insertAdjacentHTML("afterbegin",t.html)}else if(!this.hasMore){this.$refs.noteList.insertAdjacentHTML("beforeend",t.html)}}this.totalNotes++;this.isEmpty=false;var r=i;if(c.hasForm(r)){c.reset(r)}},onError:e=>{m.error(E(e))}});// Setup delete mutation
this.deleteMutation=this.query.useMutation(this.deleteNote,{onSuccess:(e,t)=>{_.closeModal(d);m.success(e.message||(0,o.__)("Note deleted successfully","tutor-pro"));var r=document.getElementById("".concat(a).concat(t.note_id));if(r){r.remove()}this.totalNotes--;if(this.hasMore){this.loadNextPage()}this.isEmpty=this.$refs.noteList.querySelectorAll(":scope > .".concat(u.NOTE_ITEM)).length===0;// Remove highlight elements associated with this note
var s=document.querySelectorAll('[data-note-id="'.concat(t.note_id,'"]'));s.forEach(e=>{if(e.tagName.toLowerCase()==="mark"){var t=e.parentNode;while(e.firstChild){t===null||t===void 0?void 0:t.insertBefore(e.firstChild,e)}t===null||t===void 0?void 0:t.removeChild(e);t===null||t===void 0?void 0:t.normalize()}})},onError:e=>{_.closeModal(d);m.error(E(e))}});// Setup update mutation
this.updateMutation=this.query.useMutation(this.updateNote,{onSuccess:(e,t)=>{m.success(e.message||(0,o.__)("Note updated successfully","tutor-pro"));this.editingId=null;// Update UI
var r=document.getElementById(n+t.note_id);if(r){r.innerHTML=t.note_text}// Update note content in lesson overview
var s=document.querySelectorAll('mark[data-note-id="'.concat(t.note_id,'"]'));s.forEach(e=>{e.dataset.noteContent=t.note_text})},onError:e=>{m.error(e.message||(0,o.__)("Failed to update note","tutor-pro"))}})},createNote(e){var t=window.TutorLessonPlayer;if(t&&typeof t.currentTime==="number"){e["video_start_time"]=Math.floor(t.currentTime)}return f("tutor_pro_save_lesson_note",e)},deleteNote(e){return f("tutor_pro_delete_lesson_note",e)},updateNote(e){return f("tutor_pro_update_lesson_note",e)},handleDeleteNote(e,t){_.showModal(d,{note_id:e,lesson_id:t})},handleEditNote(e){this.editingId=e;this.$nextTick(()=>{var t="".concat(l).concat(e);if(c.hasForm(t)){c.setFocus(t,"note_text")}})},handleChangeOrder(e){if(this.currentOrder===e)return;this.currentOrder=e;this.updateURLParam("order",e);this.reloadNotes()},handleChangeType(e){if(this.currentType===e)return;this.currentType=e;this.updateURLParam("type",e);this.reloadNotes()},updateURLParam(e,t){var r=new URL(window.location.href);if(t){r.searchParams.set(e,t)}else{r.searchParams.delete(e)}window.history.pushState({},"",r)},reloadNotes(){this.isReloading=true;this.currentPage=1;this.hasMore=false;f("tutor_pro_lesson_notes_load_more",{lesson_id:this.lessonId,offset:0,order:this.currentOrder,type:this.currentType}).then(e=>{var t;this.$refs.noteList.innerHTML=e.data.html;this.hasMore=e.data.has_more;if(e.data.total_notes!==undefined){this.totalNotes=e.data.total_notes}this.isEmpty=!((t=e.data.html)===null||t===void 0?void 0:t.trim())}).catch(e=>{m.error(E(e))}).finally(()=>{this.isReloading=false})},loadNextPage(){if(!this.lessonId||this.loading||!this.hasMore){return}this.loading=true;// Calculate offset based on main notes in DOM.
var e=this.$refs.noteList.querySelectorAll(":scope > .".concat(u.NOTE_ITEM)).length;f("tutor_pro_lesson_notes_load_more",{lesson_id:this.lessonId,offset:e,order:this.currentOrder,type:this.currentType}).then(e=>{var t;if(e.data.has_more!==undefined){this.hasMore=e.data.has_more}if((t=e.data.html)===null||t===void 0?void 0:t.trim()){this.currentPage++;this.$refs.noteList.insertAdjacentHTML("beforeend",e.data.html)}this.isEmpty=this.$refs.noteList.querySelectorAll(":scope > .".concat(u.NOTE_ITEM)).length===0}).catch(e=>{m.error(E(e))}).finally(()=>{this.loading=false})},handlePlayVideoClip(e){var t=e.currentTarget;var r=Number(t.getAttribute("data-start-time"));var o=window.TutorLessonPlayer;if(o){if(typeof o.currentTime!=="undefined"){o.currentTime=r}if(typeof o.play==="function"){o.play()}window.scrollTo({top:0,behavior:"smooth"})}},/**
     * Handle initial play time
     *
     * Checks for `tutor_play_time` query param in the URL.
     * If present, seeks the video player to that time and removes the param.
     *
     * @returns void
     */handleInitialPlayTime(){var e=new URL(window.location.href);var t=e.searchParams.get("tutor_play_time");if(!t)return;var r=parseInt(t);var o=t=>{setTimeout(()=>{t.currentTime=r;// Remove the query param from the URL without reloading the page
e.searchParams.delete("tutor_play_time");window.history.replaceState({},"",e.toString())},100)};if(window.TutorLessonPlayer){o(window.TutorLessonPlayer)}else{window.addEventListener(s.LESSON_PLAYER_READY,e=>{o(e.detail.player)})}},handleKeydown(e){if((e.metaKey||e.ctrlKey)&&e.key==="Enter"){var t;(t=e.target.closest("form"))===null||t===void 0?void 0:t.requestSubmit()}},initInfiniteScroll(){var e=new IntersectionObserver(e=>{var[t]=e;if(t.isIntersecting&&this.hasMore&&!this.loading){this.loadNextPage()}},{rootMargin:"200px"});e.observe(this.$refs.loadMoreTrigger)}}};var _=()=>{window.TutorComponentRegistry.register({type:"component",meta:{name:"learningAreaNotes",component:c}});window.TutorComponentRegistry.initWithAlpine(window.Alpine)};document.addEventListener("alpine:init",_)})();