const t=t=>t?Array.isArray(t)?t:[t]:[],e=window.productDualSaleRushFeeVariantID?window.productDualSaleRushFeeVariantID:window.defaultDualSaleRushFeeVariantID,r=window.dualSaleRushOptionName,n="_original_variant_id",o="_PROMISED_BY_DATE",a={ADD_ITEM:"cart:addItem",REMOVE_ITEM:"cart:removeItem",UPDATE_ITEM_QUANTITY:"cart:updateItemQuantity",RUSH_FEE_SYNC_COMPLETE:"cart:rushFeeSyncComplete",OPEN_CART:"cart:open",CART_DATA_UPDATED:"cart:dataUpdated"},i=async t=>{const{shop:e}=window.Shopify,{storefrontApiAccessToken:r,storefrontApiVersion:n}=(()=>{const{shop:t}=window.Shopify,e="birdygrace.myshopify.com"===t?"production":"development",{platform_url:r,storefront_api_token:n,storefront_api_version:o}={development:{platform_url:"https://platform.birdystaging.com/api",storefront_api_token:"a7cd863c8179b07652150b5bb739a07b",storefront_api_version:"2025-07"},production:{platform_url:"https://platform.birdygrey.com/api",storefront_api_token:"1a8f4e31c69ef2d8fe9c05d65c8c8f0e",storefront_api_version:"2025-07"}}[e];return{platformURL:r,storefrontApiAccessToken:n,storefrontApiVersion:o}})(),o=r,a=`https://${e}/api/${n}/graphql.json`,i=`\n query {\n product(handle: "${t}") {\n metafield(namespace: "custom", key: "production_days") {\n value\n }\n }\n }\n `,s=await fetch(a,{method:"POST",headers:{"Content-Type":"application/json","X-Shopify-Storefront-Access-Token":o},body:JSON.stringify({query:i})});if(!s.ok)throw new Error(s.message||s.statusText||s.status);const c=await s.json();if(c.errors){const t=c.errors.map((t=>t.message)).join(", ");throw new Error(`Error during getProductionDays from graphQL request: ${t}`)}const d=c?.data?.product?.metafield?.value;return d},s=t=>{const e=Math.floor(Date.now()/1e3)+24*parseInt(t,10)*60*60,r=new Date(1e3*e);return`${(r.getMonth()+1).toString().padStart(2,"0")}-${r.getDate().toString().padStart(2,"0")}-${r.getFullYear()}`};window.fetchAjaxCart=()=>fetch("/cart.js").then((async t=>{let e={};if((t.headers.get("content-type")?.includes("json")||t.headers.get("content-type")?.includes("javascript"))&&(e=await t.json()),!t.ok)throw new Error(e.message||t.statusText||t.status);const r=await(async t=>{const{items:e}=t,r=await Promise.all(e.map((async t=>{if(!Boolean(t.properties?.["_MADE-TO-ORDER"]))return t;let e=await i(t.handle);const r=t.product_title.toLowerCase();if(!e&&r.includes("matte satin")){const t="63";e=window.daysDelayedMatteSatin||t}else if(!e){const t="56";e=window.daysDelayedMto||t}const n=parseInt(e,10)-7,a=`${s(n)} and ${s(e)}`;if(t.properties[o]&&t.properties[o]!==a)try{const e=await fetch("/cart/change.js",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({id:t.key,properties:{...t.properties,_PROMISED_BY_DATE:a}})}),r=(await e.json()).items.find((e=>e.id===t.id));if(r)return r}catch(t){console.error("Error updating cart:",t)}return t})));return{...t,items:r}})(e);return window.cart=r,r})).catch((t=>{throw new Error(`Fetch error during getCart: ${t.message}`)}));const c=(e,r)=>{if(!r)return window.dispatchEvent(new CustomEvent(a.RUSH_FEE_SYNC_COMPLETE)),!1;const{variantId:o,cart:i,quantity:s}=e,c=((t,e)=>t&&t.items?t.items.find((t=>t.properties&&t.properties[n]===Number(e))):null)(i,o);return c?(async e=>{try{const n=await fetch("/cart/update.js",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({updates:(r=t(e),!!Array.isArray(r)&&r.reduce(((t,e)=>{if(Object.prototype.hasOwnProperty.call(e,"key"))return t[e.key]=e.quantity,t;throw Error("missing `key` name in property")}),{}))})});if(!n.ok){const t=await n.json();throw new Error(t.message||n.statusText||n.status)}return window.dispatchEvent(new CustomEvent(a.RUSH_FEE_SYNC_COMPLETE)),n}catch(t){return console.error(t)}var r})({key:c.key,quantity:s}):(window.dispatchEvent(new CustomEvent(a.RUSH_FEE_SYNC_COMPLETE)),!1)},d=(e,o,i)=>{if(!o||0===e.length)return window.dispatchEvent(new CustomEvent(a.RUSH_FEE_SYNC_COMPLETE,{detail:i})),!1;const s=e.find((t=>t.variant_options.includes(r)));if(s){const e=((t,e)=>{const o={};if(Object.prototype.hasOwnProperty.call(t,"product_title")&&(o._productName=t.product_title,o._productNameWithoutColor=t.product_title.split("-")[0].trim()),Object.prototype.hasOwnProperty.call(t,"variant_options")){const e=t.variant_options.filter((t=>t.trim()!==r)).join(" / ");o._variantNameWithoutArrival=e.trim()}return Object.prototype.hasOwnProperty.call(t,"variant_title")&&(o._variantName=t.variant_title),e&&(o[n]=t.id),{id:e,quantity:1,properties:{...o}}})(s,o);return(async(e,r)=>{try{const n=await fetch("/cart/add.js",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({items:t(e)})});if(!n.ok){const t=await n.json();throw new Error(t.message||n.statusText||n.status)}return window.dispatchEvent(new CustomEvent(a.RUSH_FEE_SYNC_COMPLETE,{detail:r})),n}catch(t){return console.error(t)}})(e,i)}return window.dispatchEvent(new CustomEvent(a.RUSH_FEE_SYNC_COMPLETE,{detail:i})),!1},p=t=>{const e=t.match(/([a-zA-Z0-9]+)(?=\?)/);return e?e[0]:null},u="coreCart",l=(t,e,r=30)=>{const n={cartId:t,updated:(new Date).toUTCString(),...e},o=JSON.stringify(n),a=`${u}=${o.trim()};`,i=new Date;i.setDate(i.getDate()+r);const s=a+`expires=${i.toUTCString()};`+"path=/;"+`Domain=${(()=>{const{hostname:t}=window.location;return"127.0.0.1"===t||"localhost"===t?t:t.split(".").slice(1).join(".")})()};`;document.cookie=s},w=()=>(t=>{const e=new RegExp(String.raw`${t}=(\{.*?\})`),r=document.cookie.match(e);if(r){const e=r[1];try{return JSON.parse(e)}catch(e){console.error(`Unable to parse ${t} cookie`,e)}}return null})(u);window.addEventListener(a.ADD_ITEM,(({detail:t})=>{const{data:{addToCartResponse:r}}=t,{items:n}=r,o=n.find((t=>t?.variant_title?.includes("Rush")||t?.variant_options?.some((t=>t.includes("Rush")))));if(e&&o){const e=document.getElementById("rush-fee-variant")?.dataset,{rushVariantId:r,defaultRushVariantId:o}=e;d(n,""!==r?r:o,t)}else window.dispatchEvent(new CustomEvent(a.RUSH_FEE_SYNC_COMPLETE,{detail:t}))})),window.addEventListener(a.REMOVE_ITEM,(({detail:t})=>{c(t.data,e)})),window.addEventListener(a.UPDATE_ITEM_QUANTITY,(({detail:t})=>{c(t.data,e)})),window.addEventListener(a.RUSH_FEE_SYNC_COMPLETE,(async({detail:t})=>{try{const e=window.cart,r={...t,cart:e};window.dispatchEvent(new CustomEvent(a.CART_DATA_UPDATED,{detail:r}))}catch(t){console.error("Error during cart sync event:",t)}})),window.addEventListener(a.CART_DATA_UPDATED,(async({detail:t})=>{const{cart:e}=t,{token:r,item_count:n}=e,o=p(r);if(!o)return;l(o,{hasItemsInCart:n>0})})),window.onload=()=>{const t=w();if(!t?.cartId)return;const{cart:e}=window,r=t.cartId||p(e?.token);r&&t.cartId===r||(document.cookie=`${u}=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;`)};export{d as addFeeProduct,a as eventNames,c as updateFeeProductQuantity}; //# sourceMappingURL=cart--events.min.js.map