import{r as t,h as e,a as s}from"./p-1469ddb8.js";const o="";const n=o;const i=class{constructor(e){t(this,e);this.baseUrl="";this.xmlPath=undefined;this.initialIndex=0;this.canplay=false;this.height="75vh";this.language=undefined;this.xmlData=undefined;this.zipUrl=undefined;this.codeFolderPath=undefined;this.commonAudioPath=undefined;this.scriptsInjected=false;this.localXmlData=undefined;this.xmlBaseUrl=undefined}onBaseUrlChange(){this.injectLidoScripts()}onXmlPathChange(){this.fetchXmlData()}componentWillLoad(){this.injectLidoScripts();this.fetchXmlData()}async injectLidoScripts(){console.log("injectLidoScripts() called. baseUrl=",this.baseUrl);if(!this.baseUrl){console.warn("lido-standalone: No baseUrl provided. Using npm fallback...");this.fallbackNpmImport();return}if(this.scriptsInjected){return}const t=this.baseUrl.replace(/\/+$/,"");const e=`${t}/code/lido-player.esm.js`;const s=this.doesFileExistSync(e);if(s){console.log("Using code from zip....");const s=document.createElement("script");s.type="module";s.src=e;document.head.appendChild(s);const o=document.createElement("script");o.setAttribute("nomodule","");o.src=`${t}/code/lido-player.js`;document.head.appendChild(o);this.scriptsInjected=true;console.debug("Lido scripts injected from:",this.baseUrl);return}if(this.codeFolderPath){const t=this.baseUrl.replace(/\/+$/,"");try{const e=`${t}/config.json`;try{let t={};let s=null;try{const o=await fetch(e);if(!o.ok)throw new Error("Lesson config.json missing");const n=await o.text();if(n.trim().length>0){t=JSON.parse(n)}else{console.warn("Lesson config.json is EMPTY → falling back to latest version")}s=t.code_version;console.log(`%c USING THE VERSION FOLDER--\x3e ${s} `,"color: #3bffe8ff; background:#d32f2f; font-size: 15px; font-weight: bold; padding: 6px 10px; border-radius: 4px;")}catch(t){console.warn("Lesson config.json invalid or unreadable → fallback to latest version");s=null}if(!s||typeof s!=="string"||s.trim()===""){console.warn("Lesson has NO valid codeVersion → using latest version in code-folder-path");s=null}const o=`${this.codeFolderPath.replace(/\/+$/,"")}/config.json`;const n=await fetch(o);if(!n.ok)throw new Error("Code-folder config.json missing");const i=await n.json();const c=i.versions||[];if(!c.length){throw new Error("No versions listed in code-folder config.json")}let l=null;if(s){l=c.find((t=>t.includes(s)))}if(!l){l=c[c.length-1];console.log(`%c USING THE LATEST VERSION FOLDER-> ${l} `,"color: #3bffe8ff; background:#d32f2f; font-size: 15px; font-weight: bold; padding: 6px 10px; border-radius: 4px;")}const r=`${this.codeFolderPath}/${l}`;const a=`${r}/lido-player.esm.js`;const d=`${r}/lido-player.js`;const h=await fetch(a,{method:"HEAD"});if(!h.ok)throw new Error(`Versioned script missing: ${a}`);const f=document.createElement("script");f.type="module";f.src=a;document.head.appendChild(f);const u=document.createElement("script");u.setAttribute("nomodule","");u.src=d;document.head.appendChild(u);this.scriptsInjected=true;console.debug("Loaded Lido version from:",r)}catch(t){console.warn("Failed to load versioned scripts, falling back to npm:",t);this.fallbackNpmImport()}}catch(t){console.warn("Failed loading scripts → fallback to npm:",t);this.fallbackNpmImport()}return}this.fallbackNpmImport()}doesFileExistSync(t){try{const e=new XMLHttpRequest;e.open("HEAD",t,false);e.send();const s=e.status>=200&&e.status<300;if(!s)return false;const o=e.getResponseHeader("Content-Type")||"";const n=o.includes("text/html");return!n}catch(e){console.warn("File existence check failed for:",t,e);return false}}fallbackNpmImport(){import("./p-39ee42de.js").then((function(t){return t.i})).then((({defineCustomElements:t})=>{t(window);this.scriptsInjected=true;console.debug("Lido scripts loaded via npm fallback (defineCustomElements).")})).catch((t=>{console.error('Failed to load from npm package "lido-player":',t)}))}fetchXmlData(){if(this.xmlData){this.localXmlData=this.xmlData;return}if(this.baseUrl){const t=this.baseUrl.replace(/\/+$/,"");this.xmlPath=`${t}/index.xml`;this.xmlBaseUrl=this.baseUrl}else{return}try{const t=new XMLHttpRequest;t.open("GET",this.xmlPath,false);t.send(null);if(t.status>=200&&t.status<300){this.localXmlData=t.responseText}else{console.warn(`Failed to fetch XML from ${this.xmlPath}:`,t.status)}}catch(t){console.warn(`Error fetching XML from ${this.xmlPath}:`,t)}}render(){const t=this.language||undefined;return e("lido-home",{key:"8ab52aff3a070fae1e0253f5917d29ed4e03d722","common-audio-path":this.commonAudioPath,"initial-index":this.initialIndex,canplay:this.canplay,height:this.height,lang:t,"xml-data":this.localXmlData,"base-url":this.xmlBaseUrl,"code-folder-path":this.codeFolderPath,"zip-url":this.zipUrl})}get hostElement(){return s(this)}static get watchers(){return{baseUrl:["onBaseUrlChange"],xmlPath:["onXmlPathChange"]}}};i.style=n;export{i as lido_standalone};
//# sourceMappingURL=p-9770de04.entry.js.map