function Product(t){const e=this;e.name=ko.observable(t.Name||t.ProductName||""),e.sku=t.sku,e.qty=ko.observable(t.qty?t.qty:""),e.productprice=t.Variation.Price,e.productdiscount=Math.max(t.ProductDiscount||0,0),e.productpricediscounted=getFinalPrice(e.productprice,e.productdiscount),e.productsub=t.ProductSub||"",e.productimage=t.Image||"",e.id=t.id,e.Variation=t.Variation,e.productship=t.ProductShip||"",e.ppcharge=t.PPCharge||0}function BasketViewModel(){const t=this;t.products=ko.observableArray([]),t.productFocused=ko.observable(),t.getShippingDays=ko.computed((function(){let e=t.products();return 0===e.length?null:Math.max.apply(Math,e.map((function(t){return t.productship})))})),t.getShippingDate=ko.computed((function(){return null})),t.getEarliestShippingDate=function(){return null},t.fetchBasket=async function(){const e=await fetch("/basket"),o=await e.json();t.products(o.map((t=>new Product(t))))},t.calcSubtotal=function(){let e=0;const o=t.products();for(let t=0;t=basketConfig.free_delivery?0:basketConfig.shipping})),t.updateProduct=async function(e){if(void 0!==window.isPaying&&window.isPaying)return t.fetchBasket();const o=await fetch(`/basket/${e.id}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({qty:e.qty()})}),n=await o.json();setBasket({Qty:n.totalQty,Cost:n.totalPrice}),t.fetchBasket()},t.deleteProduct=async function(e){if(void 0!==window.isPaying&&window.isPaying)return t.fetchBasket();const o=await fetch(`/basket/${e.id}`,{method:"DELETE"}),n=await o.json();setBasket({Qty:n.totalQty,Cost:n.totalPrice}),t.fetchBasket()},t.deleteProductButton=function(e){t.productFocused(e),t.deleteProduct(e)},t.fetchBasket()}var BasketView=new BasketViewModel;ko.applyBindings(BasketView);const getFinalPrice=function(t,e){return Number((t*((100-e)/100)).toFixed(2))};defer((function(){document.querySelector("#ppbtn")&&paypal.Buttons({style:{size:"responsive",color:"white",shape:"rect",label:"checkout"},createOrder:async function(t,e){return fetch("/checkout-details",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({})}).then((function(t){return t.json()})).then((function(t){return window.isPaying=!0,e.order.create(t)}))},onError:function(t,e){console.log("onError",t),alert(t),window.isPaying=!1},onCancel:function(t){alert(t),window.isPaying=!1},onApprove:function(t,e){return console.log("onApprove",t),e.order.capture().then((function(e){return console.log("capture",e),fetch("/paypal-transaction-complete",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({orderID:t.orderID})}).then((function(){window.location.href="/payment/confirm?pay=PAYPAL&status=PAID&orderID="+t.paymentID}))}))}}).render(document.querySelector("#ppbtn"))}));