(()=>{"use strict";var e={};/************************************************************************/// The module cache
var t={};// The require function
function r(o){// Check if module is in cache
var a=t[o];if(a!==undefined){return a.exports}// Create a new module (and put it into the cache)
var i=t[o]={exports:{}};// Execute the module function
e[o](i,i.exports,r);// Return the exports of the module
return i.exports}/************************************************************************/// webpack/runtime/rspack_version
(()=>{r.rv=()=>"1.4.11"})();// webpack/runtime/rspack_unique_id
(()=>{r.ruid="bundler=rspack@1.4.11"})();/************************************************************************/;// CONCATENATED MODULE: ./node_modules/@swc/helpers/esm/_async_to_generator.js
function o(e,t,r,o,a,i,n){try{var l=e[i](n);var d=l.value}catch(e){r(e);return}if(l.done)t(d);else Promise.resolve(d).then(o,a)}function a(e){return function(){var t=this,r=arguments;return new Promise(function(a,i){var n=e.apply(t,r);function l(e){o(n,a,i,l,d,"next",e)}function d(e){o(n,a,i,l,d,"throw",e)}l(undefined)})}};// CONCATENATED MODULE: ./assets/react/admin-dashboard/template-import-script.js
/**
 * Template Import Script
 *
 * This file contains utilities and high-level documentation for the template import
 * workflow and the live preview UI. It describes behavior implemented below:
 * - tutor course data import (supports .zip and JSON import via chunked job)
 * - plugin installation and template import flow (fetch/AJAX POSTs, processing loop)
 * - preview modal management (open/close, shimmer loading state)
 * - device preview switching and iframe resizing/scale handling
 * - communication with the preview iframe (postMessage) for Droip color presets and mode
 *
 * Notes:
 * - This script relies on a global _tutorobject (nonce, ajax URL, site_url, etc.).
 * - Keep DOM selectors and event handlers idempotent because the admin UI may be re-rendered.
 *
 * @file template-import-script.js
 * @since v3.9.2
 */document.addEventListener("DOMContentLoaded",function(){var e=document.querySelector(".tutor-template-import-area");var t=document.querySelector(".tutor-template-preview-modal");var r=document.querySelector(".tutor-template-preview-iframe-parent");var o=document.getElementById("tutor-template-preview-iframe");var a=document.querySelector(".tutor-template-preview-modal-back-link");var n=document.querySelectorAll(".tutor-template-preview-device-switcher li");var l=document.querySelector(".tutor-preview-template-name");var d=document.querySelector(".tutor-template-shimmer-effect");var s=document.querySelector(".tutor-template-import-btn");var c=document.getElementById("tutor_template_course_data_url");var u=document.getElementById("droip-color-presets");var v=document.querySelector(".tutor-droip-color-presets-heading");if(e){// Open live preview modal
e.addEventListener("click",e=>{if(e.target.closest(".tutor-template-preview-btn")){document.body.style.overflow="hidden";d.style.display="block";r.classList.remove("tutor-divider");t.style.display="flex";l.innerText=e.target.dataset.template_name;if(c){c.value=e.target.dataset.template_course_data_url}o.src=e.target.dataset.template_url;s.setAttribute("data-import_template_id",e.target.dataset.template_id)}});// Hide loading indicator when iframe is fully loaded
o.addEventListener("load",function(){d.style.display="none";r.classList.add("tutor-divider")});a===null||a===void 0?void 0:a.addEventListener("click",function(){p();var e=s.querySelector("i");s.classList.remove("is-loading");s.classList.add("tutor-template-import-btn");s.classList.remove("tutor-template-view-template-btn");e.classList.add("tutor-icon-import");e.classList.remove("tutor-icon-circle-mark")});// Device switcher
n.forEach(e=>{e.addEventListener("click",function(){m(n);e.classList.add("active");var t=this.getAttribute("data-width");o.style.width=t+"px";i()})});// Reset preview modal
function p(){t.style.display="none";o.src="";m(n);n[0].classList.add("active");d.style.display="none";document.body.style.overflow="visible";o.style.width="1400px";o.style.transformOrigin="left top";u.style.display="none";v.style.display="none"}// Remove active class from device list
function m(e){e.forEach(e=>{e.classList.remove("active")})}}});function i(){var e=document.querySelector(".tutor-template-preview-iframe-parent");var t=e.querySelector(".tutor-template-preview-iframe-parent iframe");var r=document.querySelector(".tutor-template-preview-device-switcher li.active");var o=r.getAttribute("data-width")||1400;var a=e.offsetWidth;if(a<Number(o)){var i=a/Number(o);if(i>0){t.style.transform="scale(".concat(i,")");t.style.transformOrigin="left top";t.style.height="".concat(100/i,"%")}}else{t.style.transformOrigin="center top"}}window.addEventListener("resize",i);document.addEventListener("DOMContentLoaded",function(){var{__}=wp.i18n;var e=document.querySelector(".tutor-template-import-area");var t=document.querySelector(".tutor-template-import-btn");var r=document.getElementById("include-demo-courses");var o;var i=false;if(e){document.addEventListener("click",e=>{if(e.target.closest(".tutor-template-import-btn")){t.classList.add("is-loading");t.setAttribute("disabled","disabled");var r=t.querySelector("i");t.innerHTML="".concat(r.outerHTML," Importing");l()}});document.addEventListener("click",e=>{if(e.target.closest(".tutor-template-view-template-btn")){window.open(_tutorobject.site_url,"_blank")}});var n=["tutorbase","droip"];// install required plugin.
function l(){return a(function*(){i=false;for(var e=0;e<n.length;e++){try{var r=new FormData;r.append("action","tutor_template_required_plugin_install");r.append(_tutorobject.nonce_key,_tutorobject._tutor_nonce);r.append("plugin_name",n[e]);var a=yield fetch(_tutorobject.ajaxurl,{method:"POST",body:r});var l=yield a.json();if(200===l.status_code){i=true}else{u();tutor_toast(__("Error","tutor-pro"),l===null||l===void 0?void 0:l.message,"error");return}}catch(e){u();tutor_toast(__("Something went wrong!","tutor-pro"),"","error");return}}// if plugin installation done start importing template content.
if(i){o=t.getAttribute("data-import_template_id");try{var c=yield d();var v=yield c.json();if(c.ok&&200===v.status_code){s()}else{throw new Error((v===null||v===void 0?void 0:v.message)||__("Template import failed!","tutor-pro"))}}catch(e){u();tutor_toast(__("Error","tutor-pro"),__(e===null||e===void 0?void 0:e.message,"tutor-pro"),"error");return}}})()}// import template zip file.
var d=()=>a(function*(){var e;var t=(e=document.querySelector(".color-palette.active"))===null||e===void 0?void 0:e.getAttribute("data-mode");if(!t)t="default";var r=new FormData;r.append("action","import_droip_template");r.append(_tutorobject.nonce_key,_tutorobject._tutor_nonce);r.append("template_id",o);r.append("selected_mode",t);var a=yield fetch(_tutorobject.ajaxurl,{method:"POST",body:r});return a})();// import template content.
var s=()=>a(function*(){var e=new FormData;e.append("action","process_droip_template");e.append(_tutorobject.nonce_key,_tutorobject._tutor_nonce);try{var t=yield fetch(_tutorobject.ajaxurl,{method:"POST",body:e});var o=yield t.json();if(200===o.status_code){var a=o===null||o===void 0?void 0:o.data;if(a.status==="importing"){setTimeout(()=>{s()},10)}else if(a.status==="done"){if(r){var i=r.checked;if(i){yield c()}}v();tutor_toast(__("Success","tutor-pro"),__("Template imported successfully.","tutor-pro"),"success");return true}}}catch(e){u();tutor_toast(__("Error","tutor-pro"),__("Error while processing imported template!","tutor-pro"),"error");return false}})();var c=function(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:0;return a(function*(){var t=document.getElementById("tutor_template_course_data_url");var r=t===null||t===void 0?void 0:t.value;if(!r)return false;var o=new FormData;o.append("job_id",e);o.append("action","tutor_pro_import");o.append(_tutorobject.nonce_key,_tutorobject._tutor_nonce);if(!e){var a=r.toLowerCase().endsWith(".zip");var i=yield fetch(r);var n=yield i.blob();if(a){var l=r.split("/").pop()||"importer.zip";o.append("data",n,l)}else{o.append("data",n,"importer.json")}}var d=yield fetch(_tutorobject.ajaxurl,{method:"POST",body:o,credentials:"same-origin"});if(d.ok){var s=yield d.json();if(s.status_code==200){var u=s.data.job_id;var v=s.data.job_progress;if(v!=100){yield c(u)}if(v==100){return true}}}else{return false}})()};function u(){var e=t.querySelector("i");t.classList.remove("is-loading");t.classList.add("tutor-template-import-btn");t.classList.remove("tutor-template-view-template-btn");t.removeAttribute("disabled");e.classList.add("tutor-icon-import");e.classList.remove("tutor-icon-circle-mark")}function v(){var e=t.querySelector("i");t.classList.remove("is-loading");t.classList.remove("tutor-template-import-btn");t.removeAttribute("disabled");t.classList.add("tutor-template-view-template-btn");e.classList.remove("tutor-icon-import");e.classList.add("tutor-icon-circle-mark");t.innerHTML="".concat(e.outerHTML," View Template")}}});(function(){var e=document.querySelector("#tutor-template-preview-iframe");var t=document.getElementById("droip-color-presets");document.addEventListener("DOMContentLoaded",()=>{// Wait for the iframe to load before interacting with it
e.addEventListener("load",()=>{i();window.addEventListener("message",r);var e=document.querySelector(".tutor-template-preview-import-area .tutor-template-shimmer-effect-2");e.style.display="none";n();// Safe to send message now
l()})});var r=e=>{var{type:r}=e.data;switch(r){case"RETURN_DROIP_VARIABLE_DATA":{var a,i,n;if(((n=e.data.droipCSSVariable)===null||n===void 0?void 0:(i=n.data)===null||i===void 0?void 0:(a=i[0])===null||a===void 0?void 0:a.modes.length)>1){var l=document.querySelector(".tutor-droip-color-presets-heading");l.style.display="block";var c=document.querySelector("#droip-color-modes");c.style.display="block";var u=e.data.droipCSSVariable.data[0];var v=u.modes;// Hide #color-preset if 1 or fewer modes
t=document.getElementById("droip-color-presets");if(c&&t){if(v.length<=1){t.style.display="none"}else{t.style.display="flex";t.style.justifyContent="center";t.style.alignItems="center"}}var p=document.createElement("div");p.classList.add("all-colors-wrapper");p.style.display="flex";v.forEach((e,t)=>{var r=s(e.key,u);var o=document.createElement("div");o.classList.add("color-palette");o.setAttribute("data-mode",e.key);r.forEach((e,t)=>{if(t<3){var r='<div style="background-color:'.concat(e,';" data-index="').concat(t,'"></div>');o.innerHTML+=r}});p.append(o)});document.querySelector("#droip-color-modes").innerHTML=p.outerHTML;document.querySelectorAll(".color-palette").forEach(e=>{e.addEventListener("click",()=>{var t=e.getAttribute("data-mode");d(t);o(t)})})}break}case"RETURN_DROIP_ACTIVE_MODE":{var m;var f=(e===null||e===void 0?void 0:(m=e.data)===null||m===void 0?void 0:m.activeMode)||"default";o(f);break}}};var o=e=>{var t,r;var o=document.querySelectorAll(".color-palette");if(!o)return;o.forEach(e=>{e.classList.remove("active")});(r=document.querySelector('[data-mode="'+e+'"]'))===null||r===void 0?void 0:(t=r.classList)===null||t===void 0?void 0:t.add("active")};var a=t=>{e.contentWindow.postMessage(t,"*");// You can replace '*' with the exact origin
};var n=()=>{a({type:"GET_DROIP_VARIABLE_DATA"})};var l=()=>{a({type:"GET_DROIP_ACTIVE_MODE"})};var d=e=>{a({type:"APPLY_DROIP_VARIABLE_PALETTE",mode:e})};var s=(e,t)=>{if(!t||!t.variables){return[]}var r=t.variables.filter(e=>e.type==="color").map(t=>{var r,o;if((r=t.value)===null||r===void 0?void 0:r[e]){return t.value[e]}if((o=t.value)===null||o===void 0?void 0:o.default){return t.value.default}return"#000000"});return r}})()})();