@salla.sa/twilight-components
Version:
Salla Web Component
5 lines • 2.29 kB
JavaScript
/*!
* Crafted with ❤ by Salla
*/
import{r as t,h as a,H as s,g as r}from"./p-bdd00808.js";const e="";const i=class{constructor(a){t(this,a);this.entity="product";this.entityId=undefined;this.specs=[];this.download=salla.lang.get("pages.thank_you.download");if(this.entityId){try{this.entityId=Array.isArray(this.entityId)?this.entityId:JSON.parse(this.entityId);return}catch(t){salla.log("Bad json passed via entityId prop")}}}getValue(t){if(t.type==="file"){return`<a href="${t.value}" class="text-primary" target="_blank"><span class="sicon-download"></span> ${this.download}</a>`}if(t.type==="url"){return`<a href="${t.value}" class="text-blue-700 underline" target="_blank">${t.value}</a>`}if(t.type==="date"){const a=new Date(t.value);const s=String(a.getDate()).padStart(2,"0");const r=String(a.getMonth()+1).padStart(2,"0");const e=a.getFullYear();const i=`${s}/${r}/${e}`;return i}return t.value}componentWillLoad(){return salla.onReady().then((()=>{var t;if(!((t=salla.config.get("store.features"))===null||t===void 0?void 0:t.includes("custom-fields"))){throw new Error("feature custom-fields is not activated")}})).then((()=>{if(!this.entityId&&salla.url.is_page("product.single")){this.entityId=salla.config.get("page.id")}if(!this.entityId){throw new Error("can't render salla-metadata without enity-id prop!")}salla.lang.onLoaded((()=>this.download=salla.lang.get("pages.thank_you.download")));const t=Array.isArray(this.entityId)?this.entityId:[this.entityId];const a=t.map((t=>`entities[]=${t}`)).join("&");const s=`https://api.salla.dev/store/v1/metadata/values?type=${this.entity}&${a}`;return salla.api.request(s).then((t=>{var a;return(a=t.data[0])===null||a===void 0?void 0:a.sections}))})).then((t=>this.specs=t)).catch((t=>salla.logger.error("Error loading more specs:",t)))}render(){if(!this.specs.length){return}return a(s,{class:"s-metadata-wrapper"},this.specs.map((t=>a("div",{class:"s-metadata-box"},a("div",{class:"s-metadata-box-header"},a("i",{class:"sicon-list"}),t.name),t.fields.map((t=>a("div",{class:"s-metadata-row"},a("p",{class:"s-metadata-row-name"},t.name),a("p",{class:"s-metadata-row-value",innerHTML:this.getValue(t)}))))))))}get host(){return r(this)}};i.style=e;export{i as salla_metadata};
//# sourceMappingURL=p-66e9be2f.entry.js.map