function BuilderItem(t){this.ProductCode=t.ProductCode}function BuilderCategory(t){this.type=t.type,this.name=t.name,this.items=t.data}function BuilderSelectModel(t,e,i,s=!1){this.isDuplicate=s,this.name=t,this.label=e,this.selected=ko.observable(),this.selected.subscribe((function(t){console.log(t)})),this.category=i,this.qty=ko.observable(1),this.qty.subscribe((t=>{setTimeout((()=>{if(0==t&&this.isDuplicate){const t=Builder.selects().indexOf(this);t>-1&&Builder.selects.splice(t,1)}}),500)})),this.qty_check=function(t){var e=isNaN(t)?1:t,i=this.isDuplicate?0:1;return e>999?e=999:e{Builder.selects.push(new BuilderSelectModel(this.name,this.label,this.category,!0))}}function Builder(t){for(var e in this.selects=ko.observableArray(),this.categories=ko.observableArray(),this.addCategory=function(t){this.categories.push(new BuilderCategory(t))},this.getItems=function(){return this.selects().filter((t=>t.qty()>0&&""!==t.selected()))},this.getTotals=function(){var t=this.getItems(),e=0;for(var i in t)e+=parseFloat(t[i].selected().ProductPrice)*t[i].qty();return e.toFixed(2)},this.click_addbuilderproducts=function(){const t=[],e=this.getItems();for(var i in e)t.push({sku:e[i].selected().ProductCode,qty:e[i].qty()});console.log(t),fetch("/basket/add-multiple",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({items:t})}).then((t=>t.json())).then((t=>{setBasket({Qty:t.totalQty,Cost:t.totalPrice}),showAlert("fa-check","Added!","Added item(s) to your basket!","#FFFFFF",!1)})).catch((t=>{console.error("Error:",t)}))},t)this.addCategory(t[e]);for(const t of builderData){const e=this.categories().find((e=>{for(const i in t.categoryCriteria)if(t.categoryCriteria[i]!==e[i])return!1;return!0}));e&&this.selects.push(new BuilderSelectModel(t.name,t.label,e))}}var Builder;document.addEventListener("DOMContentLoaded",(function(){Builder=new Builder(window.__input),ko.applyBindings(Builder,document.getElementById("content"))}));