!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var t;"undefined"!=typeof window?t=window:"undefined"!=typeof global?t=global:"undefined"!=typeof self&&(t=self),t.sbjs=e()}}(function(){return function e(t,r,n){function a(s,o){if(!r[s]){if(!t[s]){var c="function"==typeof require&&require;if(!o&&c)return c(s,!0);if(i)return i(s,!0);var u=new Error("Cannot find module '"+s+"'");throw u.code="MODULE_NOT_FOUND",u}var p=r[s]={exports:{}};t[s][0].call(p.exports,function(e){var r=t[s][1][e];return a(r||e)},p,p.exports,e,t,r,n)}return r[s].exports}for(var i="function"==typeof require&&require,s=0;s<n.length;s++)a(n[s]);return a}({1:[function(e,t,r){"use strict";var n=e("./init"),a={init:function(e){this.get=n(e),e&&e.callback&&"function"==typeof e.callback&&e.callback(this.get)}};t.exports=a},{"./init":6}],2:[function(e,t,r){"use strict";var n=e("./terms"),a=e("./helpers/utils"),i={containers:{current:"sbjs_current",current_extra:"sbjs_current_add",first:"sbjs_first",first_extra:"sbjs_first_add",session:"sbjs_session",udata:"sbjs_udata",promocode:"sbjs_promo"},service:{migrations:"sbjs_migrations"},delimiter:"|||",aliases:{main:{type:"typ",source:"src",medium:"mdm",campaign:"cmp",content:"cnt",term:"trm",id:"id",platform:"plt",format:"fmt",tactic:"tct"},extra:{fire_date:"fd",entrance_point:"ep",referer:"rf"},session:{pages_seen:"pgs",current_page:"cpg"},udata:{visits:"vst",ip:"uip",agent:"uag"},promo:"code"},pack:{main:function(e){return i.aliases.main.type+"="+e.type+i.delimiter+i.aliases.main.source+"="+e.source+i.delimiter+i.aliases.main.medium+"="+e.medium+i.delimiter+i.aliases.main.campaign+"="+e.campaign+i.delimiter+i.aliases.main.content+"="+e.content+i.delimiter+i.aliases.main.term+"="+e.term+i.delimiter+i.aliases.main.id+"="+e.id+i.delimiter+i.aliases.main.platform+"="+e.platform+i.delimiter+i.aliases.main.format+"="+e.format+i.delimiter+i.aliases.main.tactic+"="+e.tactic},extra:function(e){return i.aliases.extra.fire_date+"="+a.setDate(new Date,e)+i.delimiter+i.aliases.extra.entrance_point+"="+document.location.href+i.delimiter+i.aliases.extra.referer+"="+(document.referrer||n.none)},user:function(e,t){return i.aliases.udata.visits+"="+e+i.delimiter+i.aliases.udata.ip+"="+t+i.delimiter+i.aliases.udata.agent+"="+navigator.userAgent},session:function(e){return i.aliases.session.pages_seen+"="+e+i.delimiter+i.aliases.session.current_page+"="+document.location.href},promo:function(e){return i.aliases.promo+"="+a.setLeadingZeroToInt(a.randomInt(e.min,e.max),e.max.toString().length)}}};t.exports=i},{"./helpers/utils":5,"./terms":9}],3:[function(e,t,r){"use strict";var n=e("../data").delimiter;t.exports={useBase64:!1,setBase64Flag:function(e){this.useBase64=e},encodeData:function(e){return encodeURIComponent(e).replace(/\!/g,"%21").replace(/\~/g,"%7E").replace(/\*/g,"%2A").replace(/\'/g,"%27").replace(/\(/g,"%28").replace(/\)/g,"%29")},decodeData:function(e){try{return decodeURIComponent(e).replace(/\%21/g,"!").replace(/\%7E/g,"~").replace(/\%2A/g,"*").replace(/\%27/g,"'").replace(/\%28/g,"(").replace(/\%29/g,")")}catch(t){try{return unescape(e)}catch(r){return""}}},set:function(e,t,r,n,a){var i,s;if(r){var o=new Date;o.setTime(o.getTime()+60*r*1e3),i="; expires="+o.toGMTString()}else i="";s=n&&!a?";domain=."+n:"";var c=this.encodeData(t);this.useBase64&&(c=btoa(c).replace(/=+$/,"")),document.cookie=this.encodeData(e)+"="+c+i+s+"; path=/"},get:function(e){for(var t=this.encodeData(e)+"=",r=document.cookie.split(";"),n=0;n<r.length;n++){for(var a=r[n];" "===a.charAt(0);)a=a.substring(1,a.length);if(0===a.indexOf(t)){var i=a.substring(t.length,a.length);if(/^[A-Za-z0-9+/]+$/.test(i))try{i=atob(i.padEnd(4*Math.ceil(i.length/4),"="))}catch(s){}return this.decodeData(i)}}return null},destroy:function(e,t,r){this.set(e,"",-1,t,r)},parse:function(e){var t=[],r={};if("string"==typeof e)t.push(e);else for(var a in e)e.hasOwnProperty(a)&&t.push(e[a]);for(var i=0;i<t.length;i++){var s;r[this.unsbjs(t[i])]={},s=this.get(t[i])?this.get(t[i]).split(n):[];for(var o=0;o<s.length;o++){var c=s[o].split("="),u=c.splice(0,1);u.push(c.join("=")),r[this.unsbjs(t[i])][u[0]]=this.decodeData(u[1])}}return r},unsbjs:function(e){return e.replace("sbjs_","")}}},{"../data":2}],4:[function(e,t,r){"use strict";t.exports={parse:function(e){for(var t=this.parseOptions,r=t.parser[t.strictMode?"strict":"loose"].exec(e),n={},a=14;a--;)n[t.key[a]]=r[a]||"";return n[t.q.name]={},n[t.key[12]].replace(t.q.parser,function(e,r,a){r&&(n[t.q.name][r]=a)}),n},parseOptions:{strictMode:!1,key:["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"],q:{name:"queryKey",parser:/(?:^|&)([^&=]*)=?([^&]*)/g},parser:{strict:/^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/,loose:/^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/}},getParam:function(e){for(var t={},r=(e||window.location.search.substring(1)).split("&"),n=0;n<r.length;n++){var a=r[n].split("=");if("undefined"==typeof t[a[0]])t[a[0]]=a[1];else if("string"==typeof t[a[0]]){var i=[t[a[0]],a[1]];t[a[0]]=i}else t[a[0]].push(a[1])}return t},getHost:function(e){return this.parse(e).host.replace("www.","")}}},{}],5:[function(e,t,r){"use strict";t.exports={escapeRegexp:function(e){return e.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&")},setDate:function(e,t){var r=e.getTimezoneOffset()/60,n=e.getHours(),a=t||0===t?t:-r;return e.setHours(n+r+a),e.getFullYear()+"-"+this.setLeadingZeroToInt(e.getMonth()+1,2)+"-"+this.setLeadingZeroToInt(e.getDate(),2)+" "+this.setLeadingZeroToInt(e.getHours(),2)+":"+this.setLeadingZeroToInt(e.getMinutes(),2)+":"+this.setLeadingZeroToInt(e.getSeconds(),2)},setLeadingZeroToInt:function(e,t){for(var r=e+"";r.length<t;)r="0"+r;return r},randomInt:function(e,t){return Math.floor(Math.random()*(t-e+1))+e}}},{}],6:[function(e,t,r){"use strict";var n=e("./data"),a=e("./terms"),i=e("./helpers/cookies"),s=e("./helpers/uri"),o=e("./helpers/utils"),c=e("./params"),u=e("./migrations");t.exports=function(e){var t,r,p,f,m,d,l,g,h,y,_,v,b,x=c.fetch(e),k=s.getParam(),w=x.domain.host,q=x.domain.isolate,I=x.lifetime;function j(e){switch(e){case a.traffic.utm:t=a.traffic.utm,r="undefined"!=typeof k.utm_source?k.utm_source:"undefined"!=typeof k.gclid?"google":"undefined"!=typeof k.yclid?"yandex":a.none,p="undefined"!=typeof k.utm_medium?k.utm_medium:"undefined"!=typeof k.gclid?"cpc":"undefined"!=typeof k.yclid?"cpc":a.none,f="undefined"!=typeof k.utm_campaign?k.utm_campaign:"undefined"!=typeof k[x.campaign_param]?k[x.campaign_param]:"undefined"!=typeof k.gclid?"google_cpc":"undefined"!=typeof k.yclid?"yandex_cpc":a.none,m="undefined"!=typeof k.utm_content?k.utm_content:"undefined"!=typeof k[x.content_param]?k[x.content_param]:a.none,l=k.utm_id||a.none,g=k.utm_source_platform||a.none,h=k.utm_creative_format||a.none,y=k.utm_marketing_tactic||a.none,d="undefined"!=typeof k.utm_term?k.utm_term:"undefined"!=typeof k[x.term_param]?k[x.term_param]:function(){var e=document.referrer;if(k.utm_term)return k.utm_term;if(!(e&&s.parse(e).host&&s.parse(e).host.match(/^(?:.*\.)?yandex\..{2,9}$/i)))return!1;try{return s.getParam(s.parse(document.referrer).query).text}catch(t){return!1}}()||a.none;break;case a.traffic.organic:t=a.traffic.organic,r=r||s.getHost(document.referrer),p=a.referer.organic,f=a.none,m=a.none,d=a.none,l=a.none,g=a.none,h=a.none,y=a.none;break;case a.traffic.referral:t=a.traffic.referral,r=r||s.getHost(document.referrer),p=p||a.referer.referral,f=a.none,m=s.parse(document.referrer).path,d=a.none,l=a.none,g=a.none,h=a.none,y=a.none;break;case a.traffic.typein:t=a.traffic.typein,r=x.typein_attributes.source,p=x.typein_attributes.medium,f=a.none,m=a.none,d=a.none,l=a.none,g=a.none,h=a.none,y=a.none;break;default:t=a.oops,r=a.oops,p=a.oops,f=a.oops,m=a.oops,d=a.oops,l=a.oops,g=a.oops,h=a.oops,y=a.oops}var i={type:t,source:r,medium:p,campaign:f,content:m,term:d,id:l,platform:g,format:h,tactic:y};return n.pack.main(i)}function R(e){var t=document.referrer;switch(e){case a.traffic.organic:return!!t&&H(t)&&function(e){var t=new RegExp("^(?:.*\\.)?"+o.escapeRegexp("yandex")+"\\..{2,9}$"),n=new RegExp(".*"+o.escapeRegexp("text")+"=.*"),a=new RegExp("^(?:www\\.)?"+o.escapeRegexp("google")+"\\..{2,9}$");if(s.parse(e).query&&s.parse(e).host.match(t)&&s.parse(e).query.match(n))return r="yandex",!0;if(s.parse(e).host.match(a))return r="google",!0;if(!s.parse(e).query)return!1;for(var i=0;i<x.organics.length;i++){if(s.parse(e).host.match(new RegExp("^(?:.*\\.)?"+o.escapeRegexp(x.organics[i].host)+"$","i"))&&s.parse(e).query.match(new RegExp(".*"+o.escapeRegexp(x.organics[i].param)+"=.*","i")))return r=x.organics[i].display||x.organics[i].host,!0;if(i+1===x.organics.length)return!1}}(t);case a.traffic.referral:return!!t&&H(t)&&function(e){if(!(x.referrals.length>0))return r=s.getHost(e),!0;for(var t=0;t<x.referrals.length;t++){if(s.parse(e).host.match(new RegExp("^(?:.*\\.)?"+o.escapeRegexp(x.referrals[t].host)+"$","i")))return r=x.referrals[t].display||x.referrals[t].host,p=x.referrals[t].medium||a.referer.referral,!0;if(t+1===x.referrals.length)return r=s.getHost(e),!0}}(t);default:return!1}}function H(e){if(x.domain){if(q)return s.getHost(e)!==s.getHost(w);var t=new RegExp("^(?:.*\\.)?"+o.escapeRegexp(w)+"$","i");return!s.getHost(e).match(t)}return s.getHost(e)!==s.getHost(document.location.href)}function D(){i.set(n.containers.current_extra,n.pack.extra(x.timezone_offset),I,w,q),i.get(n.containers.first_extra)||i.set(n.containers.first_extra,n.pack.extra(x.timezone_offset),I,w,q)}return i.setBase64Flag(x.base64),u.go(I,w,q),i.set(n.containers.current,function(){var e;if("undefined"!=typeof k.utm_source||"undefined"!=typeof k.utm_medium||"undefined"!=typeof k.utm_campaign||"undefined"!=typeof k.utm_content||"undefined"!=typeof k.utm_term||"undefined"!=typeof k.utm_id||"undefined"!=typeof k.utm_source_platform||"undefined"!=typeof k.utm_creative_format||"undefined"!=typeof k.utm_marketing_tactic||"undefined"!=typeof k.gclid||"undefined"!=typeof k.yclid||"undefined"!=typeof k[x.campaign_param]||"undefined"!=typeof k[x.term_param]||"undefined"!=typeof k[x.content_param])D(),e=j(a.traffic.utm);else if(R(a.traffic.organic))D(),e=j(a.traffic.organic);else if(!i.get(n.containers.session)&&R(a.traffic.referral))D(),e=j(a.traffic.referral);else{if(i.get(n.containers.first)||i.get(n.containers.current))return i.get(n.containers.current);D(),e=j(a.traffic.typein)}return e}(),I,w,q),i.get(n.containers.first)||i.set(n.containers.first,i.get(n.containers.current),I,w,q),i.get(n.containers.udata)?(_=parseInt(i.parse(n.containers.udata)[i.unsbjs(n.containers.udata)][n.aliases.udata.visits])||1,_=i.get(n.containers.session)?_:_+1,v=n.pack.user(_,x.user_ip)):(_=1,v=n.pack.user(_,x.user_ip)),i.set(n.containers.udata,v,I,w,q),i.get(n.containers.session)?(b=parseInt(i.parse(n.containers.session)[i.unsbjs(n.containers.session)][n.aliases.session.pages_seen])||1,b+=1):b=1,i.set(n.containers.session,n.pack.session(b),x.session_length,w,q),x.promocode&&!i.get(n.containers.promocode)&&i.set(n.containers.promocode,n.pack.promo(x.promocode),I,w,q),i.parse(n.containers)}},{"./data":2,"./helpers/cookies":3,"./helpers/uri":4,"./helpers/utils":5,"./migrations":7,"./params":8,"./terms":9}],7:[function(e,t,r){"use strict";var n=e("./data"),a=e("./helpers/cookies");t.exports={go:function(e,t,r){var i,s=this.migrations,o={l:e,d:t,i:r};if(a.get(n.containers.first)||a.get(n.service.migrations)){if(!a.get(n.service.migrations))for(i=0;i<s.length;i++)s[i].go(s[i].id,o)}else{var c=[];for(i=0;i<s.length;i++)c.push(s[i].id);var u="";for(i=0;i<c.length;i++)u+=c[i]+"=1",i<c.length-1&&(u+=n.delimiter);a.set(n.service.migrations,u,o.l,o.d,o.i)}},migrations:[{id:"1418474375998",version:"1.0.0-beta",go:function(e,t){var r=e+"=1",i=e+"=0",s=function(e,t,r){return t||r?e:n.delimiter};try{var o=[];for(var c in n.containers)n.containers.hasOwnProperty(c)&&o.push(n.containers[c]);for(var u=0;u<o.length;u++)if(a.get(o[u])){var p=a.get(o[u]).replace(/(\|)?\|(\|)?/g,s);a.destroy(o[u],t.d,t.i),a.destroy(o[u],t.d,!t.i),a.set(o[u],p,t.l,t.d,t.i)}a.get(n.containers.session)&&a.set(n.containers.session,n.pack.session(0),t.l,t.d,t.i),a.set(n.service.migrations,r,t.l,t.d,t.i)}catch(f){a.set(n.service.migrations,i,t.l,t.d,t.i)}}}]}},{"./data":2,"./helpers/cookies":3}],8:[function(e,t,r){"use strict";var n=e("./terms"),a=e("./helpers/uri");t.exports={fetch:function(e){var t=e||{},r={};if(r.lifetime=this.validate.checkFloat(t.lifetime)||6,r.lifetime=parseInt(30*r.lifetime*24*60),r.session_length=this.validate.checkInt(t.session_length)||30,r.timezone_offset=this.validate.checkInt(t.timezone_offset),r.base64=t.base64||!1,r.campaign_param=t.campaign_param||!1,r.term_param=t.term_param||!1,r.content_param=t.content_param||!1,r.user_ip=t.user_ip||n.none,t.promocode?(r.promocode={},r.promocode.min=parseInt(t.promocode.min)||1e5,r.promocode.max=parseInt(t.promocode.max)||999999):r.promocode=!1,t.typein_attributes&&t.typein_attributes.source&&t.typein_attributes.medium?(r.typein_attributes={},r.typein_attributes.source=t.typein_attributes.source,r.typein_attributes.medium=t.typein_attributes.medium):r.typein_attributes={source:"(direct)",medium:"(none)"},t.domain&&this.validate.isString(t.domain)?r.domain={host:t.domain,isolate:!1}:t.domain&&t.domain.host?r.domain=t.domain:r.domain={host:a.getHost(document.location.hostname),isolate:!1},r.referrals=[],t.referrals&&t.referrals.length>0)for(var i=0;i<t.referrals.length;i++)t.referrals[i].host&&r.referrals.push(t.referrals[i]);if(r.organics=[],t.organics&&t.organics.length>0)for(var s=0;s<t.organics.length;s++)t.organics[s].host&&t.organics[s].param&&r.organics.push(t.organics[s]);return r.organics.push({host:"bing.com",param:"q",display:"bing"}),r.organics.push({host:"yahoo.com",param:"p",display:"yahoo"}),r.organics.push({host:"about.com",param:"q",display:"about"}),r.organics.push({host:"aol.com",param:"q",display:"aol"}),r.organics.push({host:"ask.com",param:"q",display:"ask"}),r.organics.push({host:"globososo.com",param:"q",display:"globo"}),r.organics.push({host:"go.mail.ru",param:"q",display:"go.mail.ru"}),r.organics.push({host:"rambler.ru",param:"query",display:"rambler"}),r.organics.push({host:"tut.by",param:"query",display:"tut.by"}),r.referrals.push({host:"t.co",display:"twitter.com"}),r.referrals.push({host:"plus.url.google.com",display:"plus.google.com"}),r},validate:{checkFloat:function(e){return!(!e||!this.isNumeric(parseFloat(e)))&&parseFloat(e)},checkInt:function(e){return!(!e||!this.isNumeric(parseInt(e)))&&parseInt(e)},isNumeric:function(e){return!isNaN(e)},isString:function(e){return"[object String]"===Object.prototype.toString.call(e)}}}},{"./helpers/uri":4,"./terms":9}],9:[function(e,t,r){"use strict";t.exports={traffic:{utm:"utm",organic:"organic",referral:"referral",typein:"typein"},referer:{referral:"referral",organic:"organic",social:"social"},none:"(none)",oops:"(Houston, we have a problem)"}},{}]},{},[1])(1)});;
!function(t){"use strict";const e=t.params,n=(document.querySelector.bind(document),(t,e)=>e.split(".").reduce((t,e)=>t&&t[e],t)),i=()=>null,s=t=>null===t||t===undefined?"":t,o="wc/store/checkout";function a(t){document.querySelectorAll("wc-order-attribution-inputs").forEach((t,e)=>{e>0&&t.remove()});for(const e of document.querySelectorAll("wc-order-attribution-inputs"))e.values=t}function r(t){window.wp&&window.wp.data&&window.wp.data.dispatch&&window.wc&&window.wc.wcBlocksData&&window.wp.data.dispatch(window.wc.wcBlocksData.CHECKOUT_STORE_KEY).setExtensionData("woocommerce/order-attribution",t,!0)}function c(){return"undefined"!=typeof sbjs}function d(){if(window.wp&&window.wp.data&&"function"==typeof window.wp.data.subscribe){const e=window.wp.data.subscribe(function(){e(),r(t.getAttributionData())},o)}}t.getAttributionData=function(){const s=e.allowTracking&&c()?n:i,o=c()?sbjs.get:{},a=Object.entries(t.fields).map(([t,e])=>[t,s(o,e)]);return Object.fromEntries(a)},t.setOrderTracking=function(n){if(e.allowTracking=n,n){if(!c())return;sbjs.init({lifetime:Number(e.lifetime),session_length:Number(e.session),base64:Boolean(e.base64),timezone_offset:"0"})}else!function(){const t=window.location.hostname;["sbjs_current","sbjs_current_add","sbjs_first","sbjs_first_add","sbjs_session","sbjs_udata","sbjs_migrations","sbjs_promo"].forEach(e=>{document.cookie=`${e}=; path=/; max-age=-999; domain=.${t};`})}();const i=t.getAttributionData();a(i),r(i)},t.setOrderTracking(e.allowTracking),"loading"===document.readyState?document.addEventListener("DOMContentLoaded",d):d(),window.customElements.define("wc-order-attribution-inputs",class extends HTMLElement{constructor(){if(super(),this._fieldNames=Object.keys(t.fields),this.hasOwnProperty("_values")){let t=this.values;delete this.values,this.values=t||{}}}connectedCallback(){this.innerHTML="";const t=new DocumentFragment;for(const n of this._fieldNames){const i=document.createElement("input");i.type="hidden",i.name=`${e.prefix}${n}`,i.value=s(this.values&&this.values[n]||""),t.appendChild(i)}this.appendChild(t)}set values(t){if(this._values=t,this.isConnected)for(const t of this._fieldNames){const n=this.querySelector(`input[name="${e.prefix}${t}"]`);n?n.value=s(this.values[t]):console.warn(`Field "${t}" not found. `+"Most likely, the '<wc-order-attribution-inputs>' element was manipulated.")}}get values(){return this._values}})}(window.wc_order_attribution);;
(()=>{"use strict";jQuery(document).ready(e=>{window.WC_Square_Digital_Wallet_Handler=class{constructor(t){!1!==t.payment_request&&(this.args=t,this.payment_request=t.payment_request,this.total_amount=t.payment_request.total?.amount,this.isPayForOrderPage=t.is_pay_for_order_page,this.orderId=t.order_id,this.orderKey=t.order_key||"",this.id_dasherized=t.gateway_id_dasherized,this.cartForm=".cart",this.wallet="#wc-square-digital-wallet",this.buttons=".wc-square-wallet-buttons",this.isGooglePayHidden=this.args.hide_button_options.includes("google"),this.isApplePayHidden=this.args.hide_button_options.includes("apple"),this.productPageForm=e(".product form"),this.cartTotalsForms=e(".cart_totals, .woocommerce-cart-form"),this.checkoutForm=e("form.checkout, #wc-square-digital-wallet"),0!==e(this.wallet).length&&(e(this.wallet).hide(),e(this.buttons).hide(),this.build_digital_wallet(),this.attach_page_events(),this.buildDigitalWalletDebounced=this.debounce(this.build_digital_wallet,500)))}build_digital_wallet(){this.block_ui(),this.get_payment_request().then(e=>{this.payment_request=JSON.parse(e),this.total_amount=this.payment_request.total?.amount,this.load_square_form()},t=>{this.log("[Square] Could not build payment request. "+t,"error"),e(this.wallet).hide()})}attach_page_events(){if("product"===this.args.context){const t=e(".single_add_to_cart_button");e("#apple-pay-button, #wc-square-google-pay").on("click",e=>{if(t.is(".disabled")||!this.isProductAddonsFormsValid())return e.stopImmediatePropagation(),void(t.is(".wc-variation-is-unavailable")?window.alert(wc_add_to_cart_variation_params.i18n_unavailable_text):t.is(".wc-variation-selection-needed")&&window.alert(wc_add_to_cart_variation_params.i18n_make_a_selection_text));this.add_to_cart()}),e(document.body).on("woocommerce_variation_has_changed",()=>this.build_digital_wallet()),e(".quantity").on("input",".qty",()=>this.buildDigitalWalletDebounced())}"cart"===this.args.context&&e(document.body).on("updated_cart_totals",()=>this.build_digital_wallet()),"checkout"===this.args.context&&e(document.body).on("updated_checkout",()=>this.build_digital_wallet()),e(document).on("payment_method_selected",()=>{this.isPayForOrderPage&&e("#payment_method_override").remove()})}load_square_form(){if(this.googlePay&&(this.googlePay.destroy(),this.squareFormLoaded=!1),this.applePay&&(this.applePay.destroy(),this.squareFormLoaded=!1),this.squareFormLoaded)return;this.squareFormLoaded=!0,this.log("[Square] Building digital wallet payment form");const{applicationId:e,locationId:t}=this.get_form_params();this.payments=window.Square.payments(e,t),this.initializeDigitalWalletPaymentMethods()}async initializeDigitalWalletPaymentMethods(){if(!this.payments)return;const t=this.payments.paymentRequest(this.create_payment_request());if(this.registerDigitalWalletShippingEventHandlers(t),this.isGooglePayHidden||(this.googlePay=await this.payments.googlePay(t),this.googlePay.attach("#wc-square-google-pay",{buttonSizeMode:"fill",buttonType:"long",buttonColor:this.args.google_pay_color}).then(()=>{const t=e("#wc-square-google-pay button").first();if(t.length>0){const e=t.attr("aria-label")||this.args.buy_with_gpay_text;t.attr("aria-label",`${e}, ${this.args.opens_in_new_window_text}`)}}),e("#wc-square-google-pay").on("click",async e=>this.handleGooglePayPaymentMethodSubmission(e,this.googlePay)),e("#wc-square-google-pay").show()),!this.isApplePayHidden)try{this.applePay=await this.payments.applePay(t),e("#apple-pay-button").on("click",async e=>this.handleApplePayPaymentMethodSubmission(e,this.applePay)),e("#apple-pay-button").show()}catch(e){console.log(e.message)}(this.googlePay||this.applePay)&&(e(this.buttons).unblock(),e(this.wallet).show())}async handleGooglePayPaymentMethodSubmission(e,t=null){if(e.preventDefault(),!t)return;switch(this.blockedForm=null,this.args.context){case"product":this.blockedForm=this.blockForms(this.productPageForm);break;case"cart":this.blockedForm=this.blockForms(this.cartTotalsForms);break;case"checkout":this.blockedForm=this.blockForms(this.checkoutForm)}const a=await t.tokenize();if("OK"===a.status){const e={...a.details.card,digital_wallet_type:a.details.method},t={billingContact:a.details.billing};a.details.shipping&&(t.shippingContact=a.details.shipping.contact,t.shippingOption=a.details.shipping.option),this.handle_card_nonce_response(!1,a.token,e,t)}else this.blockedForm&&this.blockedForm.unblock()}blockForms(e){return e.block({message:null,overlayCSS:{background:"#fff",opacity:.6}}),e}async handleApplePayPaymentMethodSubmission(e,t=null){if(e.preventDefault(),!t)return;const a=await t.tokenize();if("OK"===a.status){const e={...a.details.card,digital_wallet_type:a.details.method},t={billingContact:a.details.billing};a.details.shipping&&(t.shippingContact=a.details.shipping.contact,t.shippingOption=a.details.shipping.option),this.handle_card_nonce_response(!1,a.token,e,t)}}registerDigitalWalletShippingEventHandlers(e){e.addEventListener("shippingoptionchanged",e=>this.handle_shipping_option_changed(e)),e.addEventListener("shippingcontactchanged",e=>this.handle_shipping_address_changed(e))}get_form_params(){const e={applicationId:this.args.application_id,locationId:this.args.location_id,autobuild:!1,applePay:{elementId:"apple-pay-button"},googlePay:{elementId:"wc-square-google-pay"}};return!1===this.payment_request.requestShippingAddress&&delete e.callbacks.shippingOptionChanged,this.args.hide_button_options.includes("google")&&delete e.googlePay,this.args.hide_button_options.includes("apple")&&delete e.applePay,e}create_payment_request(){return this.payment_request}methods_supported(t,a){!0===t.applePay||!0===t.googlePay?(!0===t.applePay&&e("#apple-pay-button").show(),!0===t.googlePay&&e("#wc-square-google-pay").show(),e(this.wallet).show()):this.log(a)}get_payment_request(){return new Promise((t,a)=>{const i={context:this.args.context,security:this.args.payment_request_nonce,is_pay_for_order_page:this.isPayForOrderPage,order_id:this.orderId,...this.isPayForOrderPage&&this.orderKey&&{order_key:this.orderKey}};if("product"===this.args.context){const t=this.get_product_data();e.extend(i,t)}e.post(this.get_ajax_url("get_payment_request"),i,e=>e.success?t(e.data):a(e.data))})}async handle_shipping_address_changed(e){const t={context:this.args.context,shipping_contact:e,security:this.args.recalculate_totals_nonce,is_pay_for_order_page:this.isPayForOrderPage,order_id:this.orderId,...this.isPayForOrderPage&&this.orderKey&&{order_key:this.orderKey}};return await this.recalculate_totals(t)}async handle_shipping_option_changed(e){const t={context:this.args.context,shipping_option:e.id,security:this.args.recalculate_totals_nonce,is_pay_for_order_page:this.isPayForOrderPage,order_id:this.orderId,...this.isPayForOrderPage&&this.orderKey&&{order_key:this.orderKey}};return await this.recalculate_totals(t)}handle_card_nonce_response(t=!1,a=!1,i={},s={}){if(t)return this.render_errors(t);if(!a)return this.render_errors(this.args.general_error);this.block_ui();const o=e("#order_review"),{billingContact:r={},shippingContact:n={},shippingOption:l=null}=s,d={action:"",_wpnonce:this.args.process_checkout_nonce,billing_first_name:r.givenName?r.givenName:"",billing_last_name:r.familyName?r.familyName:"",billing_company:e("#billing_company").val(),billing_email:n.email?n.email:r.email?r.email:"",billing_phone:n.phone?n.phone:"",billing_country:r.countryCode?r.countryCode.toUpperCase():"",billing_address_1:r.addressLines&&r.addressLines[0]?r.addressLines[0]:"",billing_address_2:r.addressLines&&r.addressLines[1]?r.addressLines[1]:"",billing_city:r.city?r.city:"",billing_state:r.state?r.state:"",billing_postcode:r.postalCode?r.postalCode:"",shipping_first_name:n.givenName?n.givenName:"",shipping_last_name:n.familyName?n.familyName:"",shipping_company:e("#shipping_company").val(),shipping_country:n.countryCode?n.countryCode.toUpperCase():"",shipping_address_1:n.addressLines&&n.addressLines[0]?n.addressLines[0]:"",shipping_address_2:n.addressLines&&n.addressLines[1]?n.addressLines[1]:"",shipping_city:n.city?n.city:"",shipping_state:n.state?n.state:"",shipping_postcode:n.postalCode?n.postalCode:"",shipping_method:[l?l.id:null],order_comments:"",payment_method:"square_credit_card",ship_to_different_address:1,terms:1,"wc-square-credit-card-payment-nonce":a,"wc-square-credit-card-last-four":i.last4?i.last4:null,"wc-square-credit-card-exp-month":i.expMonth?i.expMonth:null,"wc-square-credit-card-exp-year":i.expYear?i.expYear:null,"wc-square-credit-card-payment-postcode":i.billing.postalCode?i.billing.postalCode:null,"wc-square-digital-wallet-type":i.digital_wallet_type,is_pay_for_order_page:this.isPayForOrderPage};this.isPayForOrderPage&&(i.last4&&e(`input[name=wc-${this.id_dasherized}-last-four]`).val(i.last4),i.expMonth&&e(`input[name=wc-${this.id_dasherized}-exp-month]`).val(i.expMonth),i.expYear&&e(`input[name=wc-${this.id_dasherized}-exp-year]`).val(i.expYear),i?.billing?.postalCode&&e(`input[name=wc-${this.id_dasherized}-payment-postcode]`).val(i.billing.postalCode),i.brand&&e(`input[name=wc-${this.id_dasherized}-card-type]`).val(i.brand),e(`input[name=wc-${this.id_dasherized}-payment-nonce]`).val(a),e("#payment_method_override").remove(),e("#payment").after('<input id="payment_method_override" type="hidden" name="payment_method" value="square_credit_card" />')),"GOOGLE_PAY"===i.digital_wallet_type&&(r.givenName&&(d.billing_first_name=r.givenName.split(" ").slice(0,1).join(" "),d.billing_last_name=r.givenName.split(" ").slice(1).join(" ")),n.givenName&&(d.shipping_last_name=n.givenName.split(" ").slice(0,1).join(" "),d.shipping_last_name=n.givenName.split(" ").slice(1).join(" "))),!d.billing_phone&&r.phone&&(d.billing_phone=r.phone),this.log("3DS verification enabled. Verifying buyer");var c=this;e("form.checkout").find(":input:not(:hidden)").serializeArray().forEach(function(e){e.name in d||(d[e.name]=e.value)}),delete d["wc-square-credit-card-payment-token"];try{this.payments.verifyBuyer(a,c.get_verification_details(r,n)).then(t=>{if(t.token){if(this.isPayForOrderPage&&o.length)return e(`input[name=wc-${this.id_dasherized}-buyer-verification-token]`).val(t.token),void o.trigger("submit");c.log("3DS verification successful"),d["wc-square-credit-card-buyer-verification-token"]=t.token,c.do_checkout(d)}})}catch(e){c.log("3DS verification failed"),c.log(e),c.render_errors([e.message])}}do_checkout(e){this.process_digital_wallet_checkout(e).then(e=>{window.location=e.redirect},e=>{this.log(e,"error"),this.render_errors_html(e.messages)})}get_verification_details(e,t){const a={intent:"CHARGE",amount:this.total_amount,currencyCode:this.payment_request.currencyCode,billingContact:{familyName:e.familyName?e.familyName:"",givenName:e.givenName?e.givenName:"",email:t.email?t.email:"",countryCode:e.countryCode?e.countryCode.toUpperCase():"",state:e.state?e.state:"",city:e.city?e.city:"",postalCode:e.postalCode?e.postalCode:"",phone:t.phone?t.phone:"",addressLines:e.addressLines?e.addressLines:""}};return this.log(a),a}async recalculate_totals(t){return new Promise((a,i)=>e.post(this.get_ajax_url("recalculate_totals"),t,e=>e.success?(this.total_amount=e.data.total?.amount,a(e.data)):i(e.data)))}get_product_data(){let t=e(".single_add_to_cart_button").val();const a={};return e(".single_variation_wrap").length&&(t=e(".single_variation_wrap").find('input[name="product_id"]').val(),e(".variations_form").length&&e(".variations_form").find(".variations select").each((t,i)=>{const s=e(i).data("attribute_name")||e(i).attr("name"),o=e(i).val()||"";return a[s]=o})),{product_id:t,quantity:e(".quantity .qty").val(),attributes:a}}isProductAddonsFormsValid(){const t=e("form.cart");if(!t.length)return!0;const a=t.get(0).reportValidity();return window.WC_PAO&&WC_PAO.Form(t).$addons?WC_PAO.Form(t).validation.validate(!0)&&a:a}add_to_cart(){const t={security:this.args.add_to_cart_nonce},a=this.get_product_data(),i=e("form.cart");if(!i.length)return;e.extend(t,a);const s=new FormData(i.get(0));for(const[e,a]of s.entries())e.endsWith("[]")?Array.isArray(t[e])?t[e].push(a):t[e]=[a]:t[e]=a;e.post(this.get_ajax_url("add_to_cart"),t,e=>{if(e.error)return window.alert(e.data);const t=JSON.parse(e.data);this.payment_request=t.payment_request,this.args.payment_request_nonce=t.payment_request_nonce,this.args.add_to_cart_nonce=t.add_to_cart_nonce,this.args.recalculate_totals_nonce=t.recalculate_totals_nonce,this.args.process_checkout_nonce=t.process_checkout_nonce})}process_digital_wallet_checkout(t){return new Promise((a,i)=>{e.post(this.get_ajax_url("process_checkout"),t,e=>"success"===e.result?a(e):i(e))})}get_ajax_url(e){return this.args.ajax_url.replace("%%endpoint%%","square_digital_wallet_"+e)}render_errors_html(t){e(".woocommerce-error, .woocommerce-message").remove();let a="";switch(this.args.context){case"product":a=e(".product");break;case"cart":a=e(".shop_table.cart").closest("form");break;case"checkout":a=e('form[name="checkout"]')}a.before(t),this.blockedForm.unblock(),e("html, body").animate({scrollTop:a.offset().top-100},1e3)}render_errors(e){const t='<ul class="woocommerce-error"><li>'+e.join("</li><li>")+"</li></ul>";this.render_errors_html(t)}block_ui(){e(this.buttons).block({message:null,overlayCSS:{background:"#fff",opacity:.6}})}log(e,t="notice"){if(this.args.logging_enabled)return"error"===t?console.error(e):console.log(e)}debounce(e,t,a){let i;return function(){let s=this,o=arguments,r=a&&!i;clearTimeout(i),i=setTimeout(function(){i=null,a||e.apply(s,o)},t),r&&e.apply(s,o)}}}})})();