const t=()=>{const{shop:t}=window.Shopify,e="birdygrace.myshopify.com"===t?"production":"development",{platform_url:r,storefront_api_token:n,storefront_api_version:a}={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:a}},e="\n field\n message\n",r="\n id\n createdAt\n updatedAt\n totalQuantity\n checkoutUrl\n lines(first: 50) {\n edges {\n node {\n id\n quantity\n merchandise {\n ... on ProductVariant {\n \n id\n title\n sku\n image {\n url\n }\n compareAtPrice {\n amount\n }\n selectedOptions {\n name\n value\n }\n availableForSale\n product {\n \n id\n title\n productType\n vendor\n isGiftCard\n onlineStoreUrl\n featuredImage {\n url\n id\n width\n height\n altText\n }\n tags\n images(first: 5) {\n edges {\n node {\n url\n }\n }\n }\n\n }\n price {\n amount\n }\n\n }\n }\n attributes {\n key\n value\n }\n discountAllocations {\n discountedAmount {\n amount\n }\n targetType\n }\n }\n }\n }\n attributes {\n key\n value\n }\n discountCodes {\n code\n applicable\n }\n discountAllocations {\n discountedAmount {\n amount\n }\n }\n cost {\n totalAmount {\n amount\n currencyCode\n }\n subtotalAmount {\n amount\n currencyCode\n }\n }\n",n='\n mutation CreateCart {\n cartCreate(input: {attributes: {key: "_cart_type",value: "storefront_api"}}) {\n cart {\n checkoutUrl\n id\n attributes {\n key\n value\n }\n }\n }\n }\n',a=t=>`\n query {\n cart(\n id: "${t}"\n ) {\n ${r}\n }\n }\n `,i=`\n mutation AddLinesToCart($cartId: ID!, $lines: [CartLineInput!]!) {\n cartLinesAdd(cartId: $cartId, lines: $lines) {\n cart {\n ${r}\n }\n userErrors {\n ${e}\n }\n }\n }\n`,o=`\n mutation cartLinesRemove($cartId: ID!, $lineIds: [ID!]!) {\n cartLinesRemove(cartId: $cartId, lineIds: $lineIds) {\n cart {\n ${r}\n }\n userErrors {\n ${e}\n }\n }\n }\n`,s=`\n mutation cartLinesUpdate($cartId: ID!, $lines: [CartLineUpdateInput!]!) {\n cartLinesUpdate(cartId: $cartId, lines: $lines) {\n cart {\n ${r}\n }\n userErrors {\n ${e}\n }\n }\n }\n `,c="_original_variant_id",d="_source",u="THEME",l=t=>{let e=Array.isArray(t)?[]:{};return(r=t)&&r.constructor===Object||function(t){return t&&t.constructor===Array}(t)?(Object.keys(t).forEach((r=>{e="string"==typeof r&&"edges"===r?l(t.edges.map((t=>t.node))):Object.assign(e,{[r]:l(t[r])})})),e):t;var r},p=t=>{const e=t.map((t=>{if(t.key&&t.value)return{key:t.key,value:t.value};const e=Object.keys(t)[0];return{key:e,value:t[e]}}));return e.push({key:d,value:u}),e},m=t=>{const{attributes:e,checkoutUrl:r,cost:n,discountCodes:a,id:i,lines:o,totalQuantity:s}=t,c=t=>100*Math.floor(Number(t?.amount)),d=o?l(o).map((t=>{const{attributes:e,id:r,merchandise:n,quantity:a,discountAllocations:i}=t,{title:o,compareAtPrice:s,price:d,product:u,selectedOptions:l,sku:p,id:m}=n,y=(t=>{const{discountedAmount:e}=t[0]||[];return c(e)||null})(i),h=c(d),f=c(s)||null,w=u?.vendor?.toLowerCase(),g=w?.includes("birdy grey suits")?handleize(u?.title):(_=u?.onlineStoreUrl,_.split("/products/")[1]);var _;const v=e.reduce(((t,e)=>(t[e.key]=e.value,t)),{});return{key:r,id:n.id,quantity:a,properties:v,title:o,tags:u.tags,vendor:u.vendor,product_title:u.title,variant_title:o,variant_options:[l.map((t=>t.value))],variant_id:n.id,price:h,original_price:h,discounted_price:f,line_price:f,final_price:f,final_line_price:h*a-y,original_line_price:h*a,total_discount:y,sku:p,product_id:m,product_type:u.productType,gift_card:u.isGiftCard,url:`/products/${g}`,image:u?.featuredImage?.url,featured_image:{height:u?.featuredImage?.height,width:u?.featuredImage?.width,altText:u?.featuredImage?.altText},options_with_values:l,handle:g}})):[];return{checkoutUrl:r,attributes:e,currency:n?.totalAmount.currencyCode,item_count:s,items:d,items_subtotal_price:c(n.subtotalAmount),original_total_price:c(n.totalAmount),requires_shipping:!0,token:i,total_discount:a,total_price:c(n.totalAmount)}},y=(t,e,r=30)=>{const n=new Date;n.setTime(n.getTime()+24*r*60*60*1e3);const a=`expires=${n.toUTCString()}`,i=`Domain=${getRootDomain()};`;document.cookie=`${t}=${e};${a};path=/;${i}`},h=t=>{const e=`${t}=`,r=decodeURIComponent(document.cookie).split(";");for(let t=0;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()}`},k=async e=>{const{items:r}=e,n=await Promise.all(r.map((async e=>{if(!Boolean(e.properties?.["_MADE-TO-ORDER"]))return e;let r=await(async e=>{const{shop:r}=window.Shopify,{storefrontApiAccessToken:n,storefrontApiVersion:a}=t(),i=n,o=`https://${r}/api/${a}/graphql.json`,s=`\n query {\n product(handle: "${e}") {\n metafield(namespace: "custom", key: "production_days") {\n value\n }\n }\n }\n `,c=await fetch(o,{method:"POST",headers:{"Content-Type":"application/json","X-Shopify-Storefront-Access-Token":i},body:JSON.stringify({query:s})});if(!c.ok)throw new Error(c.message||c.statusText||c.status);const d=await c.json();if(d.errors){const t=d.errors.map((t=>t.message)).join(", ");throw new Error(`Error during getProductionDays from graphQL request: ${t}`)}const u=d?.data?.product?.metafield?.value;return u})(e.handle);const n=e.product_title.toLowerCase();if(!r&&n.includes("matte satin")){const t="63";r=window.daysDelayedMatteSatin||t}else if(!r){const t="56";r=window.daysDelayedMto||t}const a=parseInt(r,10)-7,i=`${v(a)} and ${v(r)}`;if(e.properties[f]&&e.properties[f]!==i)try{const t=await fetch("/cart/change.js",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({id:e.key,properties:{...e.properties,_PROMISED_BY_DATE:i}})}),r=(await t.json()).items.find((t=>t.id===e.id));if(r)return r}catch(t){console.error("Error updating cart:",t)}return e})));return{...e,items:n}};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 k(e);return window.cart=r,r})).catch((t=>{throw new Error(`Fetch error during getCart: ${t.message}`)}));const b=(t,e,r=30)=>{const n={cartId:t,updated:(new Date).toUTCString(),...e},a=`coreCart=${JSON.stringify(n).trim()};`,i=new Date;i.setDate(i.getDate()+r);const o=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=o},C=t=>{b(h("cart-token"),{hasItemsInCart:t.items.length>0}),window.cart=t},I=async({query:e,variables:r})=>{const{shop:n}=window.Shopify,{storefrontApiAccessToken:a,storefrontApiVersion:i}=t(),o=a,s=`https://${n}/api/${i}/graphql.json`;try{const t=await fetch(s,{method:"POST",headers:{"Content-Type":"application/json","X-Shopify-Storefront-Access-Token":o},body:JSON.stringify({query:e,variables:r})});if(!t.ok)return console.error(t);const{data:n}=await t.json();return n}catch(t){return console.error("Error in sending Storefront API request",t),{statusCode:500,body:JSON.stringify({message:"Error in sending Storefront API request"})}}},A=async()=>{try{const t=await I({query:n});if(t?.cartCreate){const{id:e}=t.cartCreate.cart,r=e.split("/Cart/").pop();return y("cart-token",r),r}setTimeout((async()=>{const t=await I({query:n}),{id:e}=t.cartCreate.cart,r=e.split("/Cart/").pop();return y("cart-token",r),r}),500)}catch(t){return console.error("Error creating cart:",t),{statusCode:500,body:JSON.stringify({message:"There was a problem creating a cart."})}}},$=async()=>{try{const t=h("cart-token")&&`gid://shopify/Cart/${h("cart-token")}`;if(!t&&!window.location.hostname.includes("myshopify"))return await A(),void await $();const e=await I({query:a(t)});if(!e.cart&&!window.location.hostname.includes("myshopify"))return y("cart-token","",-1),await A(),void await $();const r=m(e.cart);return y("cart-checkout",r.checkoutUrl),window.cart=r,r}catch(t){return console.error("Error fetching storefront cart:",t),{statusCode:500,body:JSON.stringify({message:"There was an error fetching the cart.",error:t.message})}}},T=async(t,e)=>{try{const r=window.cart.token,n=document.getElementById("rush-fee-variant"),{rushVariantId:a,defaultRushVariantId:o}=n?.dataset||{},{id:d,product_title:u,variant_title:l,variant_options:y,key:h,properties:f}=t,w=[{_productName:u},{_original_variant_id:d},{_productNameWithoutColor:u.split("-")[0]},{_variantName:l},{_variantNameWithoutArrival:y.flat().filter((t=>!t.includes("Rush Production"))).join(" / ")}],g={cartId:r,lines:[{merchandiseId:`gid://shopify/ProductVariant/${a||o}`,quantity:e,attributes:p(w)}]},_=await I({query:i,variables:g}),v=m(_.cartLinesAdd.cart).items.find((t=>t.properties[c]&&t.properties[c]===d)),k=p([f]);k.push({key:"_rush_fee_amount",value:JSON.stringify(v.price/100)});const b=await I({query:s,variables:{cartId:r,lines:[{id:h,merchandiseId:d,attributes:k}]}});return m(b.cartLinesUpdate.cart)}catch(t){console.error("Error adding rush fee to dual sale item:",t)}},E=async(t,e)=>{try{const r=e,{merchandiseId:n,attributes:a,quantity:o}=t.lines[0],s=window.cart.token,c=r.innerHTML,d=r?.dataset?.location?.includes("utm swatch carousel");r.innerHTML="Adding …";const u=a.some((t=>"mini-cart"===t.value||"quick-add"===t.value))?`gid://shopify/ProductVariant/${n}`:n,l={cartId:s,lines:[{merchandiseId:u,quantity:o,attributes:p(a)}]};let y=await I({query:i,variables:l});if(!y.cartLinesAdd.cart&&y.cartLinesAdd.userErrors){const t=document.querySelector(".atc-error-message-container"),e=document.querySelector("#atc-error-message");return t&&(e.innerText=y.cartLinesAdd.userErrors[0].message,t.classList.remove("hidden"),r.innerText="Error. Try again!",setTimeout((()=>{r.innerText="Add to Bag"}),2500)),console.error("Error adding to cart.")}let h=m(y.cartLinesAdd.cart);const f={items:[h.items.find((t=>t.id===u))]},g=f.items.find((t=>t.variant_title.includes("Rush Production")));g&&(h=await T(g,o));let _="Add to Bag";f.items[0].properties&&("PREORDER"in f.items[0].properties||"_PREORDER"in f.items[0].properties)?_="Add to Bag":d&&(_=c),r.classList.contains("add-color-swatch")&&(r.innerText="GET COLOR SWATCH"),r.id&&"personalization-atc"===r.id&&window.closePersonalizationModal(),r.innerHTML=_;let v=null;if(r.classList.contains("quick-atc")){const{dataset:t}=r;v={Name:t.atcName,ProductID:t.atcProductid,Categories:t.atcCategories,ImageURL:t.atcImageurl,URL:t.atcUrl,Brand:t.atcBrand,Price:t.atcPrice,CompareAtPrice:t.atcCompareatprice,QuickATC:!0}}return r.dispatchEvent(new Event("cartChange",{bubbles:!0})),window.dispatchEvent(new CustomEvent(w,{detail:{data:{addToCartResponse:f,klaviyoProduct:v},action:"add"}})),C(h),h}catch(t){return console.error("Error adding to storefront cart:",t),{statusCode:500,body:JSON.stringify({message:t.message||"There was a problem adding product to cart."})}}},S=async t=>{try{const e=window.cart.token,r=[t.id],n=window.cart.items.find((e=>e.properties[c]===t.variantId&&e.product_title.includes("Rush")));n&&r.push(n.key);const a={cartId:e,lineIds:r},i=await I({query:o,variables:a}),s=m(i.cartLinesRemove.cart);return window.dispatchEvent(new CustomEvent(g,{detail:{data:{id:t.id,quantity:0,cart:s}}})),C(s),s}catch(t){return console.error("Error adding to storefront cart:",t),{statusCode:500,body:JSON.stringify({message:t.message||"There was a problem adding product to cart."})}}},q=async t=>{try{const{cart:e}=window,{type:r,variantId:n,key:a}=t.dataset,i=document.getElementById(`${t.dataset.keyPrefix}availability-error-${t.dataset.key}`),o=e.items.find((t=>t.key===a)),d="increment"===r?o.quantity+1:o.quantity-1,u={cartId:e.token,lines:[{id:a,merchandiseId:n,quantity:d}]};if(o.variant_title.includes("Rush Production")){const t=e.items.find((t=>t.product_title.includes("Rush Fee")&&t.properties[c]===o.id)),{id:r,key:n}=t;u.lines.push({id:n,merchandiseId:r,quantity:d})}const l=await I({query:s,variables:u});if(l.cartLinesUpdate.userErrors.length>0&&l.cartLinesUpdate.userErrors[0].field.includes("quantity"))return void i.classList.remove("hidden");const p=m(l.cartLinesUpdate.cart);return window.dispatchEvent(new CustomEvent(_,{detail:{cart:p}})),C(p),p}catch(t){return console.error("Error updating cart item in storefront cart:",t),{statusCode:500,body:JSON.stringify({message:t.message||"There was a problem updating cart item in cart."})}}},L=async()=>{const t=`gid://shopify/Cart/${h("cart-token")||await A()}`,e=await fetch("/cart.js").then((t=>t.json()));if(e.items.length>0){const r={cartId:t,lines:e.items.map((t=>{return{merchandiseId:`gid://shopify/ProductVariant/${t.variant_id}`,quantity:t.quantity,attributes:t.properties?[...(e=t.properties,Object.entries(e||{}).map((([t,e])=>({key:t,value:t===c?`gid://shopify/ProductVariant/${e}`:String(e)})))),{key:"_ajax_line_key",value:t.key}]:null};var e}))};try{const t=await I({query:i,variables:r}),e=m(t.cartLinesAdd.cart);C(e),await window.buildMiniCart();try{const t=await fetch("/cart/clear",{method:"POST"});if(!t.ok)return void console.error(`Error clearing cart: ${t.status} ${t.statusText}`);await t.json().catch((()=>null))}catch(t){console.error("Network error clearing AJAX cart:",t)}}catch(t){console.error("Error handling AJAX to Storefront conversion:",t)}}await $()},P=async()=>{await L(),window.buildMiniCart()},O=async()=>{await P(),await(async t=>{let e=!1;try{const r=t.items.map((async r=>{if(r.product_title.includes("Rush Fee")){const{key:n,id:a,quantity:i}=r,o=r.properties[c],d=t.items.find((t=>t.id===o))?.quantity;if(i!==d){const r={cartId:t.token,lines:[{id:n,merchandiseId:a,quantity:d||0}]};await I({query:s,variables:r})&&(e=!0)}}}));if(await Promise.all(r),e){const t=new URL(window.location.href);t.searchParams.set("_",(new Date).getTime()),window.location.replace(t.toString())}}catch(t){console.error("Error auditing items in the cart:",t)}})(window.cart)};window.cart||O(),window.fetchStorefrontCart=$,window.addToStorefrontCart=E,window.removeFromStorefrontCart=S,window.updateCartLine=q,window.setGlobalCart=P;export{T as addRushFee,E as addToStorefrontCart,$ as fetchStorefrontCart,L as handleAjaxCart,S as removeFromStorefrontCart,I as sendStorefrontRequest,q as updateCartLine}; //# sourceMappingURL=cart--api.min.js.map