function initConfigurator(e){var t=getPrimaryComponentCtx(),r=getActiveSurfaceCtx(t),a=r.data("surface-code"),o=getActiveColorCtx(r),n=o.data("asset-color-code"),i=o.data("alternative-color");showColorLegend(t),updateComponentsSurfaces(a,n,i),ET1(!0,o),ET2(!0,o),removeOptionHandler(),reorderComponentsOptions(),updatePrintAreas(),updateTextColorPalette(),updateQRCodes(),updateWritingSystemOptions(),refreshPreview(),is_defined(e)&&jQuery.isFunction(e)&&e()}function refreshPreview(){var e=jQuery(".pen-preview img.pen-picture");if(jQuery(e).each(function(e,t){var r=jQuery(t),a=getActiveColorCtx(getActiveSurfaceCtx(getComponentCtxByDataAttribute([{dataAttribute:"component-id",attributeValue:r.data("component-id"),dataRelation:"="}])));newColorCode=getAssetColorCode(a);var o=r.attr("src").substring(0,r.attr("src").lastIndexOf("/")+1),n=r.attr("src").substr(r.attr("src").lastIndexOf("/")+1).split(".")[0].split("_");o+=n[0]+"_"+newColorCode+"_"+n[2]+".png",r.attr("src",o)}),(e=jQuery(".pen-preview img.refill-picture")).length>0){var t=getRefillOptionsCtx(),r=getSelectedRefillCtx(t).data("refill-id"),a=getActiveRefillColorCtx(getRefillColorOptionsCtx(getRefillExtraOptionsCtx(t,r),r)).data("color-code");e.each(function(e,t){var o=jQuery(t);if(o.data("refill-id")!=r)o.hide().addClass("hidden");else{var n=o.attr("src").substring(0,o.attr("src").lastIndexOf("/")+1),i=o.attr("src").substr(o.attr("src").lastIndexOf("/")+1).split(".")[0].split("_");n+=i[0]+"_"+a+"_"+i[2]+".png",o.attr("src",n).show().removeClass("hidden")}})}}function checkRestoreConfiguration(){if(null!=urlParam("surface")&&null!=urlParam("color")){var e=urlParam("surface"),t=urlParam("color"),r={surface:e,color:/^\d+$/.test(t)?e+t:t,option:urlParam("option")},a={altColor:urlParam("altcolor"),subset:urlParam("subset"),msg:urlParam("msg")};displayLoading(!0,"load"),restoreProductConfiguration(r,a)}if(null!=urlParam("configuration")){var o=urlParam("configuration"),n=null!=urlParam("restricted")?urlParam("restricted"):"";displayLoading(!0,"load"),restoreHomeConfiguration(o,n)}if(is_defined(Cookies.get("nodeId"))){displayLoading(!0,"load");var i=Cookies.get("nodeId");jQuery.ajax({url:minerva_drupal_vars.host+"/"+Cookies.get("wp-wpml_current_language")+minerva_drupal_vars.endpoints.load.replace("{nodeId}",i),type:"GET",headers:{"Content-Type":"application/json",Accept:"application/json"},success:function(e){var t=e.hasOwnProperty("field_xmlconfiguration")?e.field_xmlconfiguration[0].value:"",r=e.hasOwnProperty("field_xmlextendedconfiguration")?e.field_xmlextendedconfiguration[0].value:"",a=e.hasOwnProperty("field_jsonconfiguration")?e.field_jsonconfiguration[0].value:"",o=e.hasOwnProperty("field_jsonextendedconfiguration")?e.field_jsonextendedconfiguration[0].value:"";a.indexOf('{""')>-1&&(a=(a=a.replace(/""""/g,"null")).replace(/""/g,'"')),o.indexOf('{""')>-1&&(o=(o=o.replace(/""""/g,"null")).replace(/""/g,'"')),""!=a&&""!=o?restoreJSONConfiguration(a,o):""!=t&&restoreXMLConfiguration(t=$($.parseXML(t)),r=$($.parseXML(r)),productId),Cookies.remove("productId"),Cookies.remove("nodeId")},error:function(e){console.log(e),displayLoading(!1,null),showErrorMessage(e,jQuery("#response-modal")),Cookies.remove("productId"),Cookies.remove("nodeId")}})}displayLoading(!1,null)}function restoreXMLConfiguration(e,t,r){var a,o,n,i,u,l,s,c,d=jQuery.parseXML(e),p=jQuery(d),f=new Array,g=Cookies.get("wp-wpml_current_language"),C=[];jQuery.each(["propertyPicker2_2","propertyPicker2_1","propertyPicker3","optionPicker","optionPicker2"],function(e,t){a=parseInt(p.find("configuration "+t+" materialId").text()),o=parseInt(p.find("configuration "+t+" colorId").text()),""!=(n=mapping[r.toString()][t].componentId[g])&&(i=mapping[r.toString()][t].surfaces,jQuery.each(i,function(e,t){i[e].materialId==a&&(u=i[e].surfaceId[g],i[e].paletteId[g],l=i[e].colors,s=l[o],c={componentId:n,surfaceId:u,colorCode:s},f.push(c))}))}),jQuery.each(f,function(e,t){var r=getComponentCtxByDataAttribute([{dataAttribute:"component-id",attributeValue:t.componentId,dataRelation:"="}]),a=getSurfaceCtxByDataAttribute([{dataAttribute:"surface-id",attributeValue:t.surfaceId,dataRelation:"="}],!1,r),o=getColorCtxByDataAttribute([{dataAttribute:"asset-color-code",attributeValue:t.colorCode,dataRelation:"="}],a);o.length>0?setActiveColor(o):C.push({type:"component",component:r.data("component-slug")})}),updateConfiguratorAfterRestoreConfiguration(),C.length>0&&(displayLoading(!1,null),showBrokenConfigurationMessage())}function restoreJSONConfiguration(e,t){var r=JSON.parse(e),a=JSON.parse(t),o=[],n=r.components;if(jQuery.each(n,function(e,t){var r=t.componentId,a=t.hasOwnProperty("surfaceId")?t.surfaceId:t.finishingId,n=t.colorCode,i=getComponentCtxByDataAttribute([{dataAttribute:"component-id",attributeValue:r,dataRelation:"="}]),u=getSurfaceCtxByDataAttribute([{dataAttribute:"surface-id",attributeValue:a,dataRelation:"="}],!1,i);if(n.length>1)var l=getColorCtxByDataAttribute([{dataAttribute:"asset-color-code",attributeValue:n,dataRelation:"="}],u);else l=getColorCtxByDataAttribute([{dataAttribute:"asset-color-code",attributeValue:n+"70",dataRelation:"="}],u);0==i.length?o.push({type:"component",component:t.componentLabel}):l.length>0?setActiveColor(l):o.push({type:"componentColor",component:t.componentLabel,color:n})}),r.hasOwnProperty("writingSystem")){var i=r.writingSystem.refillId,u=r.writingSystem.optionId,l=r.writingSystem.ballDiameter,s=r.writingSystem.refillColorCode,c=getRefillOptionsCtx(),d=getRefillCtx(i,c),p=getInkColorOptionsCtx(c,i),f=getInkColorCtxByDataAttribute(i,[{dataAttribute:"option",attributeValue:u,dataRelation:"="}],c),g=(getRefillDiameterOptionCtx(u,"=",getRefillDiameterOptionsCtx(c,i)),getRefillExtraOptionsCtx(c,i));if(d.length>0){if(d.prop("checked",!0),f.length>0){jQuery("li",p).removeClass("active"),f.addClass("active");var C=is_defined(l)?getRefillDiameterCtx(l,C):jQuery('.active input[type="radio"]',C);C.length>0?C.prop("checked",!0):o.push({type:"refillDiameter",refillType:r.writingSystem.refillLabel,diameter:r.writingSystem.ballDiameter})}else o.push({type:"refillInkColor",refillType:r.writingSystem.refillLabel,inkColor:r.writingSystem.colorName});if(g.length>0){var y=getRefillColorOptionsCtx(g,i),m=getRefillColorCtxByDataAttribute(i,[{dataAttribute:"color-code",attributeValue:s,dataRelation:"="}],y);m.length>0?(jQuery("li",y).removeClass("active"),m.addClass("active")):o.push({type:"refillColor",refillType:r.writingSystem.refillLabel,color:r.writingSystem.refillColorCode})}}else o.push({type:"refillType",refillType:r.writingSystem.refillLabel})}var b=a.imprint;jQuery.each(b,function(e,t){var r=t.areaId,a=t.dataType,n=t.dataContent,i=is_defined(t.topOffset)?t.topOffset:"";if(jQuery('.print-area[data-area-id="'+r+'"]').length>0){if("text"==a){var u=n.text,l=n.fontFamily.replace(/"/g,""),s=n.fontSize,c=n.fontWeight,d=n.fontStyle,p=n.fontColor,f=n.textAlign,g=n.textRotation;appendText(r,u,l,s,c,d,p,f,g)}else{var C=n.base64;appendImage(r,C,null),jQuery('.imprint-panel .tab-pane[data-area-id="'+r+'"] .btn-remove-container').show()}""!=i&&(jQuery('.print-area[data-area-id="'+r+'"]').each(function(e,t){jQuery(t).css("top",i)}),jQuery.each(jQuery('.move-area input[name="move-area"]'),function(e,t){var r=jQuery(t);jQuery.number(r.attr("data-top-offset"),3,".","")==jQuery.number(i.replace("px",""),3,".","")&&r.parent().trigger("click")}))}else o.push({type:"printArea",printArea:t.areaLabel})}),r.qrcode&&(QRCodeEnabled=!0),updateConfiguratorAfterRestoreConfiguration(),o.length>0&&(displayLoading(!1,null),showBrokenConfigurationMessage())}function restoreProductConfiguration(e,t){var r=e.surface,a=e.color,o=e.option,n=t.altColor,i=t.subset,u=t.msg,l=getPrimaryComponentCtx(),s=getSurfaceCtxByDataAttribute([{dataAttribute:"surface-code",attributeValue:r.toUpperCase(),dataRelation:"="}],!1,l),c=getColorCtxByDataAttribute([{dataAttribute:"asset-color-code",attributeValue:a.toUpperCase(),dataRelation:"="}],s);if(s.length>0&&c.length>0){if(setActiveColor(c),updateComponentsSurfaces(s.data("surface-code"),c.data("asset-color-code"),c.data("alternative-color")),is_defined(n)&&null!=n){var d=n.split(",");jQuery.each(d,function(e,t){var r=t.split("|"),a=r[0],o=r[1].toUpperCase(),n=getComponentCtxByDataAttribute([{dataAttribute:"component-slug",attributeValue:a,dataRelation:"="}]),i=getColorCtxByDataAttribute([{dataAttribute:"asset-color-code",attributeValue:o.toUpperCase(),dataRelation:"="}],n);setActiveColor(i)})}if(is_defined(o)&&null!=o)switch(o){case"metal":selectOption("metal-option",!1,function(){updateConfiguratorAfterRestoreConfiguration()})}if(is_defined(i)&&null!=i){var p=getComponentSurfacesCtx(l=getPrimaryComponentCtx(),!0),f=getActiveSurfaceCtx(l).attr("data-visible","true");if(updateConfiguratorAfterRestoreConfiguration(),jQuery.each(p,function(e,t){checkSurfaceCompatibility([f.data("surface-code")],l,jQuery(t))}),f.parent().addClass("last"),is_defined(u)&&null!=u){var g=getComponentCtxByDataAttribute([{dataAttribute:"component-type",attributeValue:"optional",dataRelation:"!="}]);jQuery(".standard-message-container .standard-message",g).html(minerva_configurator_vars.subset_message),g.addClass("with-message")}}else updateConfiguratorAfterRestoreConfiguration();displayLoading(!1,null)}else displayLoading(!1,null),showBrokenConfigurationMessage()}function restoreHomeConfiguration(e,t){var r=e.split(","),a=""!=t?t.split(","):[],o={},n=[];jQuery.each(r,function(e,t){var r=t.split("|"),a=r[0],i=r[1].toUpperCase(),u=getComponentCtxByDataAttribute([{dataAttribute:"component-slug",attributeValue:a,dataRelation:"="}]),l=getColorCtxByDataAttribute([{dataAttribute:"asset-color-code",attributeValue:i,dataRelation:"="}],u),s=getSurfaceCtx(l),c={componentId:u.data("component-id"),surfaceId:s.data("surface-id"),surfaceCode:s.data("surface-code"),colorCode:l.data("asset-color-code"),alternativeColor:l.data("alternative-color")};0==e?(o=c,setActiveColor(l)):n.push(c)}),updateComponentsSurfaces(o.surfaceCode,o.colorCode,o.alternativeColor),jQuery.each(n,function(e,t){var r=getComponentCtxByDataAttribute([{dataAttribute:"component-id",attributeValue:t.componentId,dataRelation:"="}]),a=getSurfaceCtxByDataAttribute([{dataAttribute:"surface-id",attributeValue:t.surfaceId,dataRelation:"="}],!1,r),o=getColorCtxByDataAttribute([{dataAttribute:"asset-color-code",attributeValue:t.colorCode,dataRelation:"="}],a);setActiveColor(o)}),updateConfiguratorAfterRestoreConfiguration(),a.length>0&&(jQuery.each(a,function(e,t){var r=getComponentCtxByDataAttribute([{dataAttribute:"component-slug",attributeValue:t,dataRelation:"="}]),a=getActiveSurfaceCtx(r),o=getComponentSurfacesCtx(r,!0);jQuery.each(o,function(e,t){checkSurfaceCompatibility([a.data("surface-code")],r,jQuery(t))})}),reorderComponentsOptions()),displayLoading(!1,null)}function getSurfaceCodeByComponentId(e){return getActiveSurfaceCtx(getComponentCtxByDataAttribute([{dataAttribute:"component-id",attributeValue:e,dataRelation:"="}])).data("surface-code")}function getProductCode(){var e="",t="";if(productCodeRules){var r=productCodeRules.standard,a=productCodeRules.optional,o=productCodeRules.suffix;if(e+=productCodeRules.writing_system,r.length>0&&jQuery.each(r,function(t,r){e+=applyRule("standard",r)}),a.length>0){var n="";jQuery.each(a,function(e,t){n+=applyRule("optional",t)}),""!=n&&(e+="-"+n)}o.length>0&&jQuery.each(o,function(e,r){var a=!0,o=r.conditions,n=r.suffix_text;jQuery.each(o,function(e,t){var r=getActiveSurfaceCtx(getComponentCtxByDataAttribute([{dataAttribute:"component-id",attributeValue:t.component_id,dataRelation:"="}])).data("surface-id"),o=jQuery.map(t.surface_id,function(e){return parseInt(e)});a=jQuery.inArray(r,o)>-1}),a&&(t+=""!=n?" "+n:n)})}return e+t}function applyRule(e,t){var r="";if("component"in t){var a=getSurfaceCodeByComponentId(t.component);("standard"==e||"optional"==e&&-1==a.indexOf(dummy_surface_code))&&(r=a)}return"fixed"in t&&(r=t.fixed),"mixed"in t&&jQuery.each(t.mixed,function(e,t){var a=!0,o=t.conditions;if(jQuery.each(o,function(e,t){var r=getActiveSurfaceCtx(getComponentCtxByDataAttribute([{dataAttribute:"component-id",attributeValue:t.component_id,dataRelation:"="}])).data("surface-id"),o=jQuery.map(t.surface_id,function(e){return parseInt(e)});a=jQuery.inArray(r,o)>-1}),a)if(""!=t.surface_code)r=t.surface_code;else if(""!=t.component_id){var n=getSurfaceCodeByComponentId(t.component_id);if(-1==n.indexOf(dummy_surface_code))if(t.use_color_code){var i=getActiveColorCtx(getComponentCtxByDataAttribute([{dataAttribute:"component-id",attributeValue:t.component_id,dataRelation:"="}])).data("color-code");r=i.replace(/\d+/g,"")}else r=n}}),r}function getComponentsCtx(){return jQuery('.component-options[data-component-type!="null"]')}function getComponentCtx(e){return jQuery(e).closest(".component-options")}function getPrimaryComponentCtx(){return getComponentCtxByDataAttribute([{dataAttribute:"component-type",attributeValue:"primary",dataRelation:"="}])}function getComponentCtxByDataAttribute(e,t){var r=".component-options";return jQuery.each(e,function(e,t){r+="[data-"+t.dataAttribute+t.dataRelation+'"'+t.attributeValue+'"]'}),is_defined(t)&&!t||(r+='[data-component-type!="null"]'),jQuery(r)}function getActiveComponentCtx(){return jQuery(".component-options.active")}function getSurfaceCtx(e){return jQuery(e).closest(".surface-container")}function getActiveSurfaceCtx(e){return jQuery(".surface-container.active",e)}function getSurfaceCtxByDataAttribute(e,t,r){var a=".surface-container";return is_defined(t)&&t&&(a+=".active"),jQuery.each(e,function(e,t){a+="[data-"+t.dataAttribute+t.dataRelation+'"'+t.attributeValue+'"]'}),jQuery(a,r)}function getComponentSurfacesCtx(e,t){return is_defined(t)&&t?jQuery(".surface-container:not(.active)",e):jQuery(".surface-container",e)}function getColorCtx(e,t){return is_defined(t)?t?jQuery(".colors-list .color-item.active",e):jQuery(".colors-list .color-item:not(.active)",e):jQuery(".colors-list .color-item",e)}function getActiveColorCtx(e){return getColorCtx(e,!0)}function getColorCtxByDataAttribute(e,t){var r=".colors-list .color-item";return jQuery.each(e,function(e,t){r+="[data-"+t.dataAttribute+t.dataRelation+'"'+t.attributeValue+'"]'}),jQuery(r,t)}function getColorPaletteCtx(e){return jQuery(e).closest(".colors-list")}function getPrintAreaTabCtxByDataAttribute(e,t){var r=".nav-link";return is_defined(t)||(t="#v-pills-printareas-tab"),jQuery.each(e,function(e,t){r+="[data-"+t.dataAttribute+t.dataRelation+'"'+t.attributeValue+'"]'}),jQuery(r,t)}function getPrintAreaTabDropdownCtxByDataAttribute(e,t){var r="option";return is_defined(t)||(t=".nav-pills-printareas-tab-dropdown"),jQuery.each(e,function(e,t){r+="[data-"+t.dataAttribute+t.dataRelation+'"'+t.attributeValue+'"]'}),jQuery(r,t)}function getActivePrintAreaTabCtx(e){return is_defined(e)||(e="#v-pills-printareas-tab"),jQuery(".nav-link.active",e)}function getPrintAreaFirstAvailableOptionCtx(e){return is_defined(e)||(e=".nav-pills-printareas-tab-dropdown"),jQuery('option[data-visible="true"]',e).first()}function getRemoveOptionSwitch(e){return jQuery(".remove-option-switch",e)}function getRefillOptionsCtx(){return getComponentCtxByDataAttribute([{dataAttribute:"component-id",attributeValue:"0",dataRelation:"="}],!1)}function getRefillCtx(e,t){return is_defined(t)||(t=getRefillOptionsCtx()),e>0?jQuery('.refill-radio input[name="refill"][data-refill-id="'+e+'"]',t):jQuery('.refill-radio input[name="refill"]',t)}function getRefillContainerCtx(e,t){if(!is_defined(e)&&!is_defined(t))return jQuery(".writing-system-container");switch(t){case"parent":return jQuery(e).closest(".writing-system-container");case"ancestor":return jQuery(e).closest(".writing-system-wrapper")}}function getSelectedRefillCtx(e){return jQuery('.refill-radio input[name="refill"]:checked',e)}function getInkColorOptionsCtx(e,t){return is_defined(t)?jQuery('.ink-colors-list[data-refill-id="'+t+'"]',e):jQuery(".ink-colors-list",e)}function getInkColorCtx(e){return jQuery(e).closest(".ink-colors-list")}function getActiveInkColorCtx(e){return jQuery(".active",e)}function getInkColorCtxByDataAttribute(e,t,r){is_defined(r)||(r=getRefillOptionsCtx());getInkColorOptionsCtx(r,e);var a="li";return jQuery.each(t,function(e,t){a+="[data-"+t.dataAttribute+t.dataRelation+'"'+t.attributeValue+'"]'}),jQuery(a,r)}function getRefillDiameterOptionsCtx(e,t){return is_defined(t)?jQuery('.ball-diameter-radio-wrapper[data-refill-id="'+t+'"]',e):jQuery(".ball-diameter-radio-wrapper",e)}function getRefillDiameterOptionCtx(e,t,r){return jQuery(".ball-diameter-radio-container[data-option"+t+'"'+e+'"]',r)}function getRefillDiameterCtx(e,t){return jQuery('.ball-diameter-radio input[type="radio"][value="'+e+'"]',t)}function getSelectedDiameterCtx(e){return jQuery('.ball-diameter-radio input[name^="diameter"]:checked',e).closest(".ball-diameter-radio")}function getRefillExtraOptionsCtx(e,t){return is_defined(t)?jQuery('.refill-extra-options[data-refill-id="'+t+'"]',e):jQuery(".refill-extra-options",e)}function getRefillColorOptionsCtx(e,t){return is_defined(t)?jQuery('.refill-colors-list[data-refill-id="'+t+'"]',e):jQuery(".refill-colors-list",e)}function getRefillColorCtxByDataAttribute(e,t,r){is_defined(r)||(r=getRefillExtraOptionsCtx(getRefillOptionsCtx(),e));getRefillColorOptionsCtx(r,e);var a="li";return jQuery.each(t,function(e,t){a+="[data-"+t.dataAttribute+t.dataRelation+'"'+t.attributeValue+'"]'}),jQuery(a,r)}function getRefillColorCtx(e){return jQuery(e).closest(".refill-colors-list")}function getActiveRefillColorCtx(e){return jQuery(".active",e)}function getImprintMainCtx(){return jQuery("#pills-imprint")}function getPrintAreaTabsCtx(){return jQuery("#v-pills-printareas-tabContent")}function getPrintAreaTypesTabCtx(){return jQuery("#nav-tabs-printareas-tabContent")}function getPrintAreaTabCtx(e,t){return is_defined(t)?jQuery(e).closest(".tab-pane."+t+"-tab"):jQuery(e).closest(".tab-pane")}function getPrintAreaParentTabCtx(e){return getPrintAreaTabCtx(e,"parent")}function getPrintAreaAncestorTabCtx(e){return getPrintAreaTabCtx(e,"ancestor")}function getPrintAreaTabCtxByAttribute(e,t){var r=".tab-pane";return is_defined(t)||(t=getPrintAreaTabsCtx()),jQuery.each(e,function(e,t){r+="["+t.attributeType+t.dataRelation+'"'+t.attributeValue+'"]'}),jQuery(r,t)}function getImageSelectionCtx(e){return is_defined(e)?jQuery(".image-selection",e):jQuery(".image-selection")}function getImageFiltersCtx(e){return jQuery(".image-filters",e)}function getImageFineTuningCtx(e){return jQuery(".image-fine-tuning",e)}function getHistoryGridCtx(e){return is_defined(e)?jQuery(".logos-history .logos-grid",e):jQuery(".logos-history .logos-grid")}function getNoticesCtx(e){return is_defined(e)?jQuery(".editor-body .notices-wrapper",e):jQuery(".editor-body .notices-wrapper")}function getHistoryNoticesCtx(e){return is_defined(e)?jQuery(".editor-body .notices-wrapper",e):jQuery(".editor-body .notices-wrapper")}function getPreviewCtx(e){return e?jQuery(".pen-preview."+e):jQuery(".pen-preview:not(.horizontal-view)")}function getPreviewPrintAreaCtxByDataAttribute(e,t){var r=".print-area";return is_defined(t)||(t=getPreviewCtx()),jQuery.each(e,function(e,t){r+="[data-"+t.dataAttribute+t.dataRelation+'"'+t.attributeValue+'"]'}),jQuery(r,t)}function getPreviewPrintAreaContentCtx(e){return jQuery(".print-area-content",e)}function getModelName(e){switch(e){case"short":return jQuery(".tech-specs.model .model","#pills-recap").text().trim();case"full":return jQuery("article.pen").data("model-name")}}function getModelShortName(){return getModelName("short")}function getModelFullName(){return getModelName("full")}function getModelId(){return jQuery("article.pen").data("model-id")}function getModelTagName(){return{ds1:141,ds2:142,ds3:143,ds3fastlane:143,ds31:144,ds3biotic:145,ds4:146,ds5:147,ds5fastlane:147,ds7:148,ds8:203,ds8fastlane:203,ds8mc:204,ds9:149,qs01:151,qs03:152,qs20:153,qs30:154,qs40:155,qs40truebiotic:156}[getModelSlug()]}function getFullProductCode(){return getModelShortName()+" "+getProductCode()}function getModelSlug(){return jQuery("article.pen").data("slug")}function updateConfiguratorAfterRestoreConfiguration(){var e=getPrimaryComponentCtx(),t=(e.data("component-id"),getActiveSurfaceCtx(e)),r=t.data("surface-code"),a=getActiveColorCtx(t),o=a.data("asset-color-code"),n=a.data("alternative-color");is_defined(n)&&""!=n&&n.split(",");getComponentCtxByDataAttribute([{dataAttribute:"component-type",attributeValue:"primary",dataRelation:"!="}]).each(function(e,t){var a=jQuery(t),n=a.data("component-type"),i=a.data("component-id"),u=(a.data("component-slug"),matches[r][i]);getComponentSurfacesCtx(a).each(function(e,t){var r=jQuery(t);checkSurfaceCompatibility(u,a,r)}),"optional"!=n&&(jQuery('.color-message p[data-asset-color-code!="'+o+'"]',a).removeClass("active"),jQuery('.color-message p[data-asset-color-code="'+o+'"]',a).addClass("active"),MixAndMatch(r,a)),showColorLegend(a)}),ET1(!0,a),ET2(!0,a),ET4(),removeOptionHandler(),reorderComponentsOptions(),updatePrintAreas(),updateTextColorPalette(),updateQRCodes(),updateWritingSystemOptions(),updateConfigurationRecap(),refreshPreview(),displayLoading(!1,null)}function showBrokenConfigurationMessage(){jQuery("#broken-modal .modal-body .primary-content").html('
'+minerva_common_vars.missing_configuration_data.generic_option_intro+"
"),jQuery("#broken-modal .modal-body .secondary-content").append(''+minerva_common_vars.missing_configuration_data.generic_option+"
"),jQuery("#broken-modal").modal("show")}function setProductPreviewFileName(e){var t=getModelSlug(),r=getActiveSurfaceCtx(getPrimaryComponentCtx()),a=r.data("surface-code").toLowerCase(),o=getActiveColorCtx(r).data("color-code").toLowerCase(),n=[];return"ab"==a&&(a=o.match(/[a-z]+/)[0].replace("ab","")+"a"),o=o.match(/\d+/)[0],n.push(t),n.push(a),n.push(o),""!=e&&n.push(e),n.join("_")}function _createProductPreview(e,t){if(""!=e){var r;switch(e){case"metal":r="metal-option"}is_defined(t)&&t?createProductPreview(e,function(e){console.log(e.urls)},function(e){console.log(e.message)}):selectOption(r,!0,function(){createProductPreview(e,function(e){console.log(e.urls)},function(e){console.log(e.message)})})}else createProductPreview(e,function(e){console.log(e.urls)},function(e){console.log(e.message)})}function createProductPreview(e,t,r){var a=jQuery.Deferred(),o=[],n=(new Date).getTime();function i(e,t,r,a,n,i,u){var l=jQuery.Deferred();return createPreviewTemplate(e,t,r,a,n,i,function(e){o.push(e),l.resolve()}),l.promise()}printProgress("","Rendering front-view image in progress"),jQuery.when(i("hi",!1,1,"png",!1,"f")).done(function(){printProgress("","Rendering finished"),printProgress("","Rendering side-view image in progress"),jQuery.when(i("hi",!1,1,"png",!1,"s")).done(function(){printProgress("","Rendering finished"),printProgress("","Creating preview images in progress");var i=base64ToBlob(o[0]),u=base64ToBlob(o[1]),l=new FormData;l.append("action","minerva_create_product_preview"),l.append("frontViewImageFile",i),l.append("sideViewImageFile",u),l.append("fileName",setProductPreviewFileName(e)),l.append("configuration",getConfigurationData("shortObj")),l.append("format","png"),l.append("_nonce",jQuery("#product_preview").val()),jQuery.ajax({url:minerva_configurator_vars.ajaxurl,type:"POST",contentType:!1,processData:!1,cache:!1,dataType:"json",data:l,success:function(e){a.resolve(),e.error?r(e):(printProgress(n,"Preview images successfully created"),t(e))},error:function(e,t,r){a.reject(),console.log(e),console.log(r)}})})})}function printProgress(e,t){if(""==e)console.log(t);else{var r=(new Date).getTime()-e;console.log(t+" ("+Math.round(r/1e3)+" sec)")}}function selectOption(e,t,r){getComponentCtxByDataAttribute([{dataAttribute:"component-type",attributeValue:"primary",dataRelation:"!="}]).each(function(r,a){var o=jQuery(a),n=!1;getSurfaceCtxByDataAttribute([{dataAttribute:"visible",attributeValue:"true",dataRelation:"="}],!1,o).each(function(r,a){n||getColorCtx(jQuery(a)).each(function(r,a){var o=jQuery(a);o.hasClass(e)&&(t?o.trigger("click"):setActiveColor(o),n=!0)})})}),is_defined(r)&&jQuery.isFunction(r)&&r()}function base64ToBlob(e,t){var r=e.split(";"),a=r[0].split(":")[1]||"",o=r[1].split(",")[1];t=t||512;for(var n=atob(o),i=[],u=0;u