/*! phoscon-app 2024-10-07 */

export function getPageContent(event,pageParams,initPages){return new Promise((resolve,reject)=>{if(!event.type||!event.data)return reject("parameter is missing - getPageContent()");let url=initPages(pageParams).find(p=>p.id==event.data).url;if(!url)throw new Error("url is missing");fetch(url).then(res=>res.text()).then(html=>{let markup=html,el=(new DOMParser).parseFromString(markup,"text/html"),body=el.querySelector(".modal-body-content"),title=el.querySelector(".modal-title-content"),footer=el.querySelector(".modal-footer-content"),trans=el.querySelector(".translate-ids");resolve({title:title,body:body,footer:footer,trans:trans})}).catch(err=>reject(err))})};export function translatePage(view){let page=view.el;page.querySelectorAll("[data-translateid]").forEach(el=>{var id=el.getAttribute("data-translateid");if(id){var tr=translate(id);tr&&(el.innerHTML=tr)}}),page.querySelectorAll(".product-name").forEach(el=>{let map,interactiveId=el.getAttribute("data-interactiveId"),modelId=el.getAttribute("data-modelId");if(!interactiveId&&!modelId)return;interactiveId&&Object.keys(deviceInfoMap).forEach(key=>{let m=deviceInfoMap[key].find(x=>x.interactive&&x.interactive==="#"+interactiveId);m&&(map=m)}),modelId&&Object.keys(deviceInfoMap).forEach(key=>{let m=deviceInfoMap[key].find(x=>x.modelid&&x.modelid===modelId);m&&(map=m)});let lang=app.lang||en;if(!lang||!map)return;let productName=map.productname[lang];productName&&(el.innerText=productName)}),app.session.product&&page.querySelectorAll(".fade-in .set-product-name").forEach(el=>el.innerText=translate(app.session.product))};