(function(){"use strict";function W(t){z(t,"a",e=>e.href="javascript:void(0)")}function z(t,e,r){Array.from(document.querySelectorAll(t)).map(n=>n.closest(e)??n.querySelector(e)).filter((n,o,s)=>!!n&&s.indexOf(n)===o).forEach(r)}async function _(t,e="module"){return new Promise(r=>{const n=document.createElement("script");n.type=e,n.src=t,n.onload=r,document.head.appendChild(n)})}async function Z(t,e){var r;await _("https://assets.motive.co/wysiwyg/wysiwyg.js"),await((r=window.wysiwyg)==null?void 0:r.setConfig({auth:{baseUrl:"https://iam.motive.co",clientId:"wysiwyg"},analytics:{baseUrl:"https://statistics.api.motive.co"},catalog:{baseUrl:"https://analytics.api.motive.co"},search:{baseUrl:"https://search-platform.motive.co"},tagging:{baseUrl:"https://tagging-playboard.api.motive.co"},instance:t,lang:e,playboardUrl:"https://playboard.motive.co",audience:"sme",appContainerSelector:"#motive-container",searchLayerSelector:"#motive-x"}))}const A="GraphQL Client",$=0,I=3,D="An error occurred while fetching from the API. Review 'graphQLErrors' for details.",N="Response returned unexpected Content-Type:",O="An unknown error has occurred. The API did not return a data object or any errors in its response.",T={json:"application/json",multipart:"multipart/mixed"},U="X-SDK-Variant",x="X-SDK-Version",tt="shopify-graphql-client",et="1.2.2",P=1e3,rt=[429,503],L=/@(defer)\b/i,j=`\r `,nt=/boundary="?([^=";]+)"?/i,V=j+j;function m(t,e=A){return t.startsWith(`${e}`)?t:`${e}: ${t}`}function g(t){return t instanceof Error?t.message:JSON.stringify(t)}function q(t){return t instanceof Error&&t.cause?t.cause:void 0}function k(t){return t.flatMap(({errors:e})=>e??[])}function H({client:t,retries:e}){if(e!==void 0&&(typeof e!="number"||e<$||e>I))throw new Error(`${t}: The provided "retries" value (${e}) is invalid - it cannot be less than ${$} or greater than ${I}`)}function p(t,e){return e&&(typeof e!="object"||Array.isArray(e)||typeof e=="object"&&Object.keys(e).length>0)?{[t]:e}:{}}function M(t,e){if(t.length===0)return e;const n={[t.pop()]:e};return t.length===0?n:M(t,n)}function F(t,e){return Object.keys(e||{}).reduce((r,n)=>(typeof e[n]=="object"||Array.isArray(e[n]))&&t[n]?(r[n]=F(t[n],e[n]),r):(r[n]=e[n],r),Array.isArray(t)?[...t]:{...t})}function K([t,...e]){return e.reduce(F,{...t})}function ot({clientLogger:t,customFetchApi:e=fetch,client:r=A,defaultRetryWaitTime:n=P,retriableCodes:o=rt}){const s=async(c,i,a)=>{const u=i+1,d=a+1;let l;try{if(l=await e(...c),t({type:"HTTP-Response",content:{requestParams:c,response:l}}),!l.ok&&o.includes(l.status)&&u<=d)throw new Error;return l}catch(f){if(u<=d){const h=l==null?void 0:l.headers.get("Retry-After");return await st(h?parseInt(h,10):n),t({type:"HTTP-Retry",content:{requestParams:c,lastResponse:l,retryAttempt:i,maxRetries:a}}),s(c,u,a)}throw new Error(m(`${a>0?`Attempted maximum number of ${a} network retries. Last message - `:""}${g(f)}`,r))}};return s}async function st(t){return new Promise(e=>setTimeout(e,t))}function at({headers:t,url:e,customFetchApi:r=fetch,retries:n=0,logger:o}){H({client:A,retries:n});const s={headers:t,url:e,retries:n},c=it(o),i=ot({customFetchApi:r,clientLogger:c,defaultRetryWaitTime:P}),a=ct(i,s),u=ut(a),d=mt(a);return{config:s,fetch:a,request:u,requestStream:d}}function it(t){return e=>{t&&t(e)}}async function G(t){const{errors:e,data:r,extensions:n}=await t.json();return{...p("data",r),...p("extensions",n),headers:t.headers,...e||!r?{errors:{networkStatusCode:t.status,message:m(e?D:O),...p("graphQLErrors",e),response:t}}:{}}}function ct(t,{url:e,headers:r,retries:n}){return async(o,s={})=>{const{variables:c,headers:i,url:a,retries:u,signal:d}=s,l=JSON.stringify({query:o,variables:c});H({client:A,retries:u});const f=Object.entries({...r,...i}).reduce((y,[C,E])=>(y[C]=Array.isArray(E)?E.join(", "):E.toString(),y),{});return!f[U]&&!f[x]&&(f[U]=tt,f[x]=et),t([a??e,{method:"POST",headers:f,body:l,signal:d}],1,u??n)}}function ut(t){return async(...e)=>{if(L.test(e[0]))throw new Error(m("This operation will result in a streamable response - use requestStream() instead."));try{const r=await t(...e),{status:n,statusText:o}=r,s=r.headers.get("content-type")||"";return r.ok?s.includes(T.json)?G(r):{errors:{networkStatusCode:n,message:m(`${N} ${s}`),response:r}}:{errors:{networkStatusCode:n,message:m(o),response:r}}}catch(r){return{errors:{message:g(r)}}}}}async function*dt(t){const e=new TextDecoder;if(t.body[Symbol.asyncIterator])for await(const r of t.body)yield e.decode(r);else{const r=t.body.getReader();let n;try{for(;!(n=await r.read()).done;)yield e.decode(n.value)}finally{r.cancel()}}}function lt(t,e){return{async*[Symbol.asyncIterator](){try{let r="";for await(const n of t)if(r+=n,r.indexOf(e)>-1){const o=r.lastIndexOf(e),c=r.slice(0,o).split(e).filter(i=>i.trim().length>0).map(i=>i.slice(i.indexOf(V)+V.length).trim());c.length>0&&(yield c),r=r.slice(o+e.length),r.trim()==="--"&&(r="")}}catch(r){throw new Error(`Error occured while processing stream payload - ${g(r)}`)}}}}function ft(t){return{async*[Symbol.asyncIterator](){yield{...await G(t),hasNext:!1}}}}function pt(t){return t.map(e=>{try{return JSON.parse(e)}catch(r){throw new Error(`Error in parsing multipart response - ${g(r)}`)}}).map(e=>{const{data:r,incremental:n,hasNext:o,extensions:s,errors:c}=e;if(!n)return{data:r||{},...p("errors",c),...p("extensions",s),hasNext:o};const i=n.map(({data:a,path:u,errors:d})=>({data:a&&u?M(u,a):{},...p("errors",d)}));return{data:i.length===1?i[0].data:K([...i.map(({data:a})=>a)]),...p("errors",k(i)),hasNext:o}})}function ht(t,e){if(t.length>0)throw new Error(D,{cause:{graphQLErrors:t}});if(Object.keys(e).length===0)throw new Error(O)}function yt(t,e){var i,a;const r=(e??"").match(nt),n=`--${r?r[1]:"-"}`;if(!((i=t.body)!=null&&i.getReader)&&!((a=t.body)!=null&&a[Symbol.asyncIterator]))throw new Error("API multipart response did not return an iterable body",{cause:t});const o=dt(t);let s={},c;return{async*[Symbol.asyncIterator](){var u;try{let d=!0;for await(const l of lt(o,n)){const f=pt(l);c=((u=f.find(y=>y.extensions))==null?void 0:u.extensions)??c;const h=k(f);s=K([s,...f.map(({data:y})=>y)]),d=f.slice(-1)[0].hasNext,ht(h,s),yield{...p("data",s),...p("extensions",c),hasNext:d}}if(d)throw new Error("Response stream terminated unexpectedly")}catch(d){const l=q(d);yield{...p("data",s),...p("extensions",c),errors:{message:m(g(d)),networkStatusCode:t.status,...p("graphQLErrors",l==null?void 0:l.graphQLErrors),response:t},hasNext:!1}}}}}function mt(t){return async(...e)=>{if(!L.test(e[0]))throw new Error(m("This operation does not result in a streamable response - use request() instead."));try{const r=await t(...e),{statusText:n}=r;if(!r.ok)throw new Error(n,{cause:r});const o=r.headers.get("content-type")||"";switch(!0){case o.includes(T.json):return ft(r);case o.includes(T.multipart):return yt(r,o);default:throw new Error(`${N} ${o}`,{cause:r})}}catch(r){return{async*[Symbol.asyncIterator](){const n=q(r);yield{errors:{message:m(g(r)),...p("networkStatusCode",n==null?void 0:n.status),...p("response",n)},hasNext:!1}}}}}}function Et({client:t,storeDomain:e}){try{if(!e||typeof e!="string")throw new Error;const r=e.trim(),n=r.match(/^https?:/)?r:`https://${r}`,o=new URL(n);return o.protocol="https",o.origin}catch(r){throw new Error(`${t}: a valid store domain ("${e}") must be provided`,{cause:r})}}function X({client:t,currentSupportedApiVersions:e,apiVersion:r,logger:n}){const o=`${t}: the provided apiVersion ("${r}")`,s=`Currently supported API versions: ${e.join(", ")}`;if(!r||typeof r!="string")throw new Error(`${o} is invalid. ${s}`);const c=r.trim();e.includes(c)||(n?n({type:"Unsupported_Api_Version",content:{apiVersion:r,supportedApiVersions:e}}):console.warn(`${o} is likely deprecated or not supported. ${s}`))}function R(t){const e=t*3-2;return e===10?e:`0${e}`}function b(t,e,r){const n=e-r;return n<=0?`${t-1}-${R(n+4)}`:`${t}-${R(n)}`}function gt(){const t=new Date,e=t.getUTCMonth(),r=t.getUTCFullYear(),n=Math.floor(e/3+1);return{year:r,quarter:n,version:`${r}-${R(n)}`}}function wt(){const{year:t,quarter:e,version:r}=gt(),n=e===4?`${t+1}-01`:`${t}-${R(e+1)}`;return[b(t,e,3),b(t,e,2),b(t,e,1),r,n,"unstable"]}function St(t){return e=>({...e??{},...t.headers})}function At({getHeaders:t,getApiUrl:e}){return(r,n)=>{const o=[r];if(n&&Object.keys(n).length>0){const{variables:s,apiVersion:c,headers:i,retries:a}=n;o.push({...s?{variables:s}:{},...i?{headers:t(i)}:{},...c?{url:e(c)}:{},...a?{retries:a}:{}})}return o}}const Q="application/json",Rt="storefront-api-client",Ct="1.0.4",Tt="X-Shopify-Storefront-Access-Token",bt="Shopify-Storefront-Private-Token",vt="X-SDK-Variant",_t="X-SDK-Version",$t="X-SDK-Variant-Source",w="Storefront API Client";function It(t){if(t&&typeof window<"u")throw new Error(`${w}: private access tokens and headers should only be used in a server-to-server implementation. Use the public API access token in nonserver environments.`)}function Dt(t,e){if(!t&&!e)throw new Error(`${w}: a public or private access token must be provided`);if(t&&e)throw new Error(`${w}: only provide either a public or private access token`)}function Nt({storeDomain:t,apiVersion:e,publicAccessToken:r,privateAccessToken:n,clientName:o,retries:s=0,customFetchApi:c,logger:i}){const a=wt(),u=Et({client:w,storeDomain:t}),d={client:w,currentSupportedApiVersions:a,logger:i};X({...d,apiVersion:e}),Dt(r,n),It(n);const l=Ot(u,e,d),f={storeDomain:u,apiVersion:e,...r?{publicAccessToken:r}:{privateAccessToken:n},headers:{"Content-Type":Q,Accept:Q,[vt]:Rt,[_t]:Ct,...o?{[$t]:o}:{},...r?{[Tt]:r}:{[bt]:n}},apiUrl:l(),clientName:o},h=at({headers:f.headers,url:f.apiUrl,retries:s,customFetchApi:c,logger:i}),y=St(f),C=Ut(f,l),E=At({getHeaders:y,getApiUrl:C});return Object.freeze({config:f,getHeaders:y,getApiUrl:C,fetch:(...S)=>h.fetch(...E(...S)),request:(...S)=>h.request(...E(...S)),requestStream:(...S)=>h.requestStream(...E(...S))})}function Ot(t,e,r){return n=>{n&&X({...r,apiVersion:n});const o=(n??e).trim();return`${t}/api/${o}/graphql.json`}}function Ut(t,e){return r=>r?e(r):t.apiUrl}let B="",v=null;function xt(t,e,r){if(!(!t||!e))return v=Nt({storeDomain:e,apiVersion:"2024-04",publicAccessToken:t}),B=r?`@inContext(${Object.entries(r).map(([n,o])=>`${n}: ${o}`).join(",")})`:"",Pt}async function Pt(t){if(!t.length||!v)return[];const e=`#graphql query products ${B} { ${t.map((n,o)=>` product${o}: product(id: "${n.id}") { id variants(first: 15) { nodes { id price { amount currencyCode } compareAtPrice { amount currencyCode } } } } `).join()} }`,r=await v.request(e);return r!=null&&r.data?Object.values(r.data).map(n=>({id:n.id,variants:n.variants.nodes.map(o=>({id:o.id.toLowerCase(),price:Lt(o)}))})):[]}function Lt(t){var n;const e=+t.price.amount,r=+(((n=t.compareAtPrice)==null?void 0:n.amount)??0);return{value:e,originalValue:r,hasDiscount:r>e}}function jt(t){const e=Number.parseFloat(t.currency.rate??"1");return(r,n)=>[r*e,n*e]}async function Vt(){try{const t=await kt();if(!t.trigger_selector||!t.engine)return;await qt(t),await Z(t.engine.uuid,Shopify.locale)}catch(t){console.log("Error retrieving config:",t)}}async function qt(t){const e=typeof MotiveStorefrontToken<"u"?MotiveStorefrontToken:"";window.initX=function(){const n=xt(e,Shopify.shop,t.useContext?{country:Shopify.country}:void 0);return W(t.trigger_selector),{xEngineId:t.engine.uuid,lang:Shopify.locale,currency:Shopify.currency.active,triggerSelector:t.trigger_selector,isolated:!0,cartUrl:"/cart",variantAddToCart:"SINGLE",callbacks:{CartHandlerGettingCartInfo:()=>({productsCount:MotiveCartInfo.item_count}),UserClickedResultAddToCart:Ht,AppendedResultsChanged:n,RecommendationsChanged:n},...e&&{transformPriceRange:jt(Shopify)}}},await _(t.motive_x_url)}function Y(t){var e;return t.engine=(e=t.engines)==null?void 0:e.find(r=>r.locale===Shopify.locale&&r.countries.includes(Shopify.country)),t}async function kt(){if(typeof Motive<"u"&&Motive)return Y(Motive);const t={"x-store-name":Shopify.shop},r=await(await fetch("https://motive.api.motive.co/shopify/store/config",{headers:t})).json();return Y(r)}async function Ht(t,e={}){var d;const r=(d=t.variants)==null?void 0:d[0];if(!r)return;const n=r.id.replace(/\D/g,""),o=(e==null?void 0:e.quantity)??1,i={method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({items:[{id:n,quantity:o}],sections:"cart-icon-bubble,header"})},a=await fetch(`${Shopify.routes.root}cart/add.js`,i);if(!a.ok)throw new Error("Error adding item to cart.");const u=await a.json();MotiveCartInfo.item_count+=o,u.sections["cart-icon-bubble"]?J("#cart-icon-bubble",u.sections["cart-icon-bubble"]):u.sections.header&&J("#shopify-section-header",u.sections.header)}function J(t,e){const r=document.querySelector(t);r&&(r.innerHTML=e)}Vt()})();