"use strict";(function(){"use strict";if(window.__datewiseLoaded)return;window.__datewiseLoaded=!0;var x=document.querySelector("[data-datewise-config]"),m={};try{m=x?JSON.parse(x.textContent):{}}catch{m={}}var l=Object.assign({choose:"Pick a highlighted date",needTime:"Please choose a delivery or pickup time before checking out.",held:"Held for you for",expired:"Your hold expired. Tap the time again to check it's still free.",left:"left",full:"Full",postal:"Postal / ZIP code",check:"Check",waitlist:"Join the waitlist",joined:"You're on the waitlist. We'll message you if a place opens.",dispatch:"Ships this day (not an arrival date)",change:"Change",prep:"Earliest times include preparation for",free:"Free",fee:"fee",none:"No delivery or pickup times are available for this cart right now.",nextAvailable:"Next available",offer:"A place opened up and we're holding it for you",error:"Something went wrong. Please try again."},m.text||{}),N=(window.Shopify&&Shopify.routes&&Shopify.routes.root||"/").replace(/\/?$/,"/"),X=N+"apps/datewise",g=m.locale||document.documentElement.lang||"en",ee=m.currency||window.Shopify&&Shopify.currency&&Shopify.currency.active||"CAD",U="_datewise";function _(e){try{return localStorage.getItem("datewise_"+e)}catch{return null}}function w(e,t){try{t==null?localStorage.removeItem("datewise_"+e):localStorage.setItem("datewise_"+e,t)}catch{}}var a={data:null,cart:null,lines:[],loading:!1,message:null,messageTone:"info",method:_("method"),locationId:_("location"),postal:_("postal")||"",date:null,sel:null,token:_("token"),expiresAt:null,heldAt:null,monthOffset:0,waitlistDone:!1,mutating:0};function i(e){return String(e==null?"":e).replace(/[&<>"']/g,function(t){return{"&":"&","<":"<",">":">",'"':""","'":"'"}[t]})}function T(e){try{return new Intl.NumberFormat(g,{style:"currency",currency:ee}).format(e/100)}catch{return"$"+(e/100).toFixed(2)}}function b(e,t){return new Intl.DateTimeFormat(g,{weekday:t?"long":"short",month:t?"long":"short",day:"numeric",timeZone:"UTC"}).format(new Date(e+"T12:00:00Z"))}function j(e){var t=e.split(":");return new Intl.DateTimeFormat(g,{hour:"numeric",minute:t[1]==="00"?void 0:"2-digit",timeZone:"UTC"}).format(new Date(Date.UTC(2e3,0,1,+t[0],+t[1])))}function q(e){return j(e.start)+" \u2013 "+j(e.end)}function te(e,t){var n=+e.slice(0,4),r=+e.slice(5,7)-1+t;return n+=Math.floor(r/12),r=(r%12+12)%12,n+"-"+String(r+1).padStart(2,"0")}function ae(e){return new Date(Date.UTC(+e.slice(0,4),+e.slice(5,7),0)).getUTCDate()}var ne={pickup:'',delivery:'',shipping:''};function P(e){return'"}function re(e){return new Date(e+"T12:00:00Z").getUTCDay()}function S(e,t,n){var r=X+e,o={method:n||"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},credentials:"same-origin"};return t&&o.method!=="GET"&&(o.body=JSON.stringify(t)),L(r,o).then(function(d){return d.json().catch(function(){return{ok:!1,message:l.error}})})}function A(e,t){return a.mutating++,L(N+e,{method:t?"POST":"GET",headers:{"Content-Type":"application/json",Accept:"application/json"},body:t?JSON.stringify(t):void 0,credentials:"same-origin"}).then(function(n){return n.json()}).finally(function(){setTimeout(function(){a.mutating--},50)})}function F(){return A("cart.js").then(function(e){a.cart=e,a.lines=e.items.filter(function(r){return!(r.properties&&r.properties._datewise_fee)}).map(function(r){return{variantId:r.variant_id,quantity:r.quantity,price:r.final_price,title:r.product_title}});var t=e.attributes&&e.attributes[U];if(t)try{var n=JSON.parse(t);a.sel={method:n.m,locationId:n.l,date:n.d,slot:n.s,fee:n.f},a.token=n.t,w("token",n.t),a.method=a.method||n.m,a.locationId=a.locationId||n.l,a.date=a.date||n.d}catch{a.sel=null}else a.sel=null;return e})}function ie(){return(a.cart?a.cart.items:[]).filter(function(e){return e.properties&&e.properties._datewise_fee})}function R(e){var t=ie(),n=Promise.resolve(),r=null;t.forEach(function(d){!r&&e&&String(d.variant_id)===String(e)&&d.quantity===1?r=d:n=n.then(function(){return A("cart/change.js",{id:d.key,quantity:0})})}),e&&!r&&(n=n.then(function(){return A("cart/add.js",{items:[{id:Number(e),quantity:1,properties:{_datewise_fee:"1"}}]})}));var o=t.length!==(r?1:0)||e&&!r;return n.then(function(){return o})}function B(e){var t=[];try{t=JSON.parse(_("keys")||"[]")}catch{}var n={};return t.forEach(function(r){n[r]=""}),Object.keys(e).forEach(function(r){n[r]=e[r]}),w("keys",JSON.stringify(Object.keys(e))),A("cart/update.js",{attributes:n})}function H(e){var t={source:"datewise"};["cart:refresh","cart:updated","cart:change","theme:cart:change"].forEach(function(n){document.dispatchEvent(new CustomEvent(n,{detail:t,bubbles:!0}))}),typeof window.publish=="function"&&window.PUB_SUB_EVENTS?F().then(function(n){window.publish(window.PUB_SUB_EVENTS.cartUpdate,{source:"datewise",cartData:n})}):e&&/\/cart\/?$/.test(location.pathname)&&setTimeout(function(){location.reload()},300)}function M(e){var t=a.token;return a.sel=null,a.expiresAt=null,e&&p(e,"critical"),t&&S("/release",{token:t}).catch(function(){}),B({[U]:""}).then(function(){return R(null)}).then(function(n){w("keys","[]"),n&&H(!0)})}var Z=null;function h(e){clearTimeout(Z),Z=setTimeout(G,e?0:300)}function G(){return!C().length&&!m.checkoutGuard?Promise.resolve():(a.loading=!0,f(),F().then(function(){if(!a.lines.length){a.data=null,a.loading=!1,a.sel&&M(null),f();return}return S("/availability",{lines:a.lines,method:a.method||void 0,locationId:a.locationId||void 0,postal:a.postal||void 0,token:a.token||void 0,locale:g}).then(function(e){if(a.loading=!1,!e||e.ok===!1){p(e&&e.message||l.error,"critical"),f();return}a.data=e,a.method=e.method,a.locationId=e.locationId,se(),f()})}).catch(function(){a.loading=!1,p(l.error,"critical"),f()}))}function oe(e,t){var n=a.data&&a.data.dates.filter(function(r){return r.date===e})[0];return{d:n,s:n&&n.slots.filter(function(r){return r.id===t})[0]}}function se(){if(a.sel){var e=a.data;if(!e||e.method!==a.sel.method||e.locationId!==a.sel.locationId)return M(null);var t=oe(a.sel.date,a.sel.slot);if(!t.s||!t.s.available){var n=t.s&&t.s.reason||t.d&&t.d.reasons[0]||"";M(n?n+". "+l.choose+".":l.choose)}}}function J(e,t){if(a.data)return p(null),a.loading=!0,f(),S("/hold",{lines:a.lines,method:a.data.method,locationId:a.data.locationId,date:e,slot:t,token:a.token||void 0,postal:a.postal||void 0,locale:g}).then(function(n){if(!n.ok){a.loading=!1,p(n.message||l.error,"critical"),h(!0);return}return a.token=n.token,w("token",n.token),a.expiresAt=Date.parse(n.expiresAt),a.heldAt=Date.now(),a.sel={method:a.data.method,locationId:a.data.locationId,date:e,slot:t,fee:n.fee?n.fee.fee:0},B(n.attributes).then(function(){return R(n.feeVariantId)}).then(function(r){a.loading=!1,f(),H(r)})}).catch(function(){a.loading=!1,p(l.error,"critical"),f()})}function p(e,t){a.message=e,a.messageTone=t||"info"}function C(){return Array.prototype.slice.call(document.querySelectorAll("[data-datewise-root]"))}function f(){C().forEach(V)}function V(e){e.classList.contains("datewise")||e.classList.add("datewise");var t=a.data,n=e.getAttribute("data-heading")||t&&t.text&&t.text.heading||"";t&&t.text&&t.text.accent&&e.style.setProperty("--dw-accent",t.text.accent);var r="";if(n&&(r+='