import{Xt as e}from"./630ba094.L_X-5TXi.js";import{Ed as r,ld as t,td as o,xO as n}from"./6ec9a0fa.rdcQt2v8.js";import{t as s}from"./bace9a08.CgQzfzYE.js";var i=/\.(shop\.dev|shop\.test|tunnel\.shopifycloud\.tech)$/,a=/-prod\.tunnel\.shopifycloud\.tech$/,u=[75664294112,62390304886,85847245104,86752461117,58033635374,66379940012,70551503014,70463455488,93853155640,80263414008,88037425452,60422193237,69049680021,70705741859,55430348880,94032855349,62738464862,63214747744,76071207125,66434269381,77807124665,90116096309,71258177703,94680613178,69211193497,96923615535,90197033254,66074640455,90855080255,103560118602,67244884158,77514178781,63675957321,90790854947,98242363682,71097516111,78492631257,78868775128,103209074848,59548663926,72175354043,103802667345,99821027670,99301720350,101844517045,75261149367,67837263935,100525212032,100583276916,105223749972,107281547596,75114709085,78967308335,73175138466,69293637654];function c({browser:e,os:r},t){return{...l(t),os:r,browser:e.telemetryName,entrypoint:o}}function l(e){const r=function(){const e=(()=>{const e="undefined"==typeof window?void 0:window.location.href;if(!e)return;let r;try{r="string"==typeof e?new URL(e).pathname:e.pathname}catch{return}const t=r.match(/checkout\/([^/]+)\/([a-z]{2,3})/)?.[1];if(!t)return;const o=parseInt(t,10);return isNaN(o)?void 0:o})();return e?e&&u.includes(e)?String(e):"other":void 0}();return{flow_version:t()?"iframe":"popup",...r&&{shopId:r},debugMode:!(!/debug=yes/.test(window.location.href)&&!/debug=true/.test(window.location.href)&&!/debug=1/.test(window.location.href)&&(/debug=no/.test(window.location.href)||/debug=false/.test(window.location.href)||/debug=0/.test(window.location.href)||!function(){if("undefined"==typeof window)return!1;const e=window.location.host;return i.test(e)&&!a.test(e)}())),...e&&{client_source:e}}}var d={shippingAddressError:"$.cart.deliveryGroups[0].deliveryAddress",discountCodeError:void 0,generalError:"$.cart"};function p({breadcrumbPrefix:r,isApplePay:t=!1}){const{observability:o,source:s,i18n:i,checkout:{identity:a,validation:u},shopPay:c}=n(),l="simulated"===s.type,d="shopPay"===a.current.value&&!c?.user.phoneNumber.value?.trim(),p=e(()=>{const e=u.missingFields.phone.isValid.value;if(!e){const e=u.missingFields.phone.input.value;u.missingFields.phone.error.value=e?i.translate("mobile_phone_number.mobile_phone_invalid"):i.translate("field_errors.shop_pay_mobile_phone_blank")}return e},[u,i]);return e(()=>l?(o.leaveErrorBreadcrumb(`${r} - simulated`),!1):d&&t&&!p()?(o.leaveErrorBreadcrumb(`${r} - requires phone`),!1):(o.leaveErrorBreadcrumb(r),!0),[r,o,l,d,t,p])}function h(){const{userEvents:t,source:o,checkout:i,shop:a}=n(),u=function(){const{observability:r,source:t,checkout:{negotiator:o}}=n(),i="shopPayExternal"===t.type,a=s();return e(()=>{if(!i)return;let e=!1,t=!1;for(const r of o.validationErrors.value)r.target===d.generalError?e=!0:r.target===d.shippingAddressError&&(t=!0);(e||t)&&r.counter({name:"shop_pay_external_checkout_with_address_errors",value:1,attributes:{hasGeneralError:e,hasDeliveryAddressError:t,...c(a.userAgentDetails,a.clientSource)}})},[i,a.clientSource,a.userAgentDetails,r,o.validationErrors])}();return e(()=>{u(),t.monorailEvent({schemaId:"shopify_pay_payment_page_pay_now/2.1",payload:{...r(o,i,a),clientTimestampMs:Date.now()}})},[t,o,i,a,u])}function f(e){return Promise.resolve().then(()=>e())}Object.values(d).filter(Boolean);export{c as i,h as n,p as r,f as t};