UNPKG

@shopify/hydrogen-react

Version:

React components, hooks, and utilities for creating custom Shopify storefronts

312 lines (299 loc) • 72.4 kB
(function(p,l){typeof exports=="object"&&typeof module<"u"?l(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],l):(p=typeof globalThis<"u"?globalThis:p||self,l(p.hydrogenreact={},p.React))})(this,(function(p,l){"use strict";function zt(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const n in e)if(n!=="default"){const r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:()=>e[n]})}}return t.default=e,Object.freeze(t)}const M=zt(l);/*! ***************************************************************************** Copyright (c) Microsoft Corporation. Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ***************************************************************************** */function Ge(e,t){var n=typeof Symbol=="function"&&e[Symbol.iterator];if(!n)return e;var r,a,i=n.call(e),o=[];try{for(;(t===void 0||t-- >0)&&!(r=i.next()).done;)o.push(r.value)}catch(s){a={error:s}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(a)throw a.error}}return o}var z;(function(e){e[e.NotStarted=0]="NotStarted",e[e.Running=1]="Running",e[e.Stopped=2]="Stopped"})(z||(z={}));var Ze={type:"xstate.init"};function Pe(e){return e===void 0?[]:[].concat(e)}function ne(e){return{type:"xstate.assign",assignment:e}}function Ke(e,t){return typeof(e=typeof e=="string"&&t&&t[e]?t[e]:e)=="string"?{type:e}:typeof e=="function"?{type:e.name,exec:e}:e}function Ce(e){return function(t){return e===t}}function Qe(e){return typeof e=="string"?{type:e}:e}function Je(e,t){return{value:e,context:t,actions:[],changed:!1,matches:Ce(e)}}function Xe(e,t,n){var r=t,a=!1;return[e.filter((function(i){if(i.type==="xstate.assign"){a=!0;var o=Object.assign({},r);return typeof i.assignment=="function"?o=i.assignment(r,n):Object.keys(i.assignment).forEach((function(s){o[s]=typeof i.assignment[s]=="function"?i.assignment[s](r,n):i.assignment[s]})),r=o,!1}return!0})),r,a]}function ze(e,t){t===void 0&&(t={});var n=Ge(Xe(Pe(e.states[e.initial].entry).map((function(o){return Ke(o,t.actions)})),e.context,Ze),2),r=n[0],a=n[1],i={config:e,_options:t,initialState:{value:e.initial,actions:r,context:a,matches:Ce(e.initial)},transition:function(o,s){var u,d,g=typeof o=="string"?{value:o,context:e.context}:o,f=g.value,h=g.context,E=Qe(s),c=e.states[f];if(c.on){var T=Pe(c.on[E.type]);try{for(var C=(function(D){var se=typeof Symbol=="function"&&Symbol.iterator,pe=se&&D[se],Ee=0;if(pe)return pe.call(D);if(D&&typeof D.length=="number")return{next:function(){return D&&Ee>=D.length&&(D=void 0),{value:D&&D[Ee++],done:!D}}};throw new TypeError(se?"Object is not iterable.":"Symbol.iterator is not defined.")})(T),A=C.next();!A.done;A=C.next()){var v=A.value;if(v===void 0)return Je(f,h);var w=typeof v=="string"?{target:v}:v,R=w.target,y=w.actions,m=y===void 0?[]:y,_=w.cond,P=_===void 0?function(){return!0}:_,O=R===void 0,b=R??f,I=e.states[b];if(P(h,E)){var q=Ge(Xe((O?Pe(m):[].concat(c.exit,m,I.entry).filter((function(D){return D}))).map((function(D){return Ke(D,i._options.actions)})),h,E),3),V=q[0],H=q[1],X=q[2],me=R??f;return{value:me,context:H,actions:V,changed:R!==f||V.length>0||X,matches:Ce(me)}}}}catch(D){u={error:D}}finally{try{A&&!A.done&&(d=C.return)&&d.call(C)}finally{if(u)throw u.error}}}return Je(f,h)}};return i}var et=function(e,t){return e.actions.forEach((function(n){var r=n.exec;return r&&r(e.context,t)}))};function en(e){var t=e.initialState,n=z.NotStarted,r=new Set,a={_machine:e,send:function(i){n===z.Running&&(t=e.transition(t,i),et(t,Qe(i)),r.forEach((function(o){return o(t)})))},subscribe:function(i){return r.add(i),i(t),{unsubscribe:function(){return r.delete(i)}}},start:function(i){if(i){var o=typeof i=="object"?i:{context:e.config.context,value:i};t={value:o.value,actions:[],context:o.context,matches:Ce(o.value)}}else t=e.initialState;return n=z.Running,et(t,Ze),a},stop:function(){return n=z.Stopped,r.clear(),a},get state(){return t},get status(){return n}};return a}const tn=typeof window<"u"?l.useLayoutEffect:l.useEffect;function nn(e){const t=l.useRef();return t.current||(t.current={v:e()}),t.current.v}function rn(e){let t;return e.subscribe(n=>t=n).unsubscribe(),t}function an(e,t){const n=l.useRef(),[r,a]=nn(()=>{const u=[],d=en(ze(e.config,t||e._options)),g=d.send;return d.send=f=>{if(d.status===z.NotStarted){u.push(f);return}g(f),n.current=d.state},[d,u]});tn(()=>{t&&(r._machine._options=t)});const i=l.useCallback(()=>rn(r),[r]),o=l.useCallback(u=>{const{unsubscribe:d}=r.subscribe(u);return d},[r]),s=l.useSyncExternalStore(o,i,i);return l.useEffect(()=>(r.start(n.current),a.forEach(r.send),n.current=r.state,()=>{r.stop()}),[]),[s,r.send,r]}function Q(e){if(!e){const t=`flattenConnection(): needs a 'connection' to flatten, but received '${e??""}' instead.`;return console.error(t+" Returning an empty array"),[]}return"nodes"in e?e.nodes:"edges"in e&&Array.isArray(e.edges)?e.edges.map(t=>{if(!(t!=null&&t.node))throw new Error("flattenConnection(): Connection edges must contain nodes");return t.node}):[]}const on=e=>` mutation CartLineAdd( $cartId: ID! $lines: [CartLineInput!]! $numCartLines: Int = 250 $country: CountryCode = ZZ $language: LanguageCode $visitorConsent: VisitorConsent ) @inContext( country: $country language: $language visitorConsent: $visitorConsent ) { cartLinesAdd(cartId: $cartId, lines: $lines) { cart { ...CartFragment } } } ${e} `,sn=e=>` mutation CartCreate( $input: CartInput! $numCartLines: Int = 250 $country: CountryCode = ZZ $language: LanguageCode $visitorConsent: VisitorConsent ) @inContext( country: $country language: $language visitorConsent: $visitorConsent ) { cartCreate(input: $input) { cart { ...CartFragment } } } ${e} `,cn=e=>` mutation CartLineRemove( $cartId: ID! $lines: [ID!]! $numCartLines: Int = 250 $country: CountryCode = ZZ $language: LanguageCode $visitorConsent: VisitorConsent ) @inContext( country: $country language: $language visitorConsent: $visitorConsent ) { cartLinesRemove(cartId: $cartId, lineIds: $lines) { cart { ...CartFragment } } } ${e} `,un=e=>` mutation CartLineUpdate( $cartId: ID! $lines: [CartLineUpdateInput!]! $numCartLines: Int = 250 $country: CountryCode = ZZ $language: LanguageCode $visitorConsent: VisitorConsent ) @inContext( country: $country language: $language visitorConsent: $visitorConsent ) { cartLinesUpdate(cartId: $cartId, lines: $lines) { cart { ...CartFragment } } } ${e} `,ln=e=>` mutation CartNoteUpdate( $cartId: ID! $note: String! $numCartLines: Int = 250 $country: CountryCode = ZZ $language: LanguageCode $visitorConsent: VisitorConsent ) @inContext( country: $country language: $language visitorConsent: $visitorConsent ) { cartNoteUpdate(cartId: $cartId, note: $note) { cart { ...CartFragment } } } ${e} `,dn=e=>` mutation CartBuyerIdentityUpdate( $cartId: ID! $buyerIdentity: CartBuyerIdentityInput! $numCartLines: Int = 250 $country: CountryCode = ZZ $language: LanguageCode $visitorConsent: VisitorConsent ) @inContext( country: $country language: $language visitorConsent: $visitorConsent ) { cartBuyerIdentityUpdate(cartId: $cartId, buyerIdentity: $buyerIdentity) { cart { ...CartFragment } } } ${e} `,fn=e=>` mutation CartAttributesUpdate( $attributes: [AttributeInput!]! $cartId: ID! $numCartLines: Int = 250 $country: CountryCode = ZZ $language: LanguageCode $visitorConsent: VisitorConsent ) @inContext( country: $country language: $language visitorConsent: $visitorConsent ) { cartAttributesUpdate(attributes: $attributes, cartId: $cartId) { cart { ...CartFragment } } } ${e} `,gn=e=>` mutation CartDiscountCodesUpdate( $cartId: ID! $discountCodes: [String!]! $numCartLines: Int = 250 $country: CountryCode = ZZ $language: LanguageCode $visitorConsent: VisitorConsent ) @inContext( country: $country language: $language visitorConsent: $visitorConsent ) { cartDiscountCodesUpdate(cartId: $cartId, discountCodes: $discountCodes) { cart { ...CartFragment } } } ${e} `,hn=e=>` query CartQuery( $id: ID! $numCartLines: Int = 250 $country: CountryCode = ZZ $language: LanguageCode $visitorConsent: VisitorConsent ) @inContext( country: $country language: $language visitorConsent: $visitorConsent ) { cart(id: $id) { ...CartFragment } } ${e} `,yn=` fragment CartFragment on Cart { id checkoutUrl totalQuantity buyerIdentity { countryCode customer { id email firstName lastName displayName } email phone } lines(first: $numCartLines) { edges { node { id quantity attributes { key value } cost { totalAmount { amount currencyCode } compareAtAmountPerQuantity { amount currencyCode } } merchandise { ... on ProductVariant { id availableForSale compareAtPrice { ...MoneyFragment } price { ...MoneyFragment } requiresShipping title image { ...ImageFragment } product { handle title id } selectedOptions { name value } } } } } } cost { subtotalAmount { ...MoneyFragment } totalAmount { ...MoneyFragment } totalDutyAmount { ...MoneyFragment } totalTaxAmount { ...MoneyFragment } } note attributes { key value } discountCodes { code applicable } } fragment MoneyFragment on MoneyV2 { currencyCode amount } fragment ImageFragment on Image { id url altText width height } `,re="2026-01",mn="mock.shop",tt=e=>e.includes(mn);function pn({storeDomain:e,privateStorefrontToken:t,publicStorefrontToken:n,storefrontApiVersion:r=re,contentType:a}){if(!e)throw new Error(Oe+"`storeDomain` is required when creating a new Storefront client in production.");r!==re&&En(`The Storefront API version that you're using is different than the version this build of Hydrogen React is targeting. You may run into unexpected errors if these versions don't match. Received version: "${r}"; expected version "${re}"`);const i=o=>{const s=(o==null?void 0:o.storeDomain)??e;return s.includes("://")?s:`https://${s}`};return{getShopifyDomain:i,getStorefrontApiUrl(o){const s=i(o);return`${s+(s.endsWith("/")?"api":"/api")}/${(o==null?void 0:o.storefrontApiVersion)??r}/graphql.json`},getPrivateTokenHeaders(o){if(!t&&!(o!=null&&o.privateStorefrontToken)&&!tt(e))throw new Error(Oe+"You did not pass in a `privateStorefrontToken` while using `createStorefrontClient()` or `getPrivateTokenHeaders()`");return{"content-type":((o==null?void 0:o.contentType)??a)==="graphql"?"application/graphql":"application/json","X-SDK-Variant":"hydrogen-react","X-SDK-Variant-Source":"react","X-SDK-Version":r,"Shopify-Storefront-Private-Token":(o==null?void 0:o.privateStorefrontToken)??t??"",...o!=null&&o.buyerIp?{"Shopify-Storefront-Buyer-IP":o.buyerIp}:{}}},getPublicTokenHeaders(o){if(!n&&!(o!=null&&o.publicStorefrontToken)&&!tt(e))throw new Error(Oe+"You did not pass in a `publicStorefrontToken` while using `createStorefrontClient()` or `getPublicTokenHeaders()`");const s=(o==null?void 0:o.contentType)??a??"json";return nt(s,r,(o==null?void 0:o.publicStorefrontToken)??n??"")}}}function nt(e,t,n){return{"content-type":e==="graphql"?"application/graphql":"application/json","X-SDK-Variant":"hydrogen-react","X-SDK-Variant-Source":"react","X-SDK-Version":t,"X-Shopify-Storefront-Access-Token":n}}const rt=new Set,Oe="[h2:error:createStorefrontClient] ",En=(e,t="warn")=>{rt.has(e)||(console[t](`[h2:${t}:createStorefrontClient] `+e),rt.add(e))},at={storeDomain:"test",storefrontToken:"abc123",storefrontApiVersion:re,countryIsoCode:"US",languageIsoCode:"EN",getStorefrontApiUrl(){return""},getPublicTokenHeaders(){return{}},getShopifyDomain(){return""}},it=l.createContext(at);function _n(){var e,t,n;if(typeof window>"u")return!1;try{const r=(t=(e=window.performance)==null?void 0:e.getEntriesByType)==null?void 0:t.call(e,"navigation")[0];return!!((n=r==null?void 0:r.serverTiming)!=null&&n.some(a=>a.name==="_sfapi_proxy"))}catch{return!1}}function Cn({children:e,...t}){if(!t.countryIsoCode||!t.languageIsoCode||!t.storeDomain||!t.storefrontToken||!t.storefrontApiVersion)throw new Error("Please provide the necessary props to '<ShopifyProvider/>'");t.storefrontApiVersion!==re&&console.warn(`<ShopifyProvider/>: This version of Hydrogen React is built for Shopify's Storefront API version ${re}, but it looks like you're using version ${t.storefrontApiVersion}. There may be issues or bugs if you use a mismatched version of Hydrogen React and the Storefront API.`);const n=l.useMemo(()=>{const r=t.sameDomainForStorefrontApi??_n();function a(i){const o=(i==null?void 0:i.storeDomain)??t.storeDomain;return o.includes("://")?o:`https://${o}`}return{...t,sameDomainForStorefrontApi:r,getPublicTokenHeaders(i){return nt(i.contentType,t.storefrontApiVersion,i.storefrontToken??t.storefrontToken)},getShopifyDomain:a,getStorefrontApiUrl(i){const o=r&&typeof window<"u"?window.location.origin:a({storeDomain:(i==null?void 0:i.storeDomain)??t.storeDomain});return`${o}${o.endsWith("/")?"":"/"}api/${(i==null?void 0:i.storefrontApiVersion)??t.storefrontApiVersion}/graphql.json`}}},[t]);return React.createElement(it.Provider,{value:n},e)}function ce(){const e=l.useContext(it);if(!e)throw new Error("'useShop()' must be a descendent of <ShopifyProvider/>");return e}const Re="shopifyCartId",ot="Shopify-Storefront-Id",st="Shopify-Storefront-Y",ct="Shopify-Storefront-S",Te="_shopify_y",Se="_shopify_s",Ve="X-Shopify-VisitToken",ke="X-Shopify-UniqueToken",De={current:null};function ee(){var t,n,r;let e;if(typeof window<"u"&&typeof window.performance<"u")try{const a=/^https?:\/\/([^/]+)(\/api\/(?:unstable|2\d{3}-\d{2})\/graphql\.json(?=$|\?))?/,i=performance.getEntriesByType("resource");let o;for(let s=i.length-1;s>=0;s--){const u=i[s];if(u.initiatorType!=="fetch")continue;const d=window.location.host,g=u.name.match(a);if(!g)continue;const[,f,h]=g;if(f===d||h&&(f==null?void 0:f.endsWith(`.${d}`))){const c=ut(u);if(c){o=c;break}}}if(o&&(e=o),e?De.current=e:De.current&&(e=De.current),!e){const s=performance.getEntriesByType("navigation")[0];e=ut(s,!1)}}catch{}if(!e){const a=typeof arguments[0]=="string"?arguments[0]:typeof document<"u"?document.cookie:"";e={uniqueToken:((t=a.match(/\b_shopify_y=([^;]+)/))==null?void 0:t[1])||"",visitToken:((n=a.match(/\b_shopify_s=([^;]+)/))==null?void 0:n[1])||"",consent:((r=a.match(/\b_tracking_consent=([^;]+)/))==null?void 0:r[1])||""}}return e}function ut(e,t=!0){let n="",r="",a="";const i=e.serverTiming;if(i&&i.length>=3)for(let o=i.length-1;o>=0;o--){const{name:s,description:u}=i[o];if(!(!s||!u)&&(s==="_y"?n=u:s==="_s"?r=u:s==="_cmp"&&(a=u),n&&r&&a))break}return n&&r&&(!t||a)?{uniqueToken:n,visitToken:r,consent:a}:void 0}function Tn(){const{storefrontId:e,getPublicTokenHeaders:t,getStorefrontApiUrl:n,sameDomainForStorefrontApi:r}=ce();return l.useCallback(({query:a,variables:i})=>{const o=t({contentType:"json"});if(e&&(o[ot]=e),!r){const{uniqueToken:s,visitToken:u}=ee();s&&(o[st]=s,o[ke]=s),u&&(o[ct]=u,o[Ve]=u)}return fetch(n(),{method:"POST",headers:o,body:JSON.stringify({query:a.toString(),variables:i})}).then(s=>s.json()).catch(s=>({data:void 0,errors:s==null?void 0:s.toString()}))},[t,e,n,r])}function Sn({numCartLines:e,cartFragment:t,countryCode:n="US",languageCode:r="EN"}){const a=Tn(),i=l.useCallback(c=>a({query:hn(t),variables:{id:c,numCartLines:e,country:n,language:r}}),[a,t,e,n,r]),o=l.useCallback(c=>a({query:sn(t),variables:{input:c,numCartLines:e,country:n,language:r}}),[t,n,a,e,r]),s=l.useCallback((c,T)=>a({query:on(t),variables:{cartId:c,lines:T,numCartLines:e,country:n,language:r}}),[t,n,a,e,r]),u=l.useCallback((c,T)=>a({query:un(t),variables:{cartId:c,lines:T,numCartLines:e,country:n,language:r}}),[t,n,a,e,r]),d=l.useCallback((c,T)=>a({query:cn(t),variables:{cartId:c,lines:T,numCartLines:e,country:n,language:r}}),[t,n,a,e,r]),g=l.useCallback((c,T)=>a({query:ln(t),variables:{cartId:c,note:T,numCartLines:e,country:n,language:r}}),[a,t,e,n,r]),f=l.useCallback((c,T)=>a({query:dn(t),variables:{cartId:c,buyerIdentity:T,numCartLines:e,country:n,language:r}}),[t,n,a,e,r]),h=l.useCallback((c,T)=>a({query:fn(t),variables:{cartId:c,attributes:T,numCartLines:e,country:n,language:r}}),[t,n,a,e,r]),E=l.useCallback((c,T)=>a({query:gn(t),variables:{cartId:c,discountCodes:T,numCartLines:e,country:n,language:r}}),[t,n,a,e,r]);return l.useMemo(()=>({cartFetch:i,cartCreate:o,cartLineAdd:s,cartLineUpdate:u,cartLineRemove:d,noteUpdate:g,buyerIdentityUpdate:f,cartAttributesUpdate:h,discountCodesUpdate:E,cartFragment:t}),[i,o,s,u,d,g,f,h,E,t])}function Y(e,t){return{entry:[...(t==null?void 0:t.entryActions)||[],ne({lastValidCart:n=>n==null?void 0:n.cart}),"onCartActionEntry","onCartActionOptimisticUI",e],on:{RESOLVE:{target:(t==null?void 0:t.resolveTarget)||"idle",actions:[ne({prevCart:n=>n==null?void 0:n.lastValidCart,cart:(n,r)=>{var a;return(a=r==null?void 0:r.payload)==null?void 0:a.cart},rawCartResult:(n,r)=>{var a;return(a=r==null?void 0:r.payload)==null?void 0:a.rawCartResult},errors:n=>{}})]},ERROR:{target:(t==null?void 0:t.errorTarget)||"error",actions:[ne({prevCart:n=>n==null?void 0:n.lastValidCart,cart:n=>n==null?void 0:n.lastValidCart,errors:(n,r)=>{var a;return(a=r==null?void 0:r.payload)==null?void 0:a.errors}})]},CART_COMPLETED:{target:"cartCompleted",actions:ne({prevCart:n=>{},cart:n=>{},lastValidCart:n=>{},rawCartResult:n=>{},errors:n=>{}})}},exit:["onCartActionComplete",...(t==null?void 0:t.exitActions)||[]]}}const ue={CART_FETCH:{target:"cartFetching"},CART_CREATE:{target:"cartCreating"},CART_SET:{target:"idle",actions:[ne({rawCartResult:(e,t)=>t.payload.cart,cart:(e,t)=>Ue(t.payload.cart)})]}},lt={CARTLINE_ADD:{target:"cartLineAdding"},CARTLINE_UPDATE:{target:"cartLineUpdating"},CARTLINE_REMOVE:{target:"cartLineRemoving"},NOTE_UPDATE:{target:"noteUpdating"},BUYER_IDENTITY_UPDATE:{target:"buyerIdentityUpdating"},CART_ATTRIBUTES_UPDATE:{target:"cartAttributesUpdating"},DISCOUNT_CODES_UPDATE:{target:"discountCodesUpdating"}};function bn(e){return ze({id:"Cart",initial:e?"idle":"uninitialized",context:{cart:e&&Ue(e)},states:{uninitialized:{on:ue},cartCompleted:{on:ue},initializationError:{on:ue},idle:{on:{...ue,...lt}},error:{on:{...ue,...lt}},cartFetching:Y("cartFetchAction",{errorTarget:"initializationError"}),cartCreating:Y("cartCreateAction",{errorTarget:"initializationError"}),cartLineRemoving:Y("cartLineRemoveAction"),cartLineUpdating:Y("cartLineUpdateAction"),cartLineAdding:Y("cartLineAddAction"),noteUpdating:Y("noteUpdateAction"),buyerIdentityUpdating:Y("buyerIdentityUpdateAction"),cartAttributesUpdating:Y("cartAttributesUpdateAction"),discountCodesUpdating:Y("discountCodesUpdateAction")}})}function An({numCartLines:e,onCartActionEntry:t,onCartActionOptimisticUI:n,onCartActionComplete:r,data:a,cartFragment:i,countryCode:o,languageCode:s}){const{cartFetch:u,cartCreate:d,cartLineAdd:g,cartLineUpdate:f,cartLineRemove:h,noteUpdate:E,buyerIdentityUpdate:c,cartAttributesUpdate:T,discountCodesUpdate:C}=Sn({numCartLines:e,cartFragment:i,countryCode:o,languageCode:s}),A=l.useMemo(()=>bn(a),[a]),[v,w,R]=an(A,{actions:{cartFetchAction:async(y,m)=>{var b;if(m.type!=="CART_FETCH")return;const{data:_,errors:P}=await u((b=m==null?void 0:m.payload)==null?void 0:b.cartId),O=W(m,_==null?void 0:_.cart,P);w(O)},cartCreateAction:async(y,m)=>{var b;if(m.type!=="CART_CREATE")return;const{data:_,errors:P}=await d(m==null?void 0:m.payload),O=W(m,(b=_==null?void 0:_.cartCreate)==null?void 0:b.cart,P);w(O)},cartLineAddAction:async(y,m)=>{var b,I;if(m.type!=="CARTLINE_ADD"||!((b=y==null?void 0:y.cart)!=null&&b.id))return;const{data:_,errors:P}=await g(y.cart.id,m.payload.lines),O=W(m,(I=_==null?void 0:_.cartLinesAdd)==null?void 0:I.cart,P);w(O)},cartLineUpdateAction:async(y,m)=>{var b,I;if(m.type!=="CARTLINE_UPDATE"||!((b=y==null?void 0:y.cart)!=null&&b.id))return;const{data:_,errors:P}=await f(y.cart.id,m.payload.lines),O=W(m,(I=_==null?void 0:_.cartLinesUpdate)==null?void 0:I.cart,P);w(O)},cartLineRemoveAction:async(y,m)=>{var b,I;if(m.type!=="CARTLINE_REMOVE"||!((b=y==null?void 0:y.cart)!=null&&b.id))return;const{data:_,errors:P}=await h(y.cart.id,m.payload.lines),O=W(m,(I=_==null?void 0:_.cartLinesRemove)==null?void 0:I.cart,P);w(O)},noteUpdateAction:async(y,m)=>{var b,I;if(m.type!=="NOTE_UPDATE"||!((b=y==null?void 0:y.cart)!=null&&b.id))return;const{data:_,errors:P}=await E(y.cart.id,m.payload.note),O=W(m,(I=_==null?void 0:_.cartNoteUpdate)==null?void 0:I.cart,P);w(O)},buyerIdentityUpdateAction:async(y,m)=>{var b,I;if(m.type!=="BUYER_IDENTITY_UPDATE"||!((b=y==null?void 0:y.cart)!=null&&b.id))return;const{data:_,errors:P}=await c(y.cart.id,m.payload.buyerIdentity),O=W(m,(I=_==null?void 0:_.cartBuyerIdentityUpdate)==null?void 0:I.cart,P);w(O)},cartAttributesUpdateAction:async(y,m)=>{var b,I;if(m.type!=="CART_ATTRIBUTES_UPDATE"||!((b=y==null?void 0:y.cart)!=null&&b.id))return;const{data:_,errors:P}=await T(y.cart.id,m.payload.attributes),O=W(m,(I=_==null?void 0:_.cartAttributesUpdate)==null?void 0:I.cart,P);w(O)},discountCodesUpdateAction:async(y,m)=>{var b,I;if(m.type!=="DISCOUNT_CODES_UPDATE"||!((b=y==null?void 0:y.cart)!=null&&b.id))return;const{data:_,errors:P}=await C(y.cart.id,m.payload.discountCodes),O=W(m,(I=_==null?void 0:_.cartDiscountCodesUpdate)==null?void 0:I.cart,P);w(O)},...t&&{onCartActionEntry:(y,m)=>{wn(m)&&t(y,m)}},...n&&{onCartActionOptimisticUI:ne((y,m)=>n(y,m))},...r&&{onCartActionComplete:(y,m)=>{In(m)&&r(y,m)}}}});return l.useMemo(()=>[v,w,R],[v,w,R])}function Ue(e){return{...e,lines:Q(e==null?void 0:e.lines),note:e.note??void 0}}function W(e,t,n){return n?{type:"ERROR",payload:{errors:n,cartActionEvent:e}}:t?{type:"RESOLVE",payload:{cart:Ue(t),rawCartResult:t,cartActionEvent:e}}:{type:"CART_COMPLETED",payload:{cartActionEvent:e}}}function wn(e){return e.type==="CART_CREATE"||e.type==="CARTLINE_ADD"||e.type==="CARTLINE_UPDATE"||e.type==="CARTLINE_REMOVE"||e.type==="NOTE_UPDATE"||e.type==="BUYER_IDENTITY_UPDATE"||e.type==="CART_ATTRIBUTES_UPDATE"||e.type==="DISCOUNT_CODES_UPDATE"}function In(e){return e.type==="RESOLVE"||e.type==="ERROR"||e.type==="CART_COMPLETED"}const dt=l.createContext(null);function ae(){const e=l.useContext(dt);if(!e)throw new Error("Expected a Cart Context, but no Cart Context was found");return e}function vn({children:e,numCartLines:t,onCreate:n,onLineAdd:r,onLineRemove:a,onLineUpdate:i,onNoteUpdate:o,onBuyerIdentityUpdate:s,onAttributesUpdate:u,onDiscountCodesUpdate:d,onCreateComplete:g,onLineAddComplete:f,onLineRemoveComplete:h,onLineUpdateComplete:E,onNoteUpdateComplete:c,onBuyerIdentityUpdateComplete:T,onAttributesUpdateComplete:C,onDiscountCodesUpdateComplete:A,data:v,cartFragment:w=yn,customerAccessToken:R,countryCode:y,languageCode:m}){var Wt,Gt,Zt,Kt,Qt,Jt,Xt;const _=ce();if(!_)throw new Error("<CartProvider> needs to be a descendant of <ShopifyProvider>");y=(y??_.countryIsoCode??"US").toUpperCase(),m=(m??_.languageIsoCode??"EN").toUpperCase(),y&&(y=y.toUpperCase());const[P,O]=l.useState(y),[b,I]=l.useState(R),q=l.useRef(!1);(P!==y||b!==R)&&(O(y),I(R),q.current=!1);const[V,H]=An({numCartLines:t,data:v,cartFragment:w,countryCode:y,languageCode:m,onCartActionEntry(S,U){try{switch(U.type){case"CART_CREATE":return n==null?void 0:n();case"CARTLINE_ADD":return r==null?void 0:r();case"CARTLINE_REMOVE":return a==null?void 0:a();case"CARTLINE_UPDATE":return i==null?void 0:i();case"NOTE_UPDATE":return o==null?void 0:o();case"BUYER_IDENTITY_UPDATE":return s==null?void 0:s();case"CART_ATTRIBUTES_UPDATE":return u==null?void 0:u();case"DISCOUNT_CODES_UPDATE":return d==null?void 0:d()}}catch(F){console.error("Cart entry action failed",F)}},onCartActionOptimisticUI(S,U){var F,K,N,_e;if(!S.cart)return{...S};switch(U.type){case"CARTLINE_REMOVE":return{...S,cart:{...S.cart,lines:(K=(F=S==null?void 0:S.cart)==null?void 0:F.lines)==null?void 0:K.filter(L=>(L==null?void 0:L.id)&&!U.payload.lines.includes(L==null?void 0:L.id))}};case"CARTLINE_UPDATE":return{...S,cart:{...S.cart,lines:(_e=(N=S==null?void 0:S.cart)==null?void 0:N.lines)==null?void 0:_e.map(L=>{const We=U.payload.lines.find(({id:Jr})=>Jr===(L==null?void 0:L.id));return We&&We.quantity?{...L,quantity:We.quantity}:L})}}}return{...S}},onCartActionComplete(S,U){const F=U.payload.cartActionEvent;try{switch(U.type){case"RESOLVE":switch(F.type){case"CART_CREATE":return g==null?void 0:g();case"CARTLINE_ADD":return f==null?void 0:f();case"CARTLINE_REMOVE":return h==null?void 0:h();case"CARTLINE_UPDATE":return E==null?void 0:E();case"NOTE_UPDATE":return c==null?void 0:c();case"BUYER_IDENTITY_UPDATE":return Rn(S,F)&&(q.current=!0),T==null?void 0:T();case"CART_ATTRIBUTES_UPDATE":return C==null?void 0:C();case"DISCOUNT_CODES_UPDATE":return A==null?void 0:A()}}}catch(K){console.error("onCartActionComplete failed",K)}}}),X=l.useRef(!1),[me,D]=l.useState(!1),se=V.matches("cartCompleted"),pe=(V.value==="idle"||V.value==="error"||V.value==="cartCompleted")&&y!==((Zt=(Gt=(Wt=V==null?void 0:V.context)==null?void 0:Wt.cart)==null?void 0:Gt.buyerIdentity)==null?void 0:Zt.countryCode)&&!V.context.errors,Ee=l.useRef(!1);l.useEffect(()=>{if(!X.current&&!Ee.current){if(!v&&Ne("localStorage")){Ee.current=!0;try{const S=window.localStorage.getItem(Re);S&&H({type:"CART_FETCH",payload:{cartId:S}})}catch(S){console.warn("error fetching cartId"),console.warn(S)}}X.current=!0,D(!0)}},[v,X,H]),l.useEffect(()=>{!pe||q.current||H({type:"BUYER_IDENTITY_UPDATE",payload:{buyerIdentity:{countryCode:y,customerAccessToken:R}}})},[y,R,pe,q,H]);const B=l.useCallback(S=>{if(!X.current)return console.warn("Cart isn't ready yet");H(S)},[H]);l.useEffect(()=>{var S,U,F;if((U=(S=V==null?void 0:V.context)==null?void 0:S.cart)!=null&&U.id&&Ne("localStorage"))try{window.localStorage.setItem(Re,(F=V.context.cart)==null?void 0:F.id)}catch(K){console.warn("Failed to save cartId to localStorage",K)}},[(Qt=(Kt=V==null?void 0:V.context)==null?void 0:Kt.cart)==null?void 0:Qt.id]),l.useEffect(()=>{if(se&&Ne("localStorage"))try{window.localStorage.removeItem(Re)}catch(S){console.warn("Failed to delete cartId from localStorage",S)}},[se]);const Ye=l.useCallback(S=>{var U,F;y&&!((U=S.buyerIdentity)!=null&&U.countryCode)&&(S.buyerIdentity==null&&(S.buyerIdentity={}),S.buyerIdentity.countryCode=y),R&&!((F=S.buyerIdentity)!=null&&F.customerAccessToken)&&(S.buyerIdentity==null&&(S.buyerIdentity={}),S.buyerIdentity.customerAccessToken=R),B({type:"CART_CREATE",payload:S})},[y,R,B]),k=On(V),Qr=l.useMemo(()=>{var S,U,F,K;return{...((S=k==null?void 0:k.context)==null?void 0:S.cart)??{lines:[],attributes:[]},status:Pn(k.value),error:(U=k==null?void 0:k.context)==null?void 0:U.errors,totalQuantity:((K=(F=k==null?void 0:k.context)==null?void 0:F.cart)==null?void 0:K.totalQuantity)??0,cartCreate:Ye,cartReady:me,linesAdd(N){var _e,L;(L=(_e=k==null?void 0:k.context)==null?void 0:_e.cart)!=null&&L.id?B({type:"CARTLINE_ADD",payload:{lines:N}}):Ye({lines:N})},linesRemove(N){B({type:"CARTLINE_REMOVE",payload:{lines:N}})},linesUpdate(N){B({type:"CARTLINE_UPDATE",payload:{lines:N}})},noteUpdate(N){B({type:"NOTE_UPDATE",payload:{note:N}})},buyerIdentityUpdate(N){B({type:"BUYER_IDENTITY_UPDATE",payload:{buyerIdentity:N}})},cartAttributesUpdate(N){B({type:"CART_ATTRIBUTES_UPDATE",payload:{attributes:N}})},discountCodesUpdate(N){B({type:"DISCOUNT_CODES_UPDATE",payload:{discountCodes:N}})},cartFragment:w}},[Ye,me,(Jt=k==null?void 0:k.context)==null?void 0:Jt.cart,(Xt=k==null?void 0:k.context)==null?void 0:Xt.errors,k.value,w,B]);return React.createElement(dt.Provider,{value:Qr},e)}function Pn(e){switch(e){case"uninitialized":case"initializationError":return"uninitialized";case"idle":case"cartCompleted":case"error":return"idle";case"cartFetching":return"fetching";case"cartCreating":return"creating";case"cartLineAdding":case"cartLineRemoving":case"cartLineUpdating":case"noteUpdating":case"buyerIdentityUpdating":case"cartAttributesUpdating":case"discountCodesUpdating":return"updating"}}function On(e){const[t,n]=l.useTransition(),[r,a]=l.useState(e),i=l.useRef(!1);t&&(i.current=!0);const o=l.useRef(!1);return!t&&i.current&&(o.current=!0),l.useEffect(()=>{n(()=>{o.current||a(e)})},[e]),o.current?e:r}function Ne(e){let t;try{t=window[e];const n="__storage_test__";return t.setItem(n,n),t.removeItem(n),!0}catch(n){return!!(n instanceof DOMException&&(n.code===22||n.code===1014||n.name==="QuotaExceededError"||n.name==="NS_ERROR_DOM_QUOTA_REACHED")&&t&&t.length!==0)}}function Rn(e,t){var n,r;return!!(t.payload.buyerIdentity.countryCode&&((r=(n=e.cart)==null?void 0:n.buyerIdentity)==null?void 0:r.countryCode)!==t.payload.buyerIdentity.countryCode)}const ft=l.createContext(null);function Vn({children:e,data:t,initialVariantId:n}){const r=l.useMemo(()=>Q(t.variants??{}),[t.variants]);if(!Dn(r))throw new Error("<ProductProvider/> requires 'product.variants.nodes' or 'product.variants.edges'");const a=l.useMemo(()=>kn(r),[r]),[i,o]=l.useState(()=>yt(n,r)),[s,u]=l.useState(()=>mt(i));l.useEffect(()=>{const C=yt(n,r);o(C),u(mt(C))},[n,r]);const d=l.useCallback((C,A)=>{u(v=>{const w={...v,[C]:A};return o(ht(r,w)),w})},[u,r]),g=l.useCallback((C,A)=>{const v=ht(r,{...s,[C]:A});return(v==null?void 0:v.availableForSale)??!0},[s,r]),f=l.useMemo(()=>Q(t.sellingPlanGroups??{}).map(C=>({...C,sellingPlans:Q((C==null?void 0:C.sellingPlans)??{})})),[t.sellingPlanGroups]),[h,E]=l.useState(void 0),c=l.useMemo(()=>{var C,A;if(!(!i||!h)){if(!((C=i.sellingPlanAllocations)!=null&&C.nodes)&&!((A=i.sellingPlanAllocations)!=null&&A.edges))throw new Error("<ProductProvider/>: You must include 'sellingPlanAllocations.nodes' or 'sellingPlanAllocations.edges' in your variants in order to calculate selectedSellingPlanAllocation");return Q(i.sellingPlanAllocations).find(v=>{var w;return((w=v==null?void 0:v.sellingPlan)==null?void 0:w.id)===h.id})}},[i,h]),T=l.useMemo(()=>({product:t,variants:r,variantsConnection:t.variants,options:a,selectedVariant:i,setSelectedVariant:o,selectedOptions:s,setSelectedOption:d,setSelectedOptions:u,isOptionInStock:g,selectedSellingPlan:h,setSelectedSellingPlan:E,selectedSellingPlanAllocation:c,sellingPlanGroups:f,sellingPlanGroupsConnection:t.sellingPlanGroups}),[t,g,a,s,h,c,i,f,d,r]);return React.createElement(ft.Provider,{value:T},e)}function gt(){const e=l.useContext(ft);if(!e)throw new Error("'useProduct' must be a child of <ProductProvider />");return e}function ht(e,t){var n,r;if(!(!e.length||((r=(n=e==null?void 0:e[0])==null?void 0:n.selectedOptions)==null?void 0:r.length)!==Object.keys(t).length))return e==null?void 0:e.find(a=>Object.entries(t).every(([i,o])=>{var s;return(s=a==null?void 0:a.selectedOptions)==null?void 0:s.some(u=>(u==null?void 0:u.name)===i&&(u==null?void 0:u.value)===o)}))}function kn(e){const t=e.reduce((n,r)=>{var a;if(!r.selectedOptions)throw new Error("'getOptions' requires 'variant.selectedOptions'");return(a=r==null?void 0:r.selectedOptions)==null||a.forEach(i=>{n[(i==null?void 0:i.name)??""]=n[(i==null?void 0:i.name)??""]||new Set,n[(i==null?void 0:i.name)??""].add((i==null?void 0:i.value)??"")}),n},{});return Object.keys(t).map(n=>({name:n,values:Array.from(t[n])}))}function yt(e,t){if(e){const n=t.find(r=>(r==null?void 0:r.id)===e);return n||console.warn("<ProductProvider/> received a 'initialVariantId' prop, but could not actually find a variant with that ID"),n}if(e===null)return null;if(e===void 0)return t.find(n=>n==null?void 0:n.availableForSale)||t[0]}function mt(e){return e!=null&&e.selectedOptions?e.selectedOptions.reduce((t,n)=>(t[(n==null?void 0:n.name)??""]=(n==null?void 0:n.value)??"",t),{}):{}}function Dn(e){return!(!e||!Array.isArray(e))}function be(e){const{as:t,onClick:n,defaultOnClick:r,children:a,buttonRef:i,...o}=e,s=l.useCallback(d=>{if(n){const g=n(d);if(typeof g=="boolean"&&g===!1||d!=null&&d.defaultPrevented)return}r==null||r(d)},[r,n]),u=t||"button";return React.createElement(u,{ref:i,onClick:s,...o},a)}function Un(e){const[t,n]=l.useState(!1),{variantId:r,quantity:a=1,attributes:i,sellingPlanId:o,onClick:s,children:u,accessibleAddingToCartLabel:d,parent:g,...f}=e,{status:h,linesAdd:E}=ae(),{selectedVariant:c}=gt(),T=r??(c==null?void 0:c.id)??"",C=r===null||T===""||c===null||t||f.disabled;l.useEffect(()=>{t&&h==="idle"&&n(!1)},[h,t]);const A=l.useCallback(()=>{n(!0),E([{quantity:a,merchandiseId:T||"",attributes:i,parent:g,sellingPlanId:o}])},[E,a,T,i,o,g]);return M.createElement(M.Fragment,null,M.createElement(be,{...f,disabled:C,onClick:s,defaultOnClick:A},u),d?M.createElement("p",{style:{position:"absolute",width:"1px",height:"1px",padding:"0",margin:"-1px",overflow:"hidden",clip:"rect(0, 0, 0, 0)",whiteSpace:"nowrap",borderWidth:"0"},role:"alert","aria-live":"assertive"},t?d:null):null)}const te={PAGE_VIEW:"PAGE_VIEW",ADD_TO_CART:"ADD_TO_CART",PAGE_VIEW_2:"PAGE_VIEW_2",COLLECTION_VIEW:"COLLECTION_VIEW",PRODUCT_VIEW:"PRODUCT_VIEW",SEARCH_VIEW:"SEARCH_VIEW"},Ae={article:"article",blog:"blog",captcha:"captcha",cart:"cart",collection:"collection",customersAccount:"customers/account",customersActivateAccount:"customers/activate_account",customersAddresses:"customers/addresses",customersLogin:"customers/login",customersOrder:"customers/order",customersRegister:"customers/register",customersResetPassword:"customers/reset_password",giftCard:"gift_card",home:"index",listCollections:"list-collections",forbidden:"403",notFound:"404",page:"page",password:"password",product:"product",policy:"policy",search:"search"},pt={hydrogen:"hydrogen",headless:"headless"},Et={hydrogen:"6167201",headless:"12875497473"};function x(e,t){return{schema_id:e,payload:t,metadata:{event_created_at_ms:Date.now()}}}function $(e){const t={id:"",resource:null,resourceId:null,search:"",searchParams:new URLSearchParams,hash:""};if(typeof e!="string")return t;try{const{search:n,searchParams:r,pathname:a,hash:i}=new URL(e),o=a.split("/"),s=o[o.length-1],u=o[o.length-2];return!s||!u?t:{id:`${s}${n}${i}`||"",resource:u??null,resourceId:s||null,search:n,searchParams:r,hash:i}}catch{return t}}function j(e,t){return typeof e!="object"?{}:(Object.entries(e).forEach(([n,r])=>{r&&(t[n]=r)}),t)}function Nn(e){return typeof document>"u"?(console.error(`${e} should only be used within the useEffect callback or event handlers`),!0):!1}const _t="xxxx-4xxx-xxxx-xxxxxxxxxxxx";function we(){let e="";try{const t=window.crypto,n=new Uint16Array(31);t.getRandomValues(n);let r=0;e=_t.replace(/[x]/g,a=>{const i=n[r]%16,o=a==="x"?i:i&3|8;return r++,o.toString(16)}).toUpperCase()}catch{e=_t.replace(/[x]/g,n=>{const r=Math.random()*16|0;return(n==="x"?r:r&3|8).toString(16)}).toUpperCase()}return`${Mn()}-${e}`}function Mn(){let e=0,t=0;e=new Date().getTime()>>>0;try{t=performance.now()>>>0}catch{t=0}return Math.abs(e+t).toString(16).toLowerCase().padStart(8,"0")}function Fn(e){const t=ee(e);return{[Te]:t.uniqueToken,[Se]:t.visitToken}}const Ln="trekkie_storefront_page_view/1.4",$n="myshopify.dev";function Ct(e){const t=e,{id:n,resource:r}=$(t.resourceId),a=r?r.toLowerCase():void 0;return[x(Ln,j({pageType:t.pageType,customerId:parseInt($(t.customerId).id||"0"),resourceType:a,resourceId:parseInt(n)},jn(t)))]}function jn(e){return{appClientId:e.shopifySalesChannel?Et[e.shopifySalesChannel]:Et.headless,isMerchantRequest:xn(e.url),hydrogenSubchannelId:e.storefrontId||e.hydrogenSubchannelId||"0",isPersistentCookie:e.hasUserConsent,uniqToken:e.uniqueToken,visitToken:e.visitToken,microSessionId:we(),microSessionCount:1,url:e.url,path:e.path,search:e.search,referrer:e.referrer,title:e.title,shopId:parseInt($(e.shopId).id),currency:e.currency,contentLanguage:e.acceptedLanguage||"en"}}function xn(e){if(typeof e!="string")return!1;const t=new URL(e).hostname;return t.indexOf($n)!==-1||t==="localhost"}const qn="2026.1.2",G="custom_storefront_customer_tracking/1.2",Tt="page_rendered",St="collection_page_rendered",bt="product_page_rendered",Hn="product_added_to_cart",At="search_submitted";function le(e){return{canonical_url:e.canonicalUrl||e.url,customer_id:parseInt($(e.customerId).id||"0")}}function Bn(e){const t=e,n=le(t),r=t.pageType,a=[];switch(a.push(x(G,j({event_name:Tt,...n},Z(t)))),r){case Ae.collection:a.push(x(G,j({event_name:St,...n,collection_name:t.collectionHandle,collection_id:parseInt($(t.collectionId).id)},Z(t))));break;case Ae.product:a.push(x(G,j({event_name:bt,...n,products:Me(t.products),total_value:t.totalValue},Z(t))));break;case Ae.search:a.push(x(G,j({event_name:At,...n,search_string:t.searchString},Z(t))));break}return a}function Yn(e){const t=e,n=le(t);return[x(G,j({event_name:Tt,...n},Z(t)))]}function Wn(e){const t=e,n=le(t);return[x(G,j({event_name:St,...n,collection_name:t.collectionHandle,collection_id:parseInt($(t.collectionId).id)},Z(t)))]}function Gn(e){const t=e,n=le(t);return[x(G,j({event_name:bt,...n,products:Me(t.products),total_value:t.totalValue},Z(t)))]}function Zn(e){const t=e,n=le(t);return[x(G,j({event_name:At,...n,search_string:t.searchString},Z(t)))]}function Kn(e){const t=e,n=$(t.cartId);return[x(G,j({event_name:Hn,customerId:t.customerId,cart_token:n!=null&&n.id?`${n.id}`:null,total_value:t.totalValue,products:Me(t.products),customer_id:parseInt($(t.customerId).id||"0")},Z(t)))]}function Z(e){const t=e;return{source:e.shopifySalesChannel||pt.headless,asset_version_id:e.assetVersionId||qn,hydrogenSubchannelId:e.storefrontId||e.hydrogenSubchannelId||"0",is_persistent_cookie:e.hasUserConsent,deprecated_visit_token:e.visitToken,unique_token:e.uniqueToken,event_time:Date.now(),event_id:we(),event_source_url:e.url,referrer:e.referrer,user_agent:e.userAgent,navigation_type:e.navigationType,navigation_api:e.navigationApi,shop_id:parseInt($(e.shopId).id),currency:e.currency,ccpa_enforced:t.ccpaEnforced||!1,gdpr_enforced:t.gdprEnforced||!1,gdpr_enforced_as_string:t.gdprEnforced?"true":"false",analytics_allowed:e.analyticsAllowed||!1,marketing_allowed:e.marketingAllowed||!1,sale_of_data_allowed:e.saleOfDataAllowed||!1}}function Me(e){return e?e.map(t=>{const n=j({variant_gid:t.variantGid,category:t.category,sku:t.sku,product_id:parseInt($(t.productGid).id),variant_id:parseInt($(t.variantGid).id)},{product_gid:t.productGid,name:t.name,variant:t.variantName||"",brand:t.brand,price:parseFloat(t.price),quantity:Number(t.quantity||0)});return JSON.stringify(n)}):[]}function Qn(e,t){const{eventName:n,payload:r}=e;if(!r.hasUserConsent)return Promise.resolve();let a=[];const i=r;return n===te.PAGE_VIEW?a=a.concat(Ct(i),Bn(i)):n===te.ADD_TO_CART?a=a.concat(Kn(r)):n===te.PAGE_VIEW_2?a=a.concat(Ct(i),Yn(i)):n===te.COLLECTION_VIEW?a=a.concat(Wn(i)):n===te.PRODUCT_VIEW?a=a.concat(Gn(i)):n===te.SEARCH_VIEW&&(a=a.concat(Zn(i))),a.length?Xn(a,t):Promise.resolve()}function Jn(){return typeof window>"u"||!window.navigator?!1:/Chrome-Lighthouse/.test(window.navigator.userAgent)}const wt="sendShopifyAnalytics request is unsuccessful";function Xn(e,t){if(Jn())return Promise.resolve();const n={events:e,metadata:{event_sent_at_ms:Date.now()}};try{return fetch(t?`https://${t}/.well-known/shopify/monorail/unstable/produce_batch`:"https://monorail-edge.shopifysvc.com/unstable/produce_batch",{method:"post",headers:{"content-type":"text/plain"},body:JSON.stringify(n)}).then(r=>{if(!r.ok)throw new Error("Response failed");return r.text()}).then(r=>{r&&JSON.parse(r).result.forEach(i=>{i.status!==200&&console.error(wt,` `,i.message)})}).catch(r=>{console.error(wt,r)})}catch{return Promise.resolve()}}function zn(){if(Nn("getClientBrowserParameters"))return{uniqueToken:"",visitToken:"",url:"",path:"",search:"",referrer:"",title:"",userAgent:"",navigationType:"",navigationApi:""};const[e,t]=nr(),n=ee();return{uniqueToken:n.uniqueToken,visitToken:n.visitToken,url:location.href,path:location.pathname,search:location.search,referrer:document.referrer,title:document.title,userAgent:navigator.userAgent,navigationType:e,navigationApi:t}}function er(){try{const e=(performance==null?void 0:performance.getEntriesByType)&&(performance==null?void 0:performance.getEntriesByType("navigation"));if(e&&e[0]){const t=window.performance.getEntriesByType("navigation")[0].type;return t&&t.toString()}}catch{}}function tr(){var e,t;try{if(PerformanceNavigation&&((e=performance==null?void 0:performance.navigation)==null?void 0:e.type)!==null&&((t=performance==null?void 0:performance.navigation)==null?void 0:t.type)!==void 0){const n=performance.navigation.type;switch(n){case PerformanceNavigation.TYPE_NAVIGATE:return"navigate";case PerformanceNavigation.TYPE_RELOAD:return"reload";case PerformanceNavigation.TYPE_BACK_FORWARD:return"back_forward";default:return`unknown: ${n}`}}}catch{}}function nr(){try{let e="PerformanceNavigationTiming",t=er();return t||(t=tr(),e="performance.navigation"),t?[t,e]:["unknown","unknown"]}catch{}return["error","error"]}function rr(e){const{cartCreate:t,checkoutUrl:n}=ae(),[r,a]=l.useState(!1),{quantity:i,variantId:o,sellingPlanId:s,onClick:u,attributes:d,children:g,...f}=e;l.useEffect(()=>{r&&n&&(window.location.href=n)},[r,n]);const h=l.useCallback(()=>{a(!0),t({lines:[{quantity:i??1,merchandiseId:o,attributes:d,sellingPlanId:s}]})},[t,i,o,d,s]);return React.createElement(be,{disabled:r??f.disabled,...f,onClick:u,defaultOnClick:h},g)}function ar(e){const[t,n]=l.useState(!1),{status:r,checkoutUrl:a}=ae(),{children:i,...o}=e;return l.useEffect(()=>{t&&a&&r==="idle"&&(window.location.href=a)},[t,r,a]),React.createElement(be,{...o,disabled:t||o.disabled,onClick:()=>n(!0)},i)}function It(e){const{countryIsoCode:t,languageIsoCode:n}=ce(),r=n.includes("_")?n.replace("_","-"):`${n}-${t}`;if(!r)throw new Error("useMoney(): Unable to get 'locale' from 'useShop()', which means that 'locale' was not passed to '<ShopifyProvider/>'. 'locale' is required for 'useMoney()' to work");const a=parseFloat(e.amount);let i=!0;try{new Intl.NumberFormat(r,{style:"currency",currency:e.currencyCode})}catch(c){c instanceof RangeError&&c.message.includes("currency")&&(i=!1)}const{defaultFormatter:o,nameFormatter:s,narrowSymbolFormatter:u,withoutTrailingZerosFormatter:d,withoutCurrencyFormatter:g,withoutTrailingZerosOrCurrencyFormatter:f}=l.useMemo(()=>{const c=i?{style:"currency",currency:e.currencyCode}:{style:"decimal",minimumFractionDigits:2,maximumFractionDigits:2};return{defaultFormatter:ie(r,c),nameFormatter:ie(r,{...c,currencyDisplay:"name"}),narrowSymbolFormatter:ie(r,{...c,currencyDisplay:"narrowSymbol"}),withoutTrailingZerosFormatter:ie(r,{...c,minimumFractionDigits:0,maximumFractionDigits:0}),withoutCurrencyFormatter:ie(r,{minimumFractionDigits:2,maximumFractionDigits:2}),withoutTrailingZerosOrCurrencyFormatter:ie(r,{minimumFractionDigits:0,maximumFractionDigits:0})}},[e.currencyCode,r,i]),h=c=>c.type==="currency",E=l.useMemo(()=>({original:()=>e,currencyCode:()=>e.currencyCode,localizedString:()=>{const c=o().format(a);return i?c:`${c} ${e.currencyCode}`},parts:()=>{const c=o().formatToParts(a);return i||c.push({type:"literal",value:" "},{type:"currency",value:e.currencyCode}),c},withoutTrailingZeros:()=>{const c=a%1===0?d().format(a):o().format(a);return i?c:`${c} ${e.currencyCode}`},withoutTrailingZerosAndCurrency:()=>a%1===0?f().format(a):g().format(a),currencyName:()=>{var c;return((c=s().formatToParts(a).find(h))==null?void 0:c.value)??e.currencyCode},currencySymbol:()=>{var c;return((c=o().formatToParts(a).find(h))==null?void 0:c.value)??e.currencyCode},currencyNarrowSymbol:()=>{var c;return((c=u().formatToParts(a).find(h))==null?void 0:c.value)??""},amount:()=>o().formatToParts(a).filter(c=>["decimal","fraction","group","integer","literal"].includes(c.type)).map(c=>c.value).join("")}),[e,a,i,s,o,u,g,d,f]);return l.useMemo(()=>new Proxy(E,{get:(c,T)=>{var C;return(C=Reflect.get(c,T))==null?void 0:C.call(null)}}),[E])}const vt=new Map;function ie(e,t){const n=JSON.stringify([e,t]);return function(){let r=vt.get(n);if(!r){try{r=new Intl.NumberFormat(e,t)}catch(a){if(a instanceof RangeError&&a.message.includes("currency")){const i={...t};delete i.currency,delete i.currencyDisplay,delete i.currencySign,r=new Intl.NumberFormat(e,i)}else throw a}vt.set(n,r)}return r}}function Ie({data:e,as:t,withoutCurrency:n,withoutTrailingZeros:r,measurement:a,measurementSeparator:i="/",...o}){if(!ir(e))throw new Error("<Money/> needs a valid 'data' prop that has 'amount' and 'currencyCode'");const s=It(e),u=t??"div";let d=s.localizedString;return(n||r)&&(n&&!r?d=s.amount:!n&&r?d=s.withoutTrailingZeros:d=s.withoutTrailingZerosAndCurrency),React.createElement(u,{...o},d,a&&a.referenceUnit&&React.createElement(React.Fragment,null,i,a.referenceUnit))}function ir(e){return typeof e.amount=="string"&&!!e.amount&&typeof e.currencyCode=="string"&&!!e.currencyCode}function or(e){const{cost:t}=ae(),{amountType:n="total",children:r,...a}=e;let i;return n=="total"?i=t==null?void 0:t.totalAmount:n=="subtotal"?i=t==null?void 0:t.subtotalAmount:n=="tax"?i=t==null?void 0:t.totalTaxAmount:n=="duty"&&(i=t==null?void 0:t.totalDutyAmount),i==null?null:React.createElement(Ie,{...a,data:i},r)}const Pt=l.createContext(null);function Fe(){const e=l.useContext(Pt);if(e==null)throw new Error("Expected a cart line context but none was found");return e}function sr({children:e,line:t}){return React.createElement(Pt.Provider,{value:t},e)}function cr(e){const t=Fe(),{as:n,...r}=e,a=n||"span";return React.createElement(a,{...r},t.quantity)}function ur(e){const{status:t,linesRemove:n,linesUpdate:r}=ae(),a=Fe(),{children:i,adjust:o,onClick:s,...u}=e,d=l.useCallback(()=>{if(o==="remove"){n([(a==null?void 0:a.id)??""]);return}const f=o==="decrease"?((a==null?void 0:a.quantity)??0)-1:((a==null?void 0:a.quantity)??0)+1;if(f<=0){n([(a==null?void 0:a.id)??""]);return}const h={id:(a==null?void 0:a.id)??"",quantity:f,attributes:(a==null?void 0:a.attributes)??[]};r([h])},[o,a==null?void 0:a.attributes,a==null?void 0:a.id,a==null?void 0:a.quantity,n,r]),g=u.disabled;return React.createElement(be,{...u,onClick:s,defaultOnClick:d,disabled:typeof g<"u"?g:t!=="idle"},i)}const lr={DateTime:"string",Decimal:"string",HTML:"string",URL:"string",Color:"string",UnsignedInt64:"string"},dr={DateTime:"string",Decimal:"string",HTML:"string",ISO8601DateTime:"string",URL:"string",UnsignedInt64:"string"},Ot=l.forwardRef((e,t)=>{const{data:n,options:r,id:a=n.id,frameBorder:i="0",allow:o="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture",allowFullScreen:s=!0,loading:u="lazy",...d}=e;if(!n.embedUrl)throw new Error("<ExternalVideo/> requires the 'embedUrl' property");let g=n.embedUrl;if(r){const f=new URL(n.embedUrl);for(const[h,E]of Object.entries(r))typeof E>"u"||f.searchParams.set(h,E.toString());g=f.toString()}return React.createElement("iframe",{...d,id:a??n.embedUrl,title:n.alt??n.id??"external video",frameBorder:i,allow:o,allowFullScreen:s,src:g,loading:u,ref:t})}),Le=",",oe={OPTION:":",END_OF_PREFIX:",",SEQUENCE_GAP:" ",RANGE:"-"},$e=(()=>{const e=new Map;return function(t,n){var r;if(t.length===0)return!1;if(!e.has(n)){const a=new Set;for(const i of Rt(n)){a.add(i.join(Le));for(let o=0;o<i.length;o++)a.add(i.slice(0,o+1).join(Le))}e.set(n,a)}return!!((r=e.get(n))!=null&&r.has(t.join(Le)))}})();function Rt(e){if(!e)return[];if(e.startsWith("v1_"))return gr(fr(e));throw new Error("Unsupported option value encoding")}const fr=e=>e.replace(/^v1_/,"");function gr(e){const t=/[ :,-]/g;let n=0,r;const a=[],i=[];let o=0,s=null;for(;r=t.exec(e);){const d=r[0],g=Number.parseInt(e.slice(n,r.index))||0;if(s!==null){for(;s<g;s++)i[o]=s,a.push([...i]);s=null}i[o]=g,d===oe.RANGE?s=g:d===oe.OPTION?o++:((d===oe.SEQUENCE_GAP||d===oe.END_OF_PREFIX&&e[r.index-1]!==oe.END_OF_PREFIX)&&a.push([...i]),d===oe.END_OF_PREFIX&&(i.pop(),o--)),n=t.lastIndex}const u=e.match(/\d+$/g);if(u){const d=parseInt(u[0]);if(s!=null)for(;s<=d;s++)i[o]=s,a.push([...i]);else a.push([d])}return a}function hr(e){return Object.assign({},...e.map(t=>({[t.name]:Object.assign({},...t!=null&&t.optionValues?t.optionValues.map((n,r)=>({[n.name]:r})):[])})))}function de(e){return Object.assign({},...e.map(t=>({[t.name]:t.value})))}function je(e){return JSON.stringify(de(e))}function Vt(e){return Array.isArray(e)?JSON.stringify(Object.assign({},...e.map(t=>({[t.name]:t.value})))):JSON.stringify(e)}function yr(e,t){return Object.keys(e).map(r=>t[r]?t[r][e[r]]:null).filter(r=>r!==null)}fun