diff --git a/app/routes/app.locations.$id.tsx b/app/routes/app.locations.$id.tsx
index d2e8b3d..7ddfb24 100644
--- a/app/routes/app.locations.$id.tsx
+++ b/app/routes/app.locations.$id.tsx
@@ -60,6 +60,11 @@ export const action = async ({ request, params }: ActionFunctionArgs) => {
if (intent === "basics") {
const lat = formString(fd, "lat");
const lng = formString(fd, "lng");
+ if (formBool(fd, "enabled") && !row.enabled) {
+ const on = cfg.locations.filter((l) => l.enabled && l.id !== row.id).length;
+ if (on >= features.maxLocations)
+ return { ok: false, message: `Your plan takes bookings at ${features.maxLocations} location${features.maxLocations === 1 ? "" : "s"}. Switch another location off, or upgrade in Settings.` };
+ }
await save({
name: formString(fd, "name") || "Location",
address: formString(fd, "address"),
diff --git a/app/services/storefront.server.ts b/app/services/storefront.server.ts
index 60626f2..b220c0c 100644
--- a/app/services/storefront.server.ts
+++ b/app/services/storefront.server.ts
@@ -59,7 +59,8 @@ async function context(domain: string, admin: AdminGraphql | undefined, q: z.inf
const today = localParts(now, cfg.shop.timezone).date;
const usage = await reservations.usage(cfg.shop.id, addDays(today, -1), addDays(today, 370), new Date(now), q.token);
const f = features(cfg.shop.plan);
- const locations = cfg.locations.slice(0, f.maxLocations);
+ // The plan limit counts locations that are switched on (imported ones start off), in priority order.
+ const locations = cfg.locations.filter((l) => l.enabled).slice(0, f.maxLocations);
return { cfg, now, cart, inventory, feeLines, address, usage, locations, f };
}
diff --git a/extensions/datewise-widget/assets/datewise.js b/extensions/datewise-widget/assets/datewise.js
index a508558..5cd0474 100644
--- a/extensions/datewise-widget/assets/datewise.js
+++ b/extensions/datewise-widget/assets/datewise.js
@@ -1 +1 @@
-"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",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 Z(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 C(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&&Z(!0)})}var G=null;function h(e){clearTimeout(G),G=setTimeout(H,e?0:300)}function H(){return!M().length&&!m.checkoutGuard?Promise.resolve():(a.loading=!0,f(),F().then(function(){if(!a.lines.length){a.data=null,a.loading=!1,a.sel&&C(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 C(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]||"";C(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(),Z(r)})}).catch(function(){a.loading=!1,p(l.error,"critical"),f()})}function p(e,t){a.message=e,a.messageTone=t||"info"}function M(){return Array.prototype.slice.call(document.querySelectorAll("[data-datewise-root]"))}function f(){M().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+='
'+i(n)+"
"),r+=''+(a.message?'
'+i(a.message)+"
":"")+"
",!t){e.innerHTML=r+(a.loading?'':""),e.setAttribute("aria-busy",a.loading);return}if(r+='',t.methods.forEach(function(s){var v=s.method===t.method;r+='"}),r+="
",!t.method){e.innerHTML=r;return}if(t.method==="delivery"&&(r+='"),t.split&&(r+=''+i(t.split)+"
"),t.method!=="shipping"&&t.locations.length>1)r+='',t.locations.forEach(function(s){var v=s.id===t.locationId,O=s.fee?s.fee.waived?l.free:T(s.fee.fee):s.distanceKm!=null?s.distanceKm+" km":"";r+='"}),r+="
";else if(t.locationId){var o=t.locations.filter(function(s){return s.id===t.locationId})[0];o&&t.method!=="shipping"&&(r+=''+i(o.name)+(o.fee?" \xB7 "+(o.fee.waived?l.free:T(o.fee.fee)+" "+l.fee):"")+"
")}if(!t.locationId){if(t.needsAddress){e.innerHTML=r;return}var d=t.locations[0]&&t.locations[0].reason;e.innerHTML=r+(d?''+i(d)+"
":"");return}t.prepNote&&t.prepNote.minutes>=60&&(r+=''+i(l.prep+" "+t.prepNote.item)+" ("+Math.round(t.prepNote.minutes/6)/10+" h)
");var c=t.dates.filter(function(s){return s.peak&&s.peak.message})[0];c&&(r+=''+i(c.peak.message)+"
"),r+=de(t),r+=ce(t,e),e.innerHTML=r,e.setAttribute("aria-busy",a.loading),z()}var le=0;function $(e){return e.__dwid||(e.__dwid=++le),e.__dwid}function de(e){var t={};e.dates.forEach(function(D){t[D.date]=D});var n=(e.dates.filter(function(D){return D.available})[0]||e.dates[0]||{}).date;if(!n)return"";for(var r=te(n.slice(0,7),a.monthOffset),o=e.text.weekStartsOn||0,d=r+"-01",c=(re(d)-o+7)%7,s=''+i(new Intl.DateTimeFormat(g,{month:"long",year:"numeric",timeZone:"UTC"}).format(new Date(d+"T12:00:00Z")))+'
',v=0;v<7;v++){var O=(o+v)%7;s+=''+i(new Intl.DateTimeFormat(g,{weekday:"narrow",timeZone:"UTC"}).format(new Date(Date.UTC(2023,0,1+O))))+""}for(var W=0;W";for(var I=1;I<=ae(r);I++){var k=r+"-"+String(I).padStart(2,"0"),u=t[k],y="dw-day",E=b(k,!0),Q="";u?u.available?(y+=" dw-avail",e.text.showRemaining&&u.remaining!=null&&u.remaining<=5&&(Q=''+u.remaining+"")):u.waitlist||/full|booked/i.test(u.reasons[0]||"")?(y+=" dw-full",E+=", "+l.full):(y+=" dw-closed",E+=", "+(u.reasons[0]||"")):y+=" dw-out",a.date===k&&(y+=" dw-sel"),u&&u.peak&&(y+=" dw-peakday",E+=", "+u.peak.name),s+='"}return s+"
"}function ce(e,t){if(!a.date)return''+i(l.choose)+"
";var n=e.dates.filter(function(o){return o.date===a.date})[0];if(!n)return"";var r=''+i(b(n.date,!0))+(n.peak?' '+i(n.peak.name)+"":"")+"
";return e.dateOnly&&(r+='
'+i(l.dispatch)+"
"),n.available?(r+='
',n.slots.forEach(function(o){var d=a.sel&&a.sel.date===n.date&&a.sel.slot===o.id,c=o.available?(e.text.showRemaining&&o.remaining!=null?o.remaining+" "+l.left:"")+(o.surcharge?(o.remaining!=null&&e.text.showRemaining?" \xB7 ":"")+"+"+T(o.surcharge):""):o.reason||"";r+='"}),r+="
",a.sel&&a.sel.date===n.date&&(r+=ue(e,n)),r+"
"):(r+=''+i(n.reasons.join(". "))+"
",n.waitlist&&!a.waitlistDone&&(r+='"),a.waitlistDone&&(r+=''+i(l.joined)+"
"),r+"")}function ue(e,t){var n=e.locations.filter(function(s){return s.id===e.locationId})[0],r=t.slots.filter(function(s){return s.id===a.sel.slot})[0],o=a.expiresAt&&a.expiresAt>Date.now(),d=a.expiresAt&&!o,c=''+P(e.method)+i(e.text.labels[e.method])+(n&&e.method!=="shipping"?", "+i(n.name):"")+''+i(b(t.date,!0))+""+(r&&!e.dateOnly?''+i(q(r))+"":"")+(a.sel.fee?'+'+i(T(a.sel.fee))+" "+i(l.fee)+"":"")+'
';return o?c+='
'+i(l.held)+" ":d?c+='
'+i(l.expired)+"":c+='
',c+="
",n&&n.pickupInstructions&&e.method==="pickup"&&(c+=''+i(n.pickupInstructions)+"
"),c}function z(){var e=a.expiresAt?a.expiresAt-Date.now():0,t=document.querySelectorAll("[data-dw-timer]");if(e<=0&&t.length)return f();for(var n=Math.max(0,Math.round(e/1e3)),r=0;r0?String(100-Math.max(0,Math.min(100,e/o*100))):"0"}setInterval(z,1e3),document.addEventListener("click",function(e){var t=e.target.closest&&e.target.closest("[data-datewise-root] [data-dw]");if(!(!t||t.tagName==="FORM")&&!(t.getAttribute("aria-disabled")==="true"&&t.getAttribute("data-dw")!=="date")){var n=t.getAttribute("data-dw"),r=t.getAttribute("data-v");n==="method"&&r!==a.method?(a.method=r,w("method",r),a.date=null,a.monthOffset=0,h(!0)):n==="loc"&&r!==a.locationId?(a.locationId=r,w("location",r),a.date=null,h(!0)):n==="month"?(a.monthOffset+=+r,f()):n==="date"?(a.date=r,a.waitlistDone=!1,p(null),f(),fe(".dw-slot:not([aria-disabled])")):n==="slot"&&J(a.date,r)}}),document.addEventListener("submit",function(e){var t=e.target;if(!(!t.closest||!t.closest("[data-datewise-root]"))){var n=t.getAttribute("data-dw");n&&(e.preventDefault(),n==="postal"&&(a.postal=t.postal.value.trim(),w("postal",a.postal),a.date=null,h(!0)),n==="waitlist"&&a.data&&S("/waitlist",{method:a.data.method,locationId:a.data.locationId,date:a.date,slot:"*",email:t.email.value.trim()}).then(function(r){r.ok?a.waitlistDone=!0:p(r.message||l.error,"critical"),f()}))}}),document.addEventListener("keydown",function(e){var t=e.target;if(!(!t.classList||!t.classList.contains("dw-day"))){var n={ArrowLeft:-1,ArrowRight:1,ArrowUp:-7,ArrowDown:7}[e.key];if(n){var r=Array.prototype.slice.call(t.parentNode.querySelectorAll(".dw-day")),o=r[r.indexOf(t)+n];o&&(e.preventDefault(),t.tabIndex=-1,o.tabIndex=0,o.focus())}}});function fe(e){setTimeout(function(){var t=document.querySelector("[data-datewise-root] "+e);t&&t.focus()},0)}function pe(){return a.data&&a.data.requireScheduling&&a.lines.length>0&&!a.sel}function he(e){if(!(!m.checkoutGuard||!pe())){var t=e.target.closest&&e.target.closest('[name="checkout"], a[href$="/checkout"], form[action$="/checkout"] [type="submit"]');if(t){e.preventDefault(),e.stopPropagation(),p(l.needTime,"critical"),f();var n=M()[0];n&&n.scrollIntoView({behavior:"smooth",block:"center"})}}}document.addEventListener("click",he,!0);var L=window.fetch.bind(window);window.fetch=function(e,t){var n=typeof e=="string"?e:e&&e.url,r=L(e,t);return n&&/\/cart\/(add|change|update|clear)(\.js)?/.test(n)&&!a.mutating&&r.then(function(){h()}),r},["cart:updated","cart:change","cart-drawer:open","ajaxCart:updated"].forEach(function(e){document.addEventListener(e,function(t){t.detail&&t.detail.source==="datewise"||h()})}),typeof window.subscribe=="function"&&window.PUB_SUB_EVENTS&&window.subscribe(window.PUB_SUB_EVENTS.cartUpdate,function(e){(!e||e.source!=="datewise")&&h()});var Y=[m.drawerSelector,"cart-drawer .drawer__footer","#CartDrawer .drawer__footer","#CartDrawer-Footer",".cart-drawer__footer","#cart-drawer .cart__footer",".js-cart-drawer .cart-drawer__footer","[data-cart-drawer] footer"].filter(Boolean);function K(){for(var e=0;e"']/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+=''+i(n)+"
"),r+=''+(a.message?'
'+i(a.message)+"
":"")+"
",e.setAttribute("aria-busy",a.loading),!t){e.innerHTML=r+(a.loading?'':"");return}if(!t.methods.length){e.innerHTML=r+''+i(l.none)+"
";return}if(r+='',t.methods.forEach(function(s){var v=s.method===t.method;r+='"}),r+="
",!t.method){e.innerHTML=r;return}if(t.method==="delivery"&&(r+='"),t.split&&(r+=''+i(t.split)+"
"),t.method!=="shipping"&&t.locations.length>1)r+='',t.locations.forEach(function(s){var v=s.id===t.locationId,O=s.fee?s.fee.waived?l.free:T(s.fee.fee):s.distanceKm!=null?s.distanceKm+" km":"";r+='"}),r+="
";else if(t.locationId){var o=t.locations.filter(function(s){return s.id===t.locationId})[0];o&&t.method!=="shipping"&&(r+=''+i(o.name)+(o.fee?" \xB7 "+(o.fee.waived?l.free:T(o.fee.fee)+" "+l.fee):"")+"
")}if(!t.locationId){if(t.needsAddress){e.innerHTML=r;return}var d=t.locations[0]&&t.locations[0].reason;e.innerHTML=r+(d?''+i(d)+"
":"");return}t.prepNote&&t.prepNote.minutes>=60&&(r+=''+i(l.prep+" "+t.prepNote.item)+" ("+Math.round(t.prepNote.minutes/6)/10+" h)
");var c=t.dates.filter(function(s){return s.peak&&s.peak.message})[0];c&&(r+=''+i(c.peak.message)+"
"),r+=de(t),r+=ce(t,e),e.innerHTML=r,e.setAttribute("aria-busy",a.loading),z()}var le=0;function $(e){return e.__dwid||(e.__dwid=++le),e.__dwid}function de(e){var t={};e.dates.forEach(function(D){t[D.date]=D});var n=(e.dates.filter(function(D){return D.available})[0]||e.dates[0]||{}).date;if(!n)return"";for(var r=te(n.slice(0,7),a.monthOffset),o=e.text.weekStartsOn||0,d=r+"-01",c=(re(d)-o+7)%7,s=''+i(new Intl.DateTimeFormat(g,{month:"long",year:"numeric",timeZone:"UTC"}).format(new Date(d+"T12:00:00Z")))+'
',v=0;v<7;v++){var O=(o+v)%7;s+=''+i(new Intl.DateTimeFormat(g,{weekday:"narrow",timeZone:"UTC"}).format(new Date(Date.UTC(2023,0,1+O))))+""}for(var W=0;W";for(var I=1;I<=ae(r);I++){var k=r+"-"+String(I).padStart(2,"0"),u=t[k],y="dw-day",E=b(k,!0),Q="";u?u.available?(y+=" dw-avail",e.text.showRemaining&&u.remaining!=null&&u.remaining<=5&&(Q=''+u.remaining+"")):u.waitlist||/full|booked/i.test(u.reasons[0]||"")?(y+=" dw-full",E+=", "+l.full):(y+=" dw-closed",E+=", "+(u.reasons[0]||"")):y+=" dw-out",a.date===k&&(y+=" dw-sel"),u&&u.peak&&(y+=" dw-peakday",E+=", "+u.peak.name),s+='"}return s+"
"}function ce(e,t){if(!a.date)return''+i(l.choose)+"
";var n=e.dates.filter(function(o){return o.date===a.date})[0];if(!n)return"";var r=''+i(b(n.date,!0))+(n.peak?' '+i(n.peak.name)+"":"")+"
";return e.dateOnly&&(r+='
'+i(l.dispatch)+"
"),n.available?(r+='
',n.slots.forEach(function(o){var d=a.sel&&a.sel.date===n.date&&a.sel.slot===o.id,c=o.available?(e.text.showRemaining&&o.remaining!=null?o.remaining+" "+l.left:"")+(o.surcharge?(o.remaining!=null&&e.text.showRemaining?" \xB7 ":"")+"+"+T(o.surcharge):""):o.reason||"";r+='"}),r+="
",a.sel&&a.sel.date===n.date&&(r+=ue(e,n)),r+"
"):(r+=''+i(n.reasons.join(". "))+"
",n.waitlist&&!a.waitlistDone&&(r+='"),a.waitlistDone&&(r+=''+i(l.joined)+"
"),r+"")}function ue(e,t){var n=e.locations.filter(function(s){return s.id===e.locationId})[0],r=t.slots.filter(function(s){return s.id===a.sel.slot})[0],o=a.expiresAt&&a.expiresAt>Date.now(),d=a.expiresAt&&!o,c=''+P(e.method)+i(e.text.labels[e.method])+(n&&e.method!=="shipping"?", "+i(n.name):"")+''+i(b(t.date,!0))+""+(r&&!e.dateOnly?''+i(q(r))+"":"")+(a.sel.fee?'+'+i(T(a.sel.fee))+" "+i(l.fee)+"":"")+'
';return o?c+='
'+i(l.held)+" ":d?c+='
'+i(l.expired)+"":c+='
',c+="
",n&&n.pickupInstructions&&e.method==="pickup"&&(c+=''+i(n.pickupInstructions)+"
"),c}function z(){var e=a.expiresAt?a.expiresAt-Date.now():0,t=document.querySelectorAll("[data-dw-timer]");if(e<=0&&t.length)return f();for(var n=Math.max(0,Math.round(e/1e3)),r=0;r0?String(100-Math.max(0,Math.min(100,e/o*100))):"0"}setInterval(z,1e3),document.addEventListener("click",function(e){var t=e.target.closest&&e.target.closest("[data-datewise-root] [data-dw]");if(!(!t||t.tagName==="FORM")&&!(t.getAttribute("aria-disabled")==="true"&&t.getAttribute("data-dw")!=="date")){var n=t.getAttribute("data-dw"),r=t.getAttribute("data-v");n==="method"&&r!==a.method?(a.method=r,w("method",r),a.date=null,a.monthOffset=0,h(!0)):n==="loc"&&r!==a.locationId?(a.locationId=r,w("location",r),a.date=null,h(!0)):n==="month"?(a.monthOffset+=+r,f()):n==="date"?(a.date=r,a.waitlistDone=!1,p(null),f(),fe(".dw-slot:not([aria-disabled])")):n==="slot"&&J(a.date,r)}}),document.addEventListener("submit",function(e){var t=e.target;if(!(!t.closest||!t.closest("[data-datewise-root]"))){var n=t.getAttribute("data-dw");n&&(e.preventDefault(),n==="postal"&&(a.postal=t.postal.value.trim(),w("postal",a.postal),a.date=null,h(!0)),n==="waitlist"&&a.data&&S("/waitlist",{method:a.data.method,locationId:a.data.locationId,date:a.date,slot:"*",email:t.email.value.trim()}).then(function(r){r.ok?a.waitlistDone=!0:p(r.message||l.error,"critical"),f()}))}}),document.addEventListener("keydown",function(e){var t=e.target;if(!(!t.classList||!t.classList.contains("dw-day"))){var n={ArrowLeft:-1,ArrowRight:1,ArrowUp:-7,ArrowDown:7}[e.key];if(n){var r=Array.prototype.slice.call(t.parentNode.querySelectorAll(".dw-day")),o=r[r.indexOf(t)+n];o&&(e.preventDefault(),t.tabIndex=-1,o.tabIndex=0,o.focus())}}});function fe(e){setTimeout(function(){var t=document.querySelector("[data-datewise-root] "+e);t&&t.focus()},0)}function pe(){return a.data&&a.data.requireScheduling&&a.lines.length>0&&!a.sel}function he(e){if(!(!m.checkoutGuard||!pe())){var t=e.target.closest&&e.target.closest('[name="checkout"], a[href$="/checkout"], form[action$="/checkout"] [type="submit"]');if(t){e.preventDefault(),e.stopPropagation(),p(l.needTime,"critical"),f();var n=C()[0];n&&n.scrollIntoView({behavior:"smooth",block:"center"})}}}document.addEventListener("click",he,!0);var L=window.fetch.bind(window);window.fetch=function(e,t){var n=typeof e=="string"?e:e&&e.url,r=L(e,t);return n&&/\/cart\/(add|change|update|clear)(\.js)?/.test(n)&&!a.mutating&&r.then(function(){h()}),r},["cart:updated","cart:change","cart-drawer:open","ajaxCart:updated"].forEach(function(e){document.addEventListener(e,function(t){t.detail&&t.detail.source==="datewise"||h()})}),typeof window.subscribe=="function"&&window.PUB_SUB_EVENTS&&window.subscribe(window.PUB_SUB_EVENTS.cartUpdate,function(e){(!e||e.source!=="datewise")&&h()});var Y=[m.drawerSelector,"cart-drawer .drawer__footer","#CartDrawer .drawer__footer","#CartDrawer-Footer",".cart-drawer__footer","#cart-drawer .cart__footer",".js-cart-drawer .cart-drawer__footer","[data-cart-drawer] footer"].filter(Boolean);function K(){for(var e=0;e' + esc(heading) + "";
h += '' + (S.message ? '
' + esc(S.message) + "
" : "") + "
";
- if (!d) { root.innerHTML = h + (S.loading ? '' : ""); root.setAttribute("aria-busy", S.loading); return; }
+ root.setAttribute("aria-busy", S.loading);
+ if (!d) { root.innerHTML = h + (S.loading ? '' : ""); return; }
+ if (!d.methods.length) { root.innerHTML = h + '' + esc(T.none) + "
"; return; }
// methods
h += '';