var quizHandler=new QuizHandlerModel;function AnswerModel(e){var t=this;t.structure={productCode:e.structure.ProductCode,productName:e.structure.ProductName,productImage:e.structure.ProdLargeImage,productLink:e.structure.ProductLink},t.extras=e.extras,t.click_add_to_basket=function(){const e=[{sku:t.structure.productCode,qty:1}];t.extras.forEach((function(t){let o={sku:t.ProductCode,qty:t.Qty||1};e.push(o)})),fetch("/basket/add-multiple",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({items:e})}).then((e=>e.json())).then((e=>{setBasket({Qty:e.totalQty,Cost:e.totalPrice}),showAlert("icon-ok-circled",CONST_PRODUCT_ADD_TITLE,CONST_PRODUCT_ADDED+" "+CONST_PRODUCT_ADDED_APPEND,"#FFFFFF",!1)})).catch((e=>{console.error("Error:",e)}))},t.click_share=function(){},t.click_talktous=function(){modalOpen(document.getElementById("ask-a-question"))},t.click_downloadbrochure=function(){modalOpen(document.getElementById("download-brochure"))},t.click_enquire_now=function(){modalOpen(document.getElementById("enquire-now"))},t.click_retry=function(){confirm("Are you sure you'd like to restart the quiz?")&&(window.location.href=window.location.origin+window.location.pathname)}}function QuizHandlerModel(){var e=this;e.currentQuiz=ko.observable(null),e.startMarqueeQuiz=function(){e.currentQuiz(new MarqueeQuizModel),e.nextQuestion()},e.startGazeboQuiz=function(){e.currentQuiz(new GazeboQuizModel),e.nextQuestion()},e.nextQuestion=function(){var t=document.querySelectorAll("button.card-box").length,o=document.querySelectorAll("button.card-box .active-option").length>0;if(void 0===t||t>0&&!o)return showAlert("icon-cancel-circled","Error","Please select an option!","#FFFFFF",!1);var n=e.currentQuiz();if("marquee"==n.name){var r=n.people()?n.people():0,i=!!n.standing()&&n.standing();if(0==n.questionIndex()){if(r<1)return showAlert("icon-cancel-circled","Error","Please select an option!","#FFFFFF",!1)}else if(1==n.questionIndex()){if(i&&r>920)return showAlert("icon-cancel-circled","Please Call Us","A sales representative will be able to help you with a larger marquee.","#FFFFFF",!1);if(!i&&r>460)return showAlert("icon-cancel-circled","Please Call Us","A sales representative will be able to help you with a larger marquee.","#FFFFFF",!1)}}var a=n.questionIndex()+1;a=e.skiplogic(n,a,1),n.questionIndex(a);var s=document.querySelector("#content .animated");s&&(s.classList.remove("fadeInLeft"),s.classList.remove("fadeInRight"),s.classList.add("fadeInRight")),scrolltoTop(),e.getQuestionIndex()==n.maxQuestions&&n.getAnswer(),e.pushURL()},e.skiplogic=function(e,t,o){return"marquee"==e.name&&6==t&&(e.standing()&&(e.people()>=240&&!e.furniture()||e.people()>=220&&e.furniture())||!e.standing()&&(e.people()>=120&&!e.furniture()||e.people()>=110&&e.furniture()))&&(t+=o),"gazebo"==e.name&&4==t&&e.smallCar()&&(t+=o),t},e.canPushURL=!1,e.pushURL=function(){if(e.canPushURL)try{pushURL()}catch(e){}},e.previousQuestion=function(){var t=e.currentQuiz();if(e.getQuestionIndex()>0){var o=t.questionIndex()+-1;o=e.skiplogic(t,o,-1),t.questionIndex(o);var n=document.querySelector("#content .animated");n&&(n.classList.remove("fadeInLeft"),n.classList.remove("fadeInRight"),n.classList.add("fadeInLeft")),scrolltoTop()}t.answer(void 0)},e.getQuestionIndex=function(){return e.currentQuiz()?e.currentQuiz().questionIndex():0}}function MarqueeQuizModel(){var e=this;this.name="marquee",this.questionIndex=ko.observable(-1),this.maxQuestions=8,this.people=ko.observable(),this.standing=ko.observable(),this.furniture=ko.observable(),this.usageQty=ko.observable(),this.ground=ko.observable(),this.water=ko.observable("NOT ALWAYS"),this.extraStability=ko.observable(),this.heaters=ko.observable(),this.lighting=ko.observable(),this.answer=ko.observable(),this.getAnswer=function(){var t=ko.toJSON(quizHandler.currentQuiz());fetch("/choosing-the-right-tent/submit",{method:"POST",headers:{"Content-Type":"application/json"},body:t}).then((e=>{if(!e.ok)throw new Error("Network response was not ok");return e.json()})).then((t=>{e.answer(new AnswerModel(t))})).catch((e=>{console.error("Error:",e)}))}}function GazeboQuizModel(){var e=this;this.name="gazebo",this.questionIndex=ko.observable(-1),this.maxQuestions=9,this.colour=ko.observable("ANY COLOUR"),this.getColourClass=function(){return this.colour()?"prod-dot-"+this.colour().toLowerCase():""},this.usageType=ko.observable(),this.smallCar=ko.observable(),this.size=ko.observable(),this.usageQty=ko.observable(),this.ground=ko.observable(),this.water=ko.observable("NOT ALWAYS"),this.sidewalls=ko.observable(),this.extraStability=ko.observable(),this.storageBag=ko.observable(),this.answer=ko.observable(),this.getAnswer=function(){var t=ko.toJSON(quizHandler.currentQuiz());fetch("/choosing-the-right-tent/submit",{method:"POST",headers:{"Content-Type":"application/json"},body:t}).then((e=>{if(!e.ok)throw new Error("Network response was not ok");return e.json()})).then((t=>{e.answer(new AnswerModel(t))})).catch((e=>{console.error("Error:",e)}))}}function scrolltoTop(){setTimeout((function(){document.body.scrollIntoView({behavior:"smooth",block:"start",inline:"nearest"})}),100)}function buildURL(){let e=`${window.location.origin}${window.location.pathname}?`,t=quizHandler.currentQuiz();return t&&(e+=`name=${t.name}&`,t.colour&&t.colour()&&(e+=`colour=${t.colour()}&`),t.usageType&&t.usageType()&&(e+=`usageType=${t.usageType()}&`),t.smallCar&&void 0!==t.smallCar()&&(e+=`smallCar=${t.smallCar()}&`),t.size&&t.size()&&(e+=`size=${t.size()}&`),t.usageQty&&t.usageQty()&&(e+=`usageQty=${t.usageQty()}&`),t.ground&&t.ground()&&(e+=`ground=${t.ground()}&water=${t.water()}&`),t.sidewalls&&void 0!==t.sidewalls()&&(e+=`sidewalls=${t.sidewalls()}&`),t.extraStability&&void 0!==t.extraStability()&&(e+=`extraStability=${t.extraStability()}&`),t.storageBag&&void 0!==t.storageBag()&&(e+=`storageBag=${t.storageBag()}&`),t.people&&t.people()&&(e+=`people=${t.people()}&`),t.standing&&void 0!==t.standing()&&(e+=`standing=${t.standing()}&`),t.furniture&&void 0!==t.furniture()&&(e+=`furniture=${t.furniture()}&`),t.heaters&&void 0!==t.heaters()&&(e+=`heaters=${t.heaters()}&`),t.lighting&&void 0!==t.lighting()&&(e+=`lighting=${t.lighting()}&`)),e}function pushURL(){const e=buildURL();window.history.pushState({path:e},"",e)}function loadURL(){const e=parseQueryStringToJson(window.location.search);if("gazebo"==e.name){quizHandler.startGazeboQuiz();let t=quizHandler.currentQuiz();e.colour&&t.colour(e.colour),e.usageType&&(t.usageType(e.usageType),quizHandler.nextQuestion()),e.smallCar&&(t.smallCar("true"==e.smallCar),quizHandler.nextQuestion()),e.size&&(t.size(e.size),quizHandler.nextQuestion()),e.usageQty&&(t.usageQty(e.usageQty),quizHandler.nextQuestion()),e.ground&&(t.ground(e.ground),t.water(e.water),quizHandler.nextQuestion()),e.sidewalls&&(t.sidewalls("true"==e.sidewalls),quizHandler.nextQuestion()),e.extraStability&&(t.extraStability("true"==e.extraStability),quizHandler.nextQuestion()),e.storageBag&&(t.storageBag("true"==e.storageBag),quizHandler.nextQuestion(),quizHandler.nextQuestion())}else if("marquee"==e.name){quizHandler.startMarqueeQuiz();let t=quizHandler.currentQuiz();e.people&&t.people(e.people),e.standing&&(t.standing("true"==e.standing),quizHandler.nextQuestion()),e.furniture&&(t.furniture("true"==e.furniture),quizHandler.nextQuestion()),e.usageQty&&(t.usageQty(e.usageQty),quizHandler.nextQuestion()),e.ground&&(t.ground(e.ground),t.water(e.water),quizHandler.nextQuestion()),e.extraStability&&(t.extraStability("true"==e.extraStability),quizHandler.nextQuestion()),e.heaters&&(t.heaters("true"==e.heaters),quizHandler.nextQuestion()),e.lighting&&(t.lighting("true"==e.lighting),quizHandler.nextQuestion(),quizHandler.nextQuestion())}quizHandler.canPushURL=!0}function parseQueryStringToJson(e){const t=new URLSearchParams(e),o={};for(const[e,n]of t.entries())o.hasOwnProperty(e)?(Array.isArray(o[e])||(o[e]=[o[e]]),o[e].push(n)):o[e]=n;return o}ko.applyBindings({quizHandler:quizHandler}),defer((()=>{loadURL()})),window.addEventListener("popstate",(function(e){e.state?loadURL():console.log("Initial page load or no state data.")}));