/*! * Customer Fields (https://customerfields.com) * Author: Helium Development, https://heliumdev.com * Version: 4.8.4 * DO NOT TOUCH. This file will be overwritten when a form is saved. */ var __defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(t,e,r)=>e in t?__defProp(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,__spreadValues=(t,e)=>{for(var r in e||(e={}))__hasOwnProp.call(e,r)&&__defNormalProp(t,r,e[r]);if(__getOwnPropSymbols)for(var r of __getOwnPropSymbols(e))__propIsEnum.call(e,r)&&__defNormalProp(t,r,e[r]);return t},__spreadProps=(t,e)=>__defProps(t,__getOwnPropDescs(e)),CustomerAPI=function(t){"use strict";const e="customer_changed",r="guest_data_saved";class n{static emit(t,e={},r=document){r||(r=document),gr()&&console.info(`[CF] Firing event ${t}`,e,r);const n=new CustomEvent(`cf:${t}`,{detail:e,bubbles:!0});r.dispatchEvent(n)}static on(t,e,r=document){const n=t=>{e(t.detail)};return r.addEventListener(`cf:${t}`,n),n}static off(t,e){document.removeEventListener(`cf:${t}`,e)}}var o="object"==typeof global&&global&&global.Object===Object&&global,i="object"==typeof self&&self&&self.Object===Object&&self,a=o||i||Function("return this")(),s=a.Symbol,u=Object.prototype,c=u.hasOwnProperty,l=u.toString,f=s?s.toStringTag:void 0;var h=Object.prototype.toString;var d=s?s.toStringTag:void 0;function p(t){return null==t?void 0===t?"[object Undefined]":"[object Null]":d&&d in Object(t)?function(t){var e=c.call(t,f),r=t[f];try{t[f]=void 0;var n=!0}catch(i){}var o=l.call(t);return n&&(e?t[f]=r:delete t[f]),o}(t):function(t){return h.call(t)}(t)}function m(t){return null!=t&&"object"==typeof t}function v(t){return"symbol"==typeof t||m(t)&&"[object Symbol]"==p(t)}var y=Array.isArray,b=s?s.prototype:void 0,g=b?b.toString:void 0;function _(t){if("string"==typeof t)return t;if(y(t))return function(t,e){for(var r=-1,n=null==t?0:t.length,o=Array(n);++r-1&&t%1==0&&t-1&&t%1==0&&t<=9007199254740991}function J(t){return null!=t&&Y(t.length)&&!j(t)}var X=Object.prototype;function Z(t){var e=t&&t.constructor;return t===("function"==typeof e&&e.prototype||X)}function Q(t){return m(t)&&"[object Arguments]"==p(t)}var tt=Object.prototype,et=tt.hasOwnProperty,rt=tt.propertyIsEnumerable,nt=Q(function(){return arguments}())?Q:function(t){return m(t)&&et.call(t,"callee")&&!rt.call(t,"callee")},ot=nt;var it="object"==typeof t&&t&&!t.nodeType&&t,at=it&&"object"==typeof module&&module&&!module.nodeType&&module,st=at&&at.exports===it?a.Buffer:void 0,ut=(st?st.isBuffer:void 0)||function(){return!1},ct={};function lt(t){return function(e){return t(e)}}ct["[object Float32Array]"]=ct["[object Float64Array]"]=ct["[object Int8Array]"]=ct["[object Int16Array]"]=ct["[object Int32Array]"]=ct["[object Uint8Array]"]=ct["[object Uint8ClampedArray]"]=ct["[object Uint16Array]"]=ct["[object Uint32Array]"]=!0,ct["[object Arguments]"]=ct["[object Array]"]=ct["[object ArrayBuffer]"]=ct["[object Boolean]"]=ct["[object DataView]"]=ct["[object Date]"]=ct["[object Error]"]=ct["[object Function]"]=ct["[object Map]"]=ct["[object Number]"]=ct["[object Object]"]=ct["[object RegExp]"]=ct["[object Set]"]=ct["[object String]"]=ct["[object WeakMap]"]=!1;var ft="object"==typeof t&&t&&!t.nodeType&&t,ht=ft&&"object"==typeof module&&module&&!module.nodeType&&module,dt=ht&&ht.exports===ft&&o.process,pt=function(){try{var t=ht&&ht.require&&ht.require("util").types;return t||dt&&dt.binding&&dt.binding("util")}catch(e){}}(),mt=pt&&pt.isTypedArray,vt=mt?lt(mt):function(t){return m(t)&&Y(t.length)&&!!ct[p(t)]},yt=Object.prototype.hasOwnProperty;function bt(t,e){var r=y(t),n=!r&&ot(t),o=!r&&!n&&ut(t),i=!r&&!n&&!o&&vt(t),a=r||n||o||i,s=a?function(t,e){for(var r=-1,n=Array(t);++r-1},It.prototype.set=function(t,e){var r=this.__data__,n=Ft(r,t);return n<0?(++this.size,r.push([t,e])):r[n][1]=e,this};var Mt=M(a,"Map");function Pt(t,e){var r,n,o=t.__data__;return("string"==(n=typeof(r=e))||"number"==n||"symbol"==n||"boolean"==n?"__proto__"!==r:null===r)?o["string"==typeof e?"string":"hash"]:o.map}function Nt(t){var e=-1,r=null==t?0:t.length;for(this.clear();++es))return!1;var c=i.get(t);if(c&&i.get(e))return c==e;var l=-1,f=!0,h=2&r?new He:void 0;for(i.set(t,e),i.set(e,t);++lo?0:o+e),(r=r>o?o:r)<0&&(r+=o),o=e>r?0:r-e>>>0,e>>>=0;for(var i=Array(o);++n=e?t:""+Array(e+1-n.length).join(r)+t},b={s:y,z:function(t){var e=-t.utcOffset(),r=Math.abs(e),n=Math.floor(r/60),o=r%60;return(e<=0?"+":"-")+y(n,2,"0")+":"+y(o,2,"0")},m:function t(e,r){if(e.date(){const e=this.data[t];/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/.test(e)&&(this.data[t]=lr(e))}))}emitReady(){n.emit("customer_ready")}addTag(...t){return this.data.tags||(this.data.tags=[]),t.forEach((t=>{var e;(null==(e=null==t?void 0:t.trim)?void 0:e.call(t))&&(this.removeTagFromTagsToRemove(t),this.getTagIndex(this.data.tags,t)>-1||(-1==this.getTagIndex(this.tagsToAdd,t)&&this.tagsToAdd.push(t),-1==this.getTagIndex(this.data.tags,t)&&(this.data.tags=[...this.data.tags,t])))})),n.emit("customer_tags_changed",{tags:this.data.tags}),this.tagsToAdd}removeTag(...t){return this.data.tags||(this.data.tags=[]),t.forEach((t=>{var e;if(!(null==(e=null==t?void 0:t.trim)?void 0:e.call(t)))return;if(this.removeTagFromTagsToAdd(t),-1==this.getTagIndex(this.data.tags,t))return;-1==this.getTagIndex(this.tagsToRemove,t)&&this.tagsToRemove.push(t);const r=this.getTagIndex(this.data.tags,t);r>-1&&this.data.tags.splice(r,1)})),n.emit("customer_tags_changed",{tags:this.data.tags}),this.tagsToRemove}removeTagFromTagsToRemove(t){const e=this.getTagIndex(this.tagsToRemove,t);return-1!=e&&this.tagsToRemove.splice(e,1),this.tagsToRemove}removeTagFromTagsToAdd(t){const e=this.getTagIndex(this.tagsToAdd,t);return-1!=e&&this.tagsToAdd.splice(e,1),this.tagsToAdd}getTagIndex(t,e){if(!t)return-1;if(!(t instanceof Array)){if("string"!=typeof t)return console.warn("[Customer Fields] customer.getTagIndex not given an array or string, instead got:",t),-1;t=t.split(",").map((t=>t.trim())).filter(Boolean)}return t.map((t=>t.toLowerCase())).indexOf(e.toLowerCase())}requestHeaders(t){const e=__spreadValues({"X-Shopify-Shop-Domain":this.shopDomain,"X-CF-Embed-Version":dr},t);return this.token&&(e["Auth-Token"]=this.token),e}getColumnType(t){return this.columns.find((e=>e.key==t)).dataType}getColumnByKey(t){return this.columns.find((e=>e.key==t))}hasColumn(t){return!!this.columns.find((e=>e.key==t))}async emit(t,e,r=new Date){if(!this.id)return;const n={event:{name:t,happened_at:r.toISOString(),details:e}};let o;const i=t=>{console.error("[CF.emit] Failed to emit event",n),console.error(t)};try{o=await fetch(`${this.baseApiUrl}/customers/${this.id}/events.json`,{method:"post",headers:this.requestHeaders({"Content-Type":"application/json"}),body:JSON.stringify(n)})}catch(a){return i(a),!1}return!!o.ok||(i(o),!1)}update(t,e={}){return this.set(t),this.save(__spreadProps(__spreadValues({},e),{data:t}))}prepareCustomerDataPayload(t,e=br(t),r,n){var o;const i={};return e.forEach((e=>{let o=Yt(t,e);const a=this.getColumnByKey(n?`${n}.${e}`:e);hr.keyIsProperlyFormatted(e)?(cr.exports.isDayjs(o)&&(o="date"==(null==a?void 0:a.dataType)?o.format("YYYY-MM-DD"):o.toISOString()),"group_list"===(null==a?void 0:a.dataType)&&o instanceof Array&&(o=o.map((t=>this.prepareCustomerDataPayload(t,br(t),r,e)))),sr(i,e,o)):gr()&&console.warn("[Customer Fields] Encountered malformed column key whilst preparing the customer data payload:",e,"This key will be ignored.")})),i.default_address&&(i.default_address=__spreadValues(__spreadValues({},this.data.default_address),i.default_address)),r?(null==(o=i.addresses)||o.forEach((t=>{delete t.id})),i.default_address&&delete i.default_address.id):(delete i.password,delete i.password_confirmation),i.locale=this.locale,this.setCountryAndProvinceCodes(i),i}storeGuestData(t=this.data){const e=this.getGuestData(),o=__spreadValues(__spreadValues({},e),t);["password","password_confirmation"].forEach((t=>delete o[t])),localStorage.setItem(pr.GUEST_DATA,JSON.stringify(o)),this.data=__spreadValues(__spreadValues({},this.data),t),n.emit(r,{guestData:ze(o)})}deleteKeysFromGuestData(t){const e=this.getGuestData();t.forEach((t=>ur(e,t))),localStorage.setItem(pr.GUEST_DATA,JSON.stringify(e))}async fetchSessionToken(){var t;let e=null;const r=null==(t=null==window?void 0:window.grecaptcha)?void 0:t.enterprise;if(!this.captchaEnabled)return null;if(!r)throw new Error("\n [Customer Fields] Google reCaptcha was incorrectly installed on your theme.\n Please reach out to Helium support at: support@heliumdev.com\n ");if(!this.captchaSiteKey)throw new Error("[Customer Fields] Missing captcha site key. Please reach out to Helium support at: support@heliumdev.com");let n;try{n=await r.execute(this.captchaSiteKey,{action:"SUBMIT"})}catch(o){throw console.error(o),new Error("\n [Customer Fields] Failed to generate a Google reCaptcha token.\n Please make sure you have recaptcha disabled in your online store settings.\n If this problem still occurs, please reach out to Helium support at: support@heliumdev.com\n ")}try{const t=await fetch("https://cfcs.heliumdev.workers.dev/session_tokens",{method:"POST",body:JSON.stringify({captcha_token:n,site_key:this.captchaSiteKey})});return e=await t.text(),e}catch(o){throw console.error(o),new Error("[Customer Fields] Failed to fetch a session token from the CF Captcha Service. Please reach out to Helium support as soon as possible at: support@heliumdev.com")}}async handleSaveError(t,e){if(402==t.status)return void(window.location.href=window.location.pathname+"?view=orig");let r,n=null;try{n=await t.json()}catch(o){r={server:["Could not save form, please try again later"]},console.error("[CF] Errors data is either not included in response, or not in JSON format.",t)}if(401==t.status){if(await this.refreshToken(),this.token)return await this.save(e)}else if(null==n?void 0:n.error){const t=n.error.code;switch(t){case"INVALID_SESSION_TOKEN":case"INSUFFICIENT_CAPTCHA_SCORE":case"SHOP_NOT_PROVIDED":r={captcha:[t]};break;default:r={unknown:[t]}}}else(null==n?void 0:n.errors)&&(r=null==n?void 0:n.errors);return r}async save(t={}){const{data:e=this.data,formId:r,recaptchaToken:o,redirect:i,redirectUrl:a,login:s,submitAsNewCustomer:u=!1,saveColumns:c}=t,l=!u&&null!=this.id,f={customer:{fields:this.prepareCustomerDataPayload(ze(e),c,!l),add_tags:this.tagsToAdd,remove_tags:this.tagsToRemove}};r&&(f.customer.form_id=r),o&&(f["g-recaptcha-response"]=o);const h=await this.fetchSessionToken();n.emit("customer_saving",{customer:this});let d="/customers";l&&(d+=`/${this.id}`);const p=`${this.baseApiUrl}${d}.json`,m=await fetch(p,{method:l?"put":"post",headers:this.requestHeaders(__spreadValues({"Content-Type":"application/json"},h&&{"X-CF-Session-Token":h})),body:JSON.stringify(f)});if(!m.ok){const e=await this.handleSaveError(m,t);return n.emit("customer_save_failed",{errors:e}),e}{let t;try{t=await m.json()}catch(v){return console.error(`[Customer Fields] Encountered malformed response from ${p}`),void console.error(v)}await this.handleCustomerSaved({submittedData:e,savedCustomer:t.customer,conditions:t.conditions,login:s,redirectUrl:i?a:void 0})}}saveAsGuest(t={}){if(this.isLoggedIn)return void console.error("[Customer Fields] Cannot saveAsGuest if the customer is logged in. Use the CF.customer.save method instead, or store the data in localStorage with your own solution.");const{data:e=this.data,redirect:r,redirectUrl:n}=t;this.storeGuestData(e),this.setData();0!=r&&!this.preventRedirect&&this.redirect(n)}detectInconsistenciesBetweenSubmittedAndSavedData(t,e,r){const n=["id","password","password_confirmation"];let o;t.forEach((t=>{if(n.includes(t))return;const i=Yt(e,t),a=Yt(r,t);ir(i,a)||(console.warn(`[Customer Fields] Attempted to submit data with column key "${t}", but the database does not reflect the submitted value.`),console.warn("Submitted:",i,"Received:",a),o=!0)})),o&&console.info("[Customer Fields] If the received value is unexpectedly undefined, ensure you have properly configured a data column with the corresponding key.",`Manage your data columns by visiting ${window.CF.baseApiUrl}/data_columns`)}async handleCustomerSaved({submittedData:t,savedCustomer:e,conditions:r,login:o,redirectUrl:i}){const a=br(t);gr()&&this.detectInconsistenciesBetweenSubmittedAndSavedData(a,t,e),this.deleteKeysFromGuestData(a),this.deleteKeysFromUnsavedChanges(a),this.savedData=e,this.setData(),this.conditions=r;if(!!t.password&&!this.conditions&&(this.id=this.data.shopify_id||this.data.id,this.tagsToAdd=[],this.tagsToRemove=[]),n.emit("customer_saved",{customer:this,conditions:r}),!this.conditions){const{email:e,password:r}=t,n=e&&r;o&&null!=this.id&&n&&!this.preventLogin?await this.login(e,r,i):i&&!this.preventRedirect&&this.redirect(i)}}set(t,e){if("string"==typeof t){const r=t;this.unsavedChanges=sr(this.unsavedChanges,r,e),this.data=sr(this.data,r,e)}else for(const r in t){const e=t[r];this.unsavedChanges=sr(this.unsavedChanges,r,e),this.data=sr(this.data,r,e)}return this.emitChange("string"==typeof t?{[t]:e}:t),this.unsavedChanges}setCountryAndProvinceCodes(t){var e,r,n,o,i;const a=Yt(t,"default_address.country"),s=Yt(t,"default_address.province");if(!a)return null==(e=t.default_address)||delete e.country_code,void(null==(r=t.default_address)||delete r.province_code);const u=null==(n=this.countries)?void 0:n.find((t=>t.name==a));if(!u)return;const c=u.code,l=null==(i=null==(o=u.provinces)?void 0:o.find((t=>t.name==s)))?void 0:i.code;Yt(t,"default_address.country_code")!==c&&sr(t,"default_address.country_code",c),Yt(t,"default_address.province_code")!==l&&sr(t,"default_address.province_code",l)}emitChange(t){n.emit(e,{changed:t,customer:this})}get(...t){if(1==t.length)return t[0]instanceof Array?this.get(...t[0]):Yt(this.data,t[0]);{const e={};return t.forEach((t=>{"string"==typeof t&&(e[t]=Yt(this.data,t))})),e}}getSavedData(...t){if(1==t.length)return t[0]instanceof Array?this.get(...t[0]):Yt(this.savedData,t[0]);{const e={};return t.forEach((t=>{"string"==typeof t&&(e[t]=Yt(this.savedData,t))})),e}}deleteKeysFromUnsavedChanges(t){t.forEach((t=>ur(this.unsavedChanges,t)))}async login(t,e,r){const n=[`customer[email]=${encodeURIComponent(t)}`,`customer[password]=${encodeURIComponent(e)}`,"form_type=customer_login"],o=await async function(t="customer_login"){var e,r;if(!(null==(r=null==(e=window.Shopify)?void 0:e.recaptchaV3)?void 0:r.siteKey))return gr()&&console.warn("Cannot generate Shopify recaptcha token, missing global recaptchaV3 or site key"),null;try{return await window.grecaptcha.execute(window.Shopify.recaptchaV3.siteKey,{action:t})}catch(n){console.error("Failed to recaptcha token using Shopify functions",n)}return null}();o&&n.push(`recaptcha-v3-token=${o}`);const i=await fetch("/account/login",{method:"post",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:n.join("&")});if(i.redirected){if("/challenge"==new URL(i.url).pathname)return console.warn("[CF] Must redirect to challenge"),void(window.location.href=i.url)}i.ok?r?this.redirect(r):await this.refreshToken():console.error("[CF] Failed to login user",this,i)}redirect(t){t&&(this.localeRootPath&&0==t.indexOf("/")&&(t=`${this.localeRootPath}${t}`),window.location.href=t)}async refreshToken(){var t;if(!this.id)return void console.error("[CF] Cannot refresh token of customer that is not logged in.");if(this.tokenRefreshAttempts>=this.maxTokenRefreshAttempts)throw new Error(`[CF] Could not refresh token after ${this.maxTokenRefreshAttempts} attempts.`);this.tokenRefreshAttempts++;const e=await(await fetch(`${this.baseApiUrl}/customers/${this.id}/token.json`,{method:"PUT",headers:this.requestHeaders()})).json();if(!!(null==e?void 0:e.access_token)){const e=`${this.proxyPath}/customer.json`;let n;try{n=await(await fetch(e)).json()}catch(r){return console.warn(`[CF] Unable to fetch ${e}`),void console.info("Do you have ngrok started? Is your proxy path set correctly?")}(null==(t=null==n?void 0:n.customer)?void 0:t.access_token)?(this.token=n.customer.access_token,this.tokenRefreshAttempts=0):console.error("Failed to fetch token from proxy endpoint",n)}else console.error("Could not make token",e)}},yr=()=>{const t=document.querySelector("script[data-cf-init]"),e=JSON.parse(t.innerHTML),r=function(t){const e=document.createElement("span");return e.innerHTML=t,e.innerText||t}(JSON.stringify(e));return JSON.parse(r)},br=t=>Object.keys(t).filter((e=>t[e]instanceof Object&&!(t[e]instanceof Array))).map((e=>br(t[e]).map((t=>`${e}.${t}`)))).reduce(((t,e)=>t.concat(e)),Object.keys(t)),gr=()=>{var t;return(!("process"in window)||"test"!==(null==(t=null==process?void 0:process.env)?void 0:t.NODE_ENV))&&("true"==localStorage.getItem(pr.DEBUG_MODE)||"false"!=localStorage.getItem(pr.DEBUG_MODE)&&"localhost"===window.location.hostname)};var _r={exports:{}};!function(t,e){t.exports=function(){var t=["prefix","templateDelimiters","rootInterface","preloadData","handler"],e=["binders","formatters","adapters"],r=0,n=1,o=0,i=1,a=/^'.*'$|^".*"$/;function s(t){var e=r,o=t;return a.test(t)?o=t.slice(1,-1):"true"===t?o=!0:"false"===t?o=!1:"null"===t?o=null:"undefined"===t?o=void 0:isNaN(t)?e=n:o=Number(t),{type:e,value:o}}function u(t,e){for(var r,n=t.length,a=0,s=0,u=e[0],c=e[1];s0&&s-1?Object.keys(o).forEach((function(t){r[n][t]=o[t]})):r[n]=o}))}};function d(t){return"object"==typeof t&&null!==t}function p(t){throw new Error("[Observer] "+t)}var m=function(){function t(t,e,r){this.keypath=e,this.callback=r,this.objectPath=[],this.parse(),this.obj=this.getRootObject(t),d(this.target=this.realize())&&this.set(!0,this.key,this.target,this.callback)}t.updateOptions=function(t){c=t.adapters,l=Object.keys(c),f=t.rootInterface},t.tokenize=function(t,e){var r,n,o=[],i={i:e,path:""};for(r=0;r-1&&o.splice(i,1),o.length||delete n.pointers[e],this.cleanupWeakReference(n,t.__rv)}}}},observe:function(t,e,r){var n,o=this,i=this.weakReference(t).callbacks;if(!i[e]){i[e]=[];var a=Object.getOwnPropertyDescriptor(t,e);a&&(a.get||a.set||!a.configurable)||(n=t[e],Object.defineProperty(t,e,{enumerable:!0,get:function(){return n},set:function(r){if(r!==n){o.unobserveArray(n,t.__rv,e),n=r;var i=o.weakmap[t.__rv];if(i){var a=i.callbacks[e];a&&a.forEach((function(t){t.sync()})),o.observeArray(r,t.__rv,e)}}}}))}-1===i[e].indexOf(r)&&i[e].push(r),this.observeArray(t[e],t.__rv,e)},unobserve:function(t,e,r){var n=this.weakmap[t.__rv];if(n){var o=n.callbacks[e];if(o){var i=o.indexOf(r);i>-1&&(o.splice(i,1),o.length||(delete n.callbacks[e],this.unobserveArray(t[e],t.__rv,e))),this.cleanupWeakReference(n,t.__rv)}}},get:function(t,e){return t[e]},set:function(t,e,r){t[e]=r}},T=function(t){return null!=t?t.toString():void 0},C=function(t,e){for(var r=0;re.length&&C(this.iterated.length-e.length,(function(){var t=r.iterated.pop();t.unbind(),r.marker.parentNode.removeChild(t.els[0])})),"OPTION"===t.nodeName&&this.view.bindings.forEach((function(t){t.el===r.marker.parentNode&&"value"===t.type&&t.sync()}))},update:function(t){var e=this,r={};Object.keys(t).forEach((function(n){n!==e.arg&&(r[n]=t[n])})),this.iterated.forEach((function(t){t.update(r)}))}},"class-*":function(t,e){var r=" "+t.className+" ";!e==r.indexOf(" "+this.arg+" ")>-1&&(t.className=e?t.className+" "+this.arg:r.replace(" "+this.arg+" "," ").trim())},text:function(t,e){t.textContent=null!=e?e:""},html:function(t,e){t.innerHTML=null!=e?e:""},show:function(t,e){t.style.display=e?"":"none"},hide:function(t,e){t.style.display=e?"none":""},enabled:function(t,e){t.disabled=!e},disabled:function(t,e){t.disabled=!!e},checked:{publishes:!0,priority:2e3,bind:function(t){var e=this;this.callback||(this.callback=function(){e.publish()}),t.addEventListener("change",this.callback)},unbind:function(t){t.removeEventListener("change",this.callback)},routine:function(t,e){"radio"===t.type?t.checked=T(t.value)===T(e):t.checked=!!e}},value:{publishes:!0,priority:3e3,bind:function(t){if(this.isRadio="INPUT"===t.tagName&&"radio"===t.type,!this.isRadio){this.event=t.getAttribute("event-name")||("SELECT"===t.tagName?"change":"input");var e=this;this.callback||(this.callback=function(){e.publish()}),t.addEventListener(this.event,this.callback)}},unbind:function(t){this.isRadio||t.removeEventListener(this.event,this.callback)},routine:function(t,e){if(this.isRadio)t.setAttribute("value",e);else if("select-multiple"===t.type){if(e instanceof Array)for(var r=0;r-1}}else T(e)!==T(t.value)&&(t.value=null!=e?e:"")}},if:{block:!0,priority:4e3,bind:function(t){this.marker?!1===this.bound&&this.nested&&this.nested.bind():(this.marker=document.createComment(" tinybind: "+this.type+" "+this.keypath+" "),this.attached=!1,t.parentNode.insertBefore(this.marker,t),t.parentNode.removeChild(t)),this.bound=!0},unbind:function(){this.nested&&(this.nested.unbind(),this.bound=!1)},routine:function(t,e){!!e!==this.attached&&(e?(this.nested||(this.nested=new A(t,this.view.models,this.view.options),this.nested.bind()),this.marker.parentNode.insertBefore(t,this.marker.nextSibling),this.attached=!0):(t.parentNode.removeChild(t),this.attached=!1))},update:function(t){this.nested&&this.nested.update(t)}}},F={watch:function(t){return t},not:function(t){return!t},negate:function(t){return!t}};function x(t,e){for(var r=0;r0})),m.updateOptions(i);var a=new A(r,n,i);return a.bind(),a},h}()}(_r);var wr=_r.exports;var jr=Object.defineProperty,kr=Object.getOwnPropertyDescriptor;const Or=class{bind(t){this.$form=t,this.formId=this.$form.getAttribute("data-cf-form-id"),this.formId||console.warn("[Customer Fields] When using the rv-cf-custom-form binder, please add the data-cf-form-id attribute and specify a valid form ID as the value."),this.prefillFields(),this.$form.addEventListener("submit",this.handleSubmit)}prefillFields(){Array.from(this.$form.querySelectorAll("[name]")).forEach((t=>{const e=hr.transformFieldNameToColumnKey(t.getAttribute("name"));if(!e)return;const r=Yt(window.CF.tinybind.state.customer,e);if(null!=r)switch(t.tagName.toLowerCase()){case"input":const e=t;switch(e.type){case"radio":e.checked=e.value==r;break;case"checkbox":e.checked=r instanceof Array?r.includes(e.value):!!r;break;default:e.value=r}break;case"select":const n=t,o=Array.from(n.querySelectorAll("option"));n.value=r,o.forEach((t=>{t.value==r&&(t.selected=!0)}))}}))}convertErrorsToStableKeys(t){for(const e in t){const r=t[e];r.forEach(((t,e)=>{const n=Or.STABLE_SERVER_ERROR_KEYS[t];n&&(r[e]=n)}))}}getFormData(){const t=[];return Array.from(this.$form.querySelectorAll("[name]")).forEach((e=>{const r=e.name,n=e.value;r&&t.push({name:r,value:n})})),t}async handleSubmit(t){var e;t.preventDefault();const r=this.getFormData(),n={data:{},redirectUrl:"/account",redirect:!0,login:!0,formId:this.formId},o=["form_type","utf8"];let i,a=!1;r.forEach((t=>{const{name:e,value:r}=t;if(!o.includes(e))switch(e){case"return_url":case"redirect_url":case"return_to":n.redirect=!0,n.redirectUrl=r;break;case"redirect":n.redirect="false"!=r;break;case"login":n.login="false"!=r;break;case"guest":a=!0;break;default:const t=hr.transformFieldNameToColumnKey(e);if(!t||t!=hr.formatColumnKey(t)){console.warn("[Customer Fields] Encountered field with an improperly formatted name attribute:",e,"The field will not be submitted. Please ensure the name attribute is in the correct format.","View our docs at https://developers.customerfields.com");break}sr(n.data,t,r)}})),a?vr.saveAsGuest(n):i=await vr.save(n),vr.conditions||i?(i&&(this.convertErrorsToStableKeys(i),Object.keys(window.CF.tinybind.state.errors).forEach((t=>{window.CF.tinybind.state.errors[t]=void 0})),Object.assign(window.CF.tinybind.state.errors,i)),"must be verified"==(null==(e=vr.conditions)?void 0:e.email)&&(window.CF.tinybind.state.errors.email=[...(null==i?void 0:i.email)||[],"verify"]),window.CF.tinybind.state.has_error=!0):(n.redirect&&(window.CF.tinybind.state.redirecting=!0),window.CF.tinybind.state.has_error=!1,window.CF.tinybind.state.errors={})}};let Ar=Or;Ar.STABLE_SERVER_ERROR_KEYS={"must be verified":"verify","has already been taken":"taken","is invalid":"invalid","is not valid":"invalid","is not a valid country":"invalid","is too short (minimum is 5 characters)":"too_short","must match the provided password.":"must_match_password"},((t,e,r,n)=>{for(var o,i=n>1?void 0:n?kr(e,r):e,a=t.length-1;a>=0;a--)(o=t[a])&&(i=(n?o(e,r,i):o(i))||i);n&&i&&jr(e,r,i)})([function(t,e,r){return{get(){const t=r.value.bind(this);return Object.defineProperty(this,e,{value:t}),t}}}],Ar.prototype,"handleSubmit",1),wr.binders.width=function(t,e){t.style.width=e},wr.binders.height=function(t,e){t.style.height=e},wr.binders.unless={block:!0,priority:4e3,bind(t){this.marker?!1===this.bound&&this.nested&&this.nested.bind():(this.marker=document.createComment(" tinybind: "+this.type+" "+this.keypath+" "),this.attached=!1,t.parentNode.insertBefore(this.marker,t),t.parentNode.removeChild(t)),this.bound=!0},unbind(){this.nested&&(this.nested.unbind(),this.bound=!1)},routine(t,e){wr.binders.if.routine.call(this,t,!e)},update(t){this.nested&&this.nested.update(t)}},wr.binders["cf-custom-form"]=t=>{(new Ar).bind(t)};var Sr={exports:{}};!function(t,e){t.exports=function(t,e,r){t=t||{};var n=e.prototype,o={future:"in %s",past:"%s ago",s:"a few seconds",m:"a minute",mm:"%d minutes",h:"an hour",hh:"%d hours",d:"a day",dd:"%d days",M:"a month",MM:"%d months",y:"a year",yy:"%d years"};function i(t,e,r,o){return n.fromToBase(t,e,r,o)}r.en.relativeTime=o,n.fromToBase=function(e,n,i,a,s){for(var u,c,l,f=i.$locale().relativeTime||o,h=t.thresholds||[{l:"s",r:44,d:"second"},{l:"m",r:89},{l:"mm",r:44,d:"minute"},{l:"h",r:89},{l:"hh",r:21,d:"hour"},{l:"d",r:35},{l:"dd",r:25,d:"day"},{l:"M",r:45},{l:"MM",r:10,d:"month"},{l:"y",r:17},{l:"yy",d:"year"}],d=h.length,p=0;p0,v<=m.r||!m.r){v<=1&&p>0&&(m=h[p-1]);var y=f[m.l];s&&(v=s(""+v)),c="string"==typeof y?y.replace("%d",v):y(v,n,m.l,l);break}}if(n)return c;var b=l?f.future:f.past;return"function"==typeof b?b(c):b.replace("%s",c)},n.to=function(t,e){return i(t,e,this,!0)},n.from=function(t,e){return i(t,e,this)};var a=function(t){return t.$u?r.utc():r()};n.toNow=function(t){return this.to(a(this),t)},n.fromNow=function(t){return this.from(a(this),t)}}}(Sr);var Er=Sr.exports;lr.extend(Er),wr.formatters.log=function(t){return console.log(t)},wr.formatters.default=function(t,e){return wr.formatters.isEmpty(t)?e:t},wr.formatters.add=function(t,e){return t+e},wr.formatters.sub=function(t,e){return t-e},wr.formatters.map=function(t,e,r){let n=Array.prototype.slice.call(arguments);return n.splice(1,2),e[r].apply(e,n)},wr.formatters.isBoolean=function(t){return"boolean"==typeof t},wr.formatters.isNumeric=function(t){return!isNaN(t)},wr.formatters.isNaN=function(t){return!!wr.formatters.isArray(t)||isNaN(t)},wr.formatters.isInteger=function(t){return t===+t&&t===(0|t)},wr.formatters.isFloat=function(t){return t!==1/0&&t===+t&&t!==(0|t)},wr.formatters.isNumber=function(t){return wr.formatters.isFloat(t)||wr.formatters.isInteger(t)},wr.formatters.isObject=function(t){return wr.formatters.toBoolean(t)&&"object"==typeof t&&!wr.formatters.isArray(t)},wr.formatters.isFunction=function(t){return"function"==typeof t},wr.formatters.isArray=function(t){return wr.formatters.isFunction(Array.isArray)?Array.isArray(t):t instanceof Array},wr.formatters.isString=function(t){return"string"==typeof t||t instanceof String},wr.formatters.isInfinity=function(t){return t===1/0},wr.formatters.toBoolean=function(t){return!!t},wr.formatters.toInteger=function(t){let e=parseInt(1*t+"",10);return isNaN(e)?0:e},wr.formatters.toFloat=function(t){let e=parseFloat(1*t+"");return isNaN(e)?0:e},wr.formatters.toDecimal=function(t){let e=wr.formatters.toInteger(1*t),r=wr.formatters.toFloat(t);return e==r?e:r},wr.formatters.toArray=function(t){return wr.formatters.isArray(t)?t:wr.formatters.isObject(t)?wr.formatters.values(t):[t]},wr.formatters.toString=function(t){return t?t.toString():""},wr.formatters.sum=function(t,e){return 1*t+1*e},wr.formatters.substract=function(t,e){return 1*t-1*e},wr.formatters.multiply=function(t,e){return 1*t*(1*e)},wr.formatters.divide=function(t,e){return 1*t/(1*e)},wr.formatters.min=function(){return Math.min.apply(Math,arguments)},wr.formatters.max=function(){return Math.max.apply(Math,arguments)},wr.formatters.isEqual=function(t,e){return t===e},wr.formatters.isNotEqual=function(t,e){return t!==e},wr.formatters.isLess=function(t,e){return 1*t<1*e},wr.formatters.isGreater=function(t,e){return 1*t>1*e},wr.formatters.isLessEqual=function(t,e){return 1*t<=1*e},wr.formatters.isGreaterEqual=function(t,e){return 1*t>=1*e},wr.formatters.or=function(){for(let t=0;t{var t;return __spreadValues({},(null==(t=window.CF.customer)?void 0:t.data)||{})},Cr={customer:{},customer_logged_in:!1,customer_saving:!1,customer_saved:!1,has_error:!1,redirecting:!1,errors:{}};n.on("customer_changed",(()=>{Cr.customer=Tr()})),n.on("guest_data_saved",(()=>{Cr.customer=Tr()})),n.on("customer_saving",(()=>{Cr.customer_saving=!0,Cr.customer_saved=!1})),n.on("customer_save_failed",(()=>{Cr.customer_saving=!1})),n.on("customer_saved",(()=>{Cr.customer_saving=!1,Cr.customer_saved=!0,setTimeout((()=>{Cr.customer_saved=!1}),3e3)}));const $r=()=>{Cr.customer=Tr(),Cr.customer_logged_in=vr.isLoggedIn;const t=document.querySelectorAll("[data-cf-view]");for(let e=0;e{const t=yr();(t=>{window.CF=__spreadProps(__spreadValues({},window.CF),{version:dr,domain:t.domain,baseApiUrl:t.baseApiUrl,theme:t.theme,customer:vr,on:n.on,off:n.off})})(t),window.CF.tinybind={state:Cr,binders:wr.binders,formatters:wr.formatters},await vr.init(__spreadProps(__spreadValues({},t),{columns:[]})),$r()},Fr=t=>{"complete"===document.readyState||"loading"!==document.readyState&&!document.documentElement.doScroll?t():document.addEventListener("DOMContentLoaded",t)};return Fr(Dr),t.domReady=Fr,t.getCustomerDataForTinybindModel=Tr,t.initCustomerAndBindCfViews=Dr,Object.defineProperty(t,"__esModule",{value:!0}),t[Symbol.toStringTag]="Module",t}({});