"undefined"==typeof moment&&alert("Moment error"),moment.updateLocale("en",{holidays:["2024-12-25","2024-12-26","2024-12-27","2025-01-01","2025-04-18","2025-04-21","2025-05-05","2025-05-26","2025-08-25","2025-12-25","2025-12-26"],holidayFormat:"YYYY-MM-DD"});const DeliveryOpts=["08915","08914","08913","08910","08270","10578","12754"];function Product(e){const t=this;t.name=ko.observable(e.name||e.ProductName||""),t.sku=e.sku,t.qty=ko.observable(e.qty?e.qty:""),t.productprice=e.ProductPrice,t.productdiscount=Math.max(e.ProductDiscount,e.voucherDiscount,e.warrantyDiscount||0),t.productpricediscounted=getFinalPrice(e.ProductPrice,t.productdiscount),t.productsub=e.ProductSub||"",t.productimage=e.ProdLargeImage||"",t.warrantyID=e.warrantyId||0,t.id=e.id,t.pkg=e.pkg,t.productimage.startsWith("/")||(t.productimage="/"+t.productimage),t.productship=e.ProductShip||"",t.ppcharge=e.PPCharge||0,t.printing="Yes"==e.Artwork,t.special="Yes"==e.Special,t.dyesub="Yes"==e.DyeSub}function BasketViewModel(){const e=this;function t(){var e=new Date,t=new Date;t.setHours(15,45,0,0);var n=t.getTime()-e.getTime();n<0&&(t.setDate(t.getDate()+1),n=t.getTime()-e.getTime());var o=Math.floor(n/36e5),r=Math.floor(n%36e5/6e4),a=Math.floor(n%6e4/1e3);return(o=(o<10?"0":"")+o)+":"+(r=(r<10?"0":"")+r)+":"+(a=(a<10?"0":"")+a)}function n(){var e=new Date,t=e.getDay(),n=e.getHours(),o=e.getMinutes();return t>=1&&t<=5&&14==n&&o>=45||15==n&&o<45}e.products=ko.observableArray([]),e.country=ko.observable(localStorage.getItem("country")),e.country.subscribe((function(t){localStorage.setItem("country",t),"United Kingdom (Mainland Only)"!==e.country()&&"Highlands and Islands of Scotland"!==e.country()&&e.postcode(""),e.deliveryOption(void 0),document.querySelectorAll(".delivery-opt-cont").forEach((function(e){e.classList.remove("selected")})),document.querySelectorAll('input[name="delivery-opts"]').forEach((function(e){e.checked=!1}))})),e.postcode=ko.observable(localStorage.getItem("postcode")||""),e.postcode.extend({rateLimit:{timeout:500,method:"notifyWhenChangesStop"}}),e.postcode.subscribe((function(t){localStorage.setItem("postcode",t),setTimeout((function(){"Highlands and Islands of Scotland"!==e.country()&&e.isScotland()&&e.country("Highlands and Islands of Scotland"),"Northern Ireland"!==e.country()&&e.isNorthernIreland()&&e.country("Northern Ireland"),e.saveOptions()}),0)})),e.deliveryOption=ko.observable(),e.deliveryTime=ko.observable(),e.postcodeVerify=ko.observable(!1),e.productFocused=ko.observable(),e.isNorthernIreland=function(){return"BT"==e.postcode().substring(0,2).toUpperCase()},e.isScotland=function(){const t=e.postcode().substring(0,2).toUpperCase();return!(-1==["AB","DD","DG","EH","FK","HS","IV","KA","KW","KY","ML","PA","PH","TD","ZE"].indexOf(t))},e.getSTDCharge=ko.computed((function(){if(!e.postcodeVerify())return NaN;if(e.calcSubtotal()>=basketConfig.free_delivery)return 0;let t=e.products();return 0===t.length?null:Math.max.apply(Math,t.map((function(e){return e.ppcharge})))})),e.getPPCharge=ko.computed((function(){if("COL"==e.deliveryOption())return 0;if(!e.postcodeVerify())return NaN;if(e.calcSubtotal()>=basketConfig.free_delivery)return 0;let t=e.products();return 0===t.length?null:Math.max.apply(Math,t.map((function(e){return e.ppcharge})))})),e.getShippingDays=ko.computed((function(){let t=e.products();if(0===t.length)return null;return e.hasPrinting()?null:Math.max.apply(Math,t.map((function(e){return e.productship})))})),e.timeLeftNextDay=ko.observable(t()),e.shouldDisplayCutoffCountdown=ko.observable(n()),setInterval((function(){e.timeLeftNextDay(t())}),1e3),function t(){e.shouldDisplayCutoffCountdown(n());var o,r=new Date,a=r.getDay(),i=r.getHours(),c=r.getMinutes();if(a>=1&&a<=5)if(i<14||14==i&&c<45){var s=new Date(r);s.setHours(14,45,0,0),o=s-r}else if(i>15||15==i&&c>=45){var u=r;u.setDate(r.getDate()+(a%5+1)),u.setHours(14,45,0,0),o=u-r}else{var d=new Date(r);d.setHours(15,45,0,0),o=d-r}else{var l=new Date(r);l.setDate(r.getDate()+(8-a)%7),l.setHours(14,45,0,0),o=l-r}setTimeout(t,o)}(),e.getShippingDate=ko.computed((function(){var t=e.getShippingDays();if(null==t)return"TBD";var n=moment(),o=(new Date).getHours(),r=(new Date).getMinutes();return(o>15||15===o&&r>=45)&&(n=n.businessAdd(1)),(e.isNorthernIreland()||e.isScotland())&&(n=n.businessAdd(2)),(n=n.businessAdd(t)).format("DD MMM")})),e.getEarliestShippingDate=function(){var t=e.getShippingDays();if(null==t)return null;var n=moment(),o=(new Date).getHours(),r=(new Date).getMinutes();return(o>15||15===o&&r>=45)&&(n=n.businessAdd(1)),(e.isNorthernIreland()||e.isScotland())&&(n=n.businessAdd(2)),n=n.businessAdd(t)},e.hasPrinting=function(){let t=e.products();for(let e=0;enew Product(e))))},e.calcSubtotal=function(){let t=0;const n=e.products();for(let e=0;eContinue',"#FFFFFF",!0),!1;if(!i)return showAlert("icon-cancel-circled","Invalid Voucher!",'Continue',"#FFFFFF",!0),!1;if(!a)return showAlert("icon-cancel-circled","A price has recently changed, please check your totals.",'Dismiss',"#FFFFFF",!1),BasketView.fetchBasket(),!1;if(!r)return showAlert("icon-cancel-circled","Shipping dates have changed, please check your delivery dates.",'Dismiss',"#FFFFFF",!1),BasketView.fetchBasket(),!1}catch(e){return console.error("There was a problem with the fetch operation:",e),showAlert("icon-cancel-circled","Unable to validate basket. Please try again.",'Continue',"#FFFFFF",!0),!1}if(void 0===e.deliveryOption())return showAlert("icon-cancel-circled",CONST_BASKET_ERROR,CONST_BASKET_NODELIVERYOPTION,"#FFFFFF",!1),!1;if("NOM"==e.deliveryOption()){var t=moment(e.deliveryTime()),n=moment().endOf("day"),o=e.getEarliestShippingDate();if(void 0===e.deliveryTime())return showAlert("icon-cancel-circled","Error","Please select a date!","#FFFFFF",!1),!1;if(t.isBefore(n))return showAlert("icon-cancel-circled","Error","Please select a future date!","#FFFFFF",!1),!1;if(6===t.day()||0===t.day())return showAlert("icon-cancel-circled","Error","We can't deliver on weekends!","#FFFFFF",!1),!1;if(null!==o&&t.isBefore(o))return showAlert("icon-cancel-circled","Error","You picked a date earlier than we can deliver!","#FFFFFF",!1),!1}return!0},e.click_checkout=async function(){if(!await e.checkoutChecks())return;await e.saveOptions();window.location.href="/checkout-details"},e.updateProduct=async function(t){const n=await fetch(`/basket/${t.id}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({qty:t.qty()})}),o=await n.json();setBasket({Qty:o.totalQty,Cost:o.totalPrice}),e.fetchBasket()},e.deleteProduct=async function(t){const n=await fetch(`/basket/${t.id}`,{method:"DELETE"}),o=await n.json();setBasket({Qty:o.totalQty,Cost:o.totalPrice}),e.fetchBasket(),modalCloseId(document.getElementById("warranty-basket-warning")),modalCloseId(document.getElementById("package-basket-warning"))},e.deleteProductButton=function(t){return e.productFocused(t),t.warrantyID?modalOpen(document.getElementById("warranty-basket-warning")):t.pkg?modalOpen(document.getElementById("package-basket-warning")):void e.deleteProduct(t)},e.saveOptions=async function(){const t=await fetch("/basket/options",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({country:e.country(),postcode:e.postcode(),deliveryOption:e.deliveryOption(),deliveryTime:e.deliveryTime()})}),n=await t.json();return e.postcodeVerify(n.postcodeGood),n},e.fetchBasket(),e.saveOptions()}var BasketView;document.addEventListener("DOMContentLoaded",(function(){BasketView=new BasketViewModel,ko.applyBindings(BasketView,document.getElementById("content"))}));var getFinalPrice=function(e,t){return Number((e*((100-t)/100)).toFixed(2))};document.addEventListener("DOMContentLoaded",(function(){function e(){setTimeout((function(){document.getElementById("none").checked=!0}),250),setTimeout((function(){document.getElementById("none").checked=!0}),500)}e(),window.addEventListener("popstate",e),window.addEventListener("pageshow",(function(t){t.persisted&&e()}))})),document.addEventListener("visibilitychange",(function(){"visible"===document.visibilityState&&checkForStale(!0)}));const basketMS=(new Date).getTime(),checkForStale=e=>{const t=(new Date).getTime();return!(parseInt((t-basketMS)/1e3/60)>=20)||(e?(window.location.reload(!1),!1):(showAlert("","Your basket may have changed since you last looked.",'Continue',"#FFFFFF",!0),!1))};