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