(()=>{"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 n=t[o]={exports:{}};// Execute the module function
e[o](n,n.exports,r);// Return the exports of the module
return n.exports}// webpack/runtime/rspack_version
(()=>{r.rv=()=>"1.6.5"})();// webpack/runtime/rspack_unique_id
(()=>{r.ruid="bundler=rspack@1.6.5"})();// CONCATENATED MODULE: ./node_modules/.pnpm/@swc+helpers@0.5.17/node_modules/@swc/helpers/esm/_async_to_generator.js
function o(e,t,r,o,a,n,i){try{var l=e[n](i);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,n){var i=e.apply(t,r);function l(e){o(i,a,n,l,d,"next",e)}function d(e){o(i,a,n,l,d,"throw",e)}l(undefined)})}};// CONCATENATED MODULE: ./assets/src/js/template-import.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{__}=wp.i18n;var e=document.querySelector(".tutor-template-import-area");var t=document.querySelector(".tutor-template-preview-modal");var r=document.querySelector(".tutor-template-preview-modal-overlay");var o=document.querySelector(".tutor-template-preview-iframe-parent");var i=document.getElementById("tutor-template-preview-iframe");var l=document.querySelector(".tutor-template-preview-modal-back-link");var d=document.querySelectorAll(".tutor-template-preview-device-switcher li");var s=document.querySelector(".tutor-preview-template-name");var c=document.querySelector(".tutor-template-shimmer-effect");var u=document.querySelector(".tutor-template-import-btn");var p=document.getElementById("tutor_template_course_data_url");var v=document.getElementById("droip-color-presets");var m=document.querySelector(".tutor-droip-color-presets-heading");var y=document.getElementById("tutor-include-courses-checkbox");var f=document.querySelector(".tutor-template-consent-modal");var _=document.querySelector(".tutor-template-consent-modal-overlay");var b=document.querySelector(".tutor-template-consent-modal-close");var g=document.querySelector(".tutor-template-consent-cancel");var h=document.querySelector(".tutor-template-consent-import-btn");var L=document.getElementById("tutor-template-consent-checkbox");var w=document.querySelector(".tutor-template-consent-progress");var E=document.querySelector(".tutor-template-consent-progress-bar-inner");var k=document.querySelector(".tutor-template-consent-progress-status");var S=document.querySelector(".tutor-template-consent-progress-percent");var q=document.querySelector(".tutor-template-consent-modal-check");if(e){// Open live preview modal
e.addEventListener("click",e=>{if(e.target.closest(".tutor-template-preview-btn")){document.body.style.overflow="hidden";c.style.display="block";o.classList.remove("tutor-divider");t.style.display="flex";s.innerText=e.target.dataset.template_name;if(p){p.value=e.target.dataset.template_course_data_url}i.src=e.target.dataset.template_url;u.setAttribute("data-import_template_id",e.target.dataset.template_id)}});// Hide loading indicator when iframe is fully loaded
i.addEventListener("load",function(){c.style.display="none";o.classList.add("tutor-divider")});r===null||r===void 0?void 0:r.addEventListener("click",A);l===null||l===void 0?void 0:l.addEventListener("click",A);function A(){T();U();w.style.display="none";q.style.display="block";L.checked=false;h.disabled=true}// Device switcher
d.forEach(e=>{e.addEventListener("click",function(){I(d);e.classList.add("active");var t=this.getAttribute("data-width");i.style.width=t+"px";n()})});// Reset preview modal
function T(){t.style.display="none";i.src="";I(d);d[0].classList.add("active");c.style.display="none";document.body.style.overflow="visible";i.style.width="1400px";i.style.transformOrigin="left top";v.style.display="none";m.style.display="none"}// Remove active class from device list
function I(e){e.forEach(e=>{e.classList.remove("active")})}}var j;var x=false;var M=false;if(e){var D;document.addEventListener("click",e=>{if(e.target.closest(".tutor-template-import-btn")){P()}});L===null||L===void 0?void 0:L.addEventListener("change",function(){if(!h){return}if(L.checked){h.removeAttribute("disabled")}else{h.setAttribute("disabled","disabled")}});b===null||b===void 0?void 0:b.addEventListener("click",H);g===null||g===void 0?void 0:g.addEventListener("click",H);_===null||_===void 0?void 0:_.addEventListener("click",H);(D=document.querySelector(".tutor-template-preview-modal-back-link"))===null||D===void 0?void 0:D.addEventListener("click",H);document.addEventListener("click",e=>{if(e.target.closest(".tutor-template-consent-import-btn")){if(M){console.log("isImportInProgress",M);return}M=true;N();z(5,__("Preparing import...","tutor-pro"));R()}});document.addEventListener("click",e=>{if(e.target.closest(".tutor-template-view-template-btn")){window.open(_tutorobject.site_url,"_blank")}});var O=["tutorbase","kirki","kirki-pro"];function P(){if(!f){return}f.style.display="flex"}function H(){if(M){// Prevent closing the consent modal while import is running.
return}if(!f){return}f.style.display="none"}function R(){h.classList.add("is-loading");h.setAttribute("disabled","disabled");q.style.display="none";b.style.display="none";g.style.display="none";var e=h.querySelector("i");h.innerHTML="".concat(e.outerHTML," ").concat(__("Importing","tutor-pro"));z(10,__("Installing required plugins...","tutor-pro"));B()}// install required plugin.
function B(){return a(function*(){x=false;for(var e=0;e<O.length;e++){try{var t=new FormData;t.append("action","tutor_template_required_plugin_install");t.append(_tutorobject.nonce_key,_tutorobject._tutor_nonce);t.append("plugin_name",O[e]);t.append("consent",L.checked);var r=yield fetch(_tutorobject.ajaxurl,{method:"POST",body:t});var o=yield r.json();if(200===o.status_code){x=true;var a=e+1;var n=Math.min(40+a*10,60);// keep plugins phase between 40%-60%
z(n,__("Installing required plugins...","tutor-pro"))}else{throw new Error((o===null||o===void 0?void 0:o.message)||__("Template import failed!","tutor-pro"))}}catch(e){U();G(false);tutor_toast(__("Error","tutor-pro"),(e===null||e===void 0?void 0:e.message)||__("Something went wrong!","tutor-pro"),"error");return}}// if plugin installation done start importing template content.
if(x){j=u.getAttribute("data-import_template_id");try{z(65,__("Importing template content...","tutor-pro"));var i=yield C();var l=yield i.json();if(i.ok&&200===l.status_code){V()}else{throw new Error((l===null||l===void 0?void 0:l.message)||__("Template import failed!","tutor-pro"))}}catch(e){U();G(false);tutor_toast(__("Error","tutor-pro"),(e===null||e===void 0?void 0:e.message)||__("Something went wrong!","tutor-pro"),"error");return}}})()}// import template zip file.
var C=()=>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_tutor_template");r.append(_tutorobject.nonce_key,_tutorobject._tutor_nonce);r.append("template_id",j);r.append("selected_mode",t);var o=yield fetch(_tutorobject.ajaxurl,{method:"POST",body:r});return o})();// import template content.
var V=()=>a(function*(){var e=new FormData;e.append("action","process_tutor_template");e.append(_tutorobject.nonce_key,_tutorobject._tutor_nonce);try{var t=yield fetch(_tutorobject.ajaxurl,{method:"POST",body:e});var r=yield t.json();if(200===r.status_code){var o=r===null||r===void 0?void 0:r.data;if(o.status==="importing"){setTimeout(()=>{V()},10)}else if(o.status==="done"){if(y){var a=y.checked;if(a){z(80,__("Importing demo courses...","tutor-pro"));yield F()}}z(100,__("Finalizing import...","tutor-pro"));Y();G(true);tutor_toast(__("Success","tutor-pro"),__("Template imported successfully.","tutor-pro"),"success");return true}}else{throw new Error((r===null||r===void 0?void 0:r.message)||__("Template import failed!","tutor-pro"))}}catch(e){U();G(false);tutor_toast(__("Error","tutor-pro"),(e===null||e===void 0?void 0:e.message)||__("Something went wrong!","tutor-pro"),"error");return false}})();var F=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 n=yield fetch(r);var i=yield n.blob();if(a){var l=r.split("/").pop()||"importer.zip";o.append("data",i,l)}else{o.append("data",i,"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 c=s.data.job_id;var u=s.data.job_progress;if(u!=100){z(Math.min(80+u*.2,99),__("Importing demo courses...","tutor-pro"));yield F(c)}if(u==100){z(100,__("Demo courses imported.","tutor-pro"));return true}}}else{return false}})()};function z(e,t){if(!w||!E){return}var r=Math.max(0,Math.min(100,Math.round(e)));w.style.display="block";E.style.width="".concat(r,"%");if(S){S.textContent="".concat(r,"%")}if(k&&t){k.textContent=t}}function N(){if(b){b.setAttribute("disabled","disabled")}if(g){g.setAttribute("disabled","disabled")}if(_){_.classList.add("is-disabled")}}function W(){if(b){b.removeAttribute("disabled")}if(g){g.removeAttribute("disabled")}if(_){_.classList.remove("is-disabled")}}function G(e){M=false;W();if(k){k.innerHTML=e?"Import completed.":'<span style="color: var(--tutor-color-danger);">Import failed!. You can try again.</span>'}}}function U(){M=false;var e=document.querySelector(".tutor-template-consent-modal-actions button:last-child");var t=e.querySelector("i");e.classList.remove("is-loading");e.classList.add("tutor-template-consent-import-btn");e.classList.remove("tutor-template-view-template-btn");e.removeAttribute("disabled");t.classList.add("tutor-icon-import");t.classList.remove("tutor-icon-circle-mark");e.innerHTML="".concat(t.outerHTML," Import");// consent progress bar
E.style.width="0%";S.textContent="0%";b.style.display="block";g.style.display="block";g.innerHTML="close"}function Y(){M=false;var e=document.querySelector(".tutor-template-consent-modal-actions button:last-child");var t=e.querySelector("i");e.classList.remove("is-loading");e.classList.remove("tutor-template-consent-import-btn");e.removeAttribute("disabled");e.classList.add("tutor-template-view-template-btn");t.classList.remove("tutor-icon-import");t.classList.add("tutor-icon-circle-mark");e.innerHTML="".concat(t.outerHTML," View Template");b.style.display="block";g.style.display="block";g.innerHTML="close"}});function n(){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 n=a/Number(o);if(n>0){t.style.transform="scale(".concat(n,")");t.style.transformOrigin="left top";t.style.height="".concat(100/n,"%");t.style.margin="0px auto"}}else{t.style.transformOrigin="center top"}}window.addEventListener("resize",n);(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",()=>{n();window.addEventListener("message",r);var e=document.querySelector(".tutor-template-preview-import-area .tutor-template-shimmer-effect-2");e.style.display="none";i();// Safe to send message now
l()})});var r=e=>{var{type:r}=e.data;switch(r){case"RETURN_DROIP_VARIABLE_DATA":{var a,n,i;if(((i=e.data.droipCSSVariable)===null||i===void 0?void 0:(n=i.data)===null||n===void 0?void 0:(a=n[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 p=u.modes;// Hide #color-preset if 1 or fewer modes
t=document.getElementById("droip-color-presets");if(c&&t){if(p.length<=1){t.style.display="none"}else{t.style.display="flex";t.style.justifyContent="center";t.style.alignItems="center"}}var v=document.createElement("div");v.classList.add("all-colors-wrapper");v.style.display="flex";p.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}});v.append(o)});document.querySelector("#droip-color-modes").innerHTML=v.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 y=(e===null||e===void 0?void 0:(m=e.data)===null||m===void 0?void 0:m.activeMode)||"default";o(y);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 i=()=>{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}})()})();