(()=>{"use strict";var e={n:t=>{var i=t&&t.__esModule?()=>t.default:()=>t;return e.d(i,{a:i}),i},d:(t,i)=>{for(var a in i)e.o(i,a)&&!e.o(t,a)&&Object.defineProperty(t,a,{enumerable:!0,get:i[a]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)};const t=window.jQuery;var i=e.n(t);const a=window.wp.apiFetch;var n=e.n(a);const c=class{constructor({id:e,prefix:t,data:a}){this.id=e,this.prefix=t,this.data=a,i()(document.body).on("change",'[name^="woocommerce_ppcp_"]',this.handleInputChange.bind(this)),i()(document.body).on("click",".wc-ppcp-clipboard",this.handleClipboard.bind(this)),this.maybeShowDependencies(),this.initializeSlider()}getFieldKey(e){return`${this.prefix}${e}`}getFieldValue(e){const t=i()(`#${this.getFieldKey(e)}`);return t.is(":checkbox")?t.is(":checked"):t.val()}setFieldValue(e,t,a=!1){const n=`#${this.getFieldKey(e)}`;i()(n).val(t),a&&i()(n).trigger("change")}handleInputChange(e){this.maybeShowDependencies(),"woocommerce_ppcp_use_place_order"===i()(e.currentTarget).attr("name")&&i()(e.currentTarget).is(":checked")&&i()("#woocommerce_ppcp_checkout_placement").val("place_order").trigger("change")}maybeShowDependencies(){const e=document.querySelectorAll("[data-show-if]"),t=[];for(const a of e){const e=a.getAttribute("data-show-if").match(/(([\w]+)=([\w]+))+/g);if(e&&!t.includes(a.id))for(const n of e){const[e,c]=n.split("="),o=document.getElementById(`${this.prefix}${e}`);try{if(i()(o).is(":checkbox")){if(o.checked.toString()!=c)throw"no match"}else if(o.value!=c)throw"no match";i()(a).closest("tr").show()}catch(e){t.push(a.id),i()(a).closest("tr").hide();break}}}}getSettings(){return wcPPCPSettings[this.id]}getLoaderHtml(){return'<div class="wc-ppcp-loader">\n            <div></div>\n            <div></div>\n            <div></div>\n        </div>'}showLoader(e){i()(e).append(this.getLoaderHtml())}hideLoader(e){i()(e).find(".wc-ppcp-loader").remove()}block(e=null,t={}){const a={css:{border:"none","background-color":"transparent","font-size":"16px"},overlayCSS:{background:"#fff",opacity:.7},...t};e?i()(e).block(a):i().blockUI(a)}unblock(e){e?i()(e).unblock():i().unblockUI()}handleClipboard(e){const t=i()(e.currentTarget).parent().data("clipboard"),a=document.createElement("input");a.value=t,a.type="text",i()(document.body).append(a),a.select(),document.execCommand("copy"),i()(a).remove()}getAjaxPath(e){const t=wcPPCPSettings?.adminAjaxUrl||"";return e=e.replace(/(^\/)/,""),t.replace("$path",e)}initializeSlider(){const e=i()(".wc-ppcp-slider");if(!e.length)return;const t={min:e.data("height-min"),max:e.data("height-max"),step:e.data("height-step"),value:this.getFieldValue("button_height")};e.slider(t),e.on("slidechange",(e,t)=>{this.onSlideChange(e,t)}).on("slide",(t,i)=>e.closest("td").find(".wc-ppcp-slider-val").text(`${i.value}px`))}onSlideChange(e,t){this.setFieldValue("button_height",t.value,!0),i()(e.currentTarget).closest("td").find(".wc-ppcp-slider-val").text(`${t.value}px`)}};var o;o="ppcp_applepay",new class extends c{constructor(e){super(e),i()(document.body).on("click",".button-domain-association",this.createDomainAssociationFile.bind(this))}async createDomainAssociationFile(e){e.preventDefault();const t=i()(e.currentTarget),a=t.text();try{t.prop("disabled",!0).text(this.data.i18n.processing);const e=await n()({method:"POST",url:this.getAjaxPath("/wc-ppcp/v1/admin/domain-association-file")});alert(e.message)}catch(e){alert(this.data.i18n.file_error+" "+e.message)}finally{t.prop("disabled",!1).text(a)}}}({id:o,prefix:`woocommerce_${o}_`,data:wcPPCPSettings?.[o]||{}}),(this.wcPPCP=this.wcPPCP||{})["applepay-settings"]={}})();
//# sourceMappingURL=applepay-settings.js.map