define(function(require){var DecorillaView=require("DecorillaView");var Modal=require("Modal-ren");return DecorillaView.extend({defaults:{bannerText:null,launchUrl:null,roomTypePrices:null,roomTypePricesByCurrency:null,hrRatesByCurrency:null,minimumPlatinumPriceByCurrency:null,paymentCurrency:'USD',currencySymbols:{},activePromoAmount:0,fallbackCurrencySymbol:null,},initialize:function(options){this.options=$.extend({},this.defaults,options||{});this.$root=$('.pricing-section-partial');this.$root.find('.btn-room-price').on('click',$.proxy(this.handleRoomPriceClick,this));this.$root.find('.designer-lvl-info-lnk').on('click',$.proxy(this.handleDesignerLevelInfoClick,this));this.$root.find('.btn-benefits').on('click',$.proxy(this.handleBenefitsButtonClick,this));this.$root.find('.add-room-btn').on('click',$.proxy(this.handleAddRoomButtonClick,this));this.$root.find('.roomQtyDrp').on('change',$.proxy(this.handleAddRoomDropdownChange,this));this.$root.find('.rem-room-btn').on('click',$.proxy(this.handleRemoveRoomButtonClick,this));this.$root.find('.togglePricingSidebar').on('click',$.proxy(this.handleTogglePricingSidebarButtonClick,this));this.$root.find('.closePricingSidebarBtn').on('click',$.proxy(this.handleClosePricingSidebarButtonClick,this));this.$root.find('.room-frame').on('click',$.proxy(this.handleMobileCaptionClick,this));this.$root.find('.currency-switch-section .dropdown-item').on('click',$.proxy(this.handleCurrencySelectChange,this));this.$root.data('pricingView',this);this.checkScreenWidth();this.hideMobileSidebarPricingControlsOnLoad();$(window).resize($.proxy(this.checkScreenWidth,this));$(window).resize($.proxy(this.hideMobileSidebarPricingControlsOnLoad,this));$(document).on('click',$.proxy(this.handleDocumentClick,this))},handleDesignerLevelInfoClick:function(evt){evt.preventDefault();let $btn=$(evt.currentTarget);let title=$btn.data('title');let id=$btn.data('id');let existingModal=$('.pricing-desc-modal');$('#promotion-level-descriptions-container').slick('slickGoTo',id-1);if(existingModal.length>0&&this.modal){existingModal.find('.modal-title').html(title);if(!existingModal.hasClass('show')){this.modal.show()}}else{this.modal=new Modal({title:title,contentId:'promotion-levels-modal',modalClass:'pricing-desc-modal',modalDialogClass:'modal-dialog-centered',buttons:[],destroyOnHide:!1,})}},handleRoomPriceClick:function(evt){let $btn=$(evt.currentTarget);this.$root.find('.pricing-row .row,.loading-row img').addClass('d-none');this.$root.find('.pricing-row').addClass('short');this.$root.find('.pricing-row .room-title').html($btn.html());this.$root.find('.loading-row').removeClass('d-none')},handleBenefitsButtonClick:function(evt){let $btn=$(evt.currentTarget);this.$root.find('.btn-benefits').removeClass('btn-active');$btn.addClass('btn-active');this.$root.find('.table-benefits').addClass('d-none');this.$root.find('.'+$btn.data('table')).removeClass('d-none')},handleAddRoomButtonClick:function(evt){evt.preventDefault();let $btn=$(evt.currentTarget);let roomType=$btn.data('roomtype');let qtyInput=this.$root.find('#rooms_'+roomType);let numberLabel=qtyInput.next('.number-label');let currentValue=parseInt(qtyInput.val());if(currentValue===0){$btn.parents('.room-frame').addClass('active');$btn.parents('.room-selection-container').addClass('active')} if(currentValue<50){qtyInput.val(currentValue+1);numberLabel.text(currentValue+1);this.$root.find('#roomQtyDrp_'+roomType).val(currentValue+1);this.calculateTotalPrice()}},handleAddRoomDropdownChange:function(evt){evt.preventDefault();let $roomQtyDrp=$(evt.currentTarget);let roomType=$roomQtyDrp.data('roomtype');let qtyInput=this.$root.find('#rooms_'+roomType);let numberLabel=qtyInput.next('.number-label');let currentValue=parseInt($roomQtyDrp.val());if(currentValue<51){qtyInput.val(currentValue);numberLabel.text(currentValue);this.$root.find('#roomQtyDrp_'+roomType).val(currentValue);this.calculateTotalPrice()}},handleRemoveRoomButtonClick:function(evt){evt.preventDefault();let $btn=$(evt.currentTarget);let roomType=$btn.data('roomtype');let qtyInput=this.$root.find('#rooms_'+roomType);let numberLabel=qtyInput.next('.number-label');let currentValue=parseInt(qtyInput.val());if($btn.parents('.room-frame').hasClass('default')&¤tValue===0){return} if(currentValue>0){qtyInput.val(currentValue-1);numberLabel.text(currentValue-1);this.$root.find('#roomQtyDrp_'+roomType).val((currentValue-1<1)?1:currentValue-1);this.calculateTotalPrice();if(currentValue-1===0){$btn.parents('.room-frame').removeClass('active');$btn.parents('.room-selection-container').removeClass('active')}}},calculateTotalPrice:function(){const roomPrices=this.options.roomTypePrices;let currencySymbols=JSON.parse(this.options.currencySymbols);const currencySymbol=this.options.fallbackCurrencySymbol?this.options.fallbackCurrencySymbol:(currencySymbols[this.options.paymentCurrency]||'$');let roomQtyInput=0;let totalRoomQty=0;let defaultTotalPrices={};let totalPrices={};let totalDiscountedPrices={};let displayTotalPrices={};let displayedPromotionLevels=[1,2,3];let lastRoomAdded=this.$root.find('.pricing-row .header .dropdown-text .room-title').text();let roomParams=[];for(let promotionLevelId of displayedPromotionLevels){defaultTotalPrices[promotionLevelId]=0} for(let roomTypeId in roomPrices){if(roomPrices.hasOwnProperty(roomTypeId)){roomQtyInput=parseInt(this.$root.find('#rooms_'+roomTypeId).val());if(roomQtyInput>0){totalRoomQty+=roomQtyInput;roomParams.push({[roomTypeId]:roomQtyInput})} for(let promotionLevelId in roomPrices[roomTypeId]){if(roomPrices[roomTypeId].hasOwnProperty(promotionLevelId)){let price=roomPrices[roomTypeId][promotionLevelId];if(roomQtyInput>0){totalPrices[promotionLevelId]=(totalPrices[promotionLevelId]||0)+(roomQtyInput*price);lastRoomAdded=this.$root.find('#rooms_'+roomTypeId).parents('.controls').find('button.minus-icon-btn').data('room-title')}}}}} if(totalRoomQty>1){this.$root.find('.pricing-row .header .dropdown-text .room-title').text('Multiple Rooms');for(let promotionLevelId in totalPrices){if(totalPrices.hasOwnProperty(promotionLevelId)){totalDiscountedPrices[promotionLevelId]=totalPrices[promotionLevelId]-(totalPrices[promotionLevelId]*0.1)}} let roomParamsJson=encodeURIComponent(JSON.stringify(roomParams));let currentUrl=this.$root.find('.start-project-now').attr('href');let newUrl=currentUrl.replace(/([?&])rooms=[^&]*(&|$)/,(match,p1,p2)=>p2?p1:'');if(newUrl.includes('?')){newUrl=`${newUrl}&rooms=${roomParamsJson}`}else{newUrl=`${newUrl}?rooms=${roomParamsJson}`} this.$root.find('.start-project-now').attr('href',newUrl)}else{if(totalPrices!==0){this.$root.find('.pricing-row .header .dropdown-text .room-title').text(lastRoomAdded)} totalDiscountedPrices={}} displayTotalPrices=Object.keys(totalPrices).length?totalPrices:defaultTotalPrices;for(let promotionLevelId of displayedPromotionLevels){let regularPrice=displayTotalPrices[promotionLevelId];let promoPrice=regularPrice;if(this.options.activePromoAmount>0&®ularPrice>0){promoPrice=this.options.activePromoAmount<1?promoPrice*(1-this.options.activePromoAmount):promoPrice-this.options.activePromoAmount} if(totalDiscountedPrices.hasOwnProperty(promotionLevelId)){let finalPrice=Math.min(totalDiscountedPrices[promotionLevelId],promoPrice);this.$root.find('.pricing-row .price-row-'+promotionLevelId).find('.price').html(this.formatPriceForCurrency(finalPrice,currencySymbol,!0));this.$root.find('.mobile-price-section .mobile-price-col-'+promotionLevelId).html(this.formatPriceForCurrency(totalDiscountedPrices[promotionLevelId],currencySymbol,!0));this.$root.find('.pricing-row .price-row-'+promotionLevelId).find('.price').removeClass('hasDecimal').addClass('hasDecimal');this.$root.find('.pricing-row .price-row-'+promotionLevelId).find('.slashed-price .offset-cont').text(this.formatPriceForCurrency(displayTotalPrices[promotionLevelId],currencySymbol,!1));this.$root.find('.pricing-row .price-row-'+promotionLevelId).find('.slashed-price .discount-desc').text(totalDiscountedPrices[promotionLevelId]<=promoPrice?'10% OFF':(this.options.activePromoAmount<1?(this.options.activePromoAmount*100)+"%":currencySymbol+this.options.activePromoAmount)+' OFF');this.$root.find('.mobile-price-section .mobile-slashed-price-col-'+promotionLevelId).text(this.formatPriceForCurrency(displayTotalPrices[promotionLevelId],currencySymbol,!1))}else if(displayTotalPrices.hasOwnProperty(promotionLevelId)){this.$root.find('.pricing-row .price-row-'+promotionLevelId).find('.price').html(this.formatPriceForCurrency(promoPrice,currencySymbol,!0));this.$root.find('.mobile-price-section .mobile-price-col-'+promotionLevelId).html(this.formatPriceForCurrency(displayTotalPrices[promotionLevelId],currencySymbol,!0));this.$root.find('.pricing-row .price-row-'+promotionLevelId).find('.price').removeClass('hasDecimal');this.$root.find('.pricing-row .price-row-'+promotionLevelId).find('.slashed-price .offset-cont').text(promoPrice==regularPrice?'':this.formatPriceForCurrency(displayTotalPrices[promotionLevelId],currencySymbol,!1));this.$root.find('.pricing-row .price-row-'+promotionLevelId).find('.slashed-price .discount-desc').text(promoPrice==regularPrice?'':(this.options.activePromoAmount<1?(this.options.activePromoAmount*100)+"%":currencySymbol+this.options.activePromoAmount)+' OFF');this.$root.find('.mobile-price-section .mobile-slashed-price-col-'+promotionLevelId).text('')}}},formatPriceForCurrency:function(amount,symbol,showCurrencyCode){var num=Math.floor(parseFloat(amount));if(symbol==='€'){return num.toString().replace(/\B(?=(\d{3})+(?!\d))/g,' ')+' '+symbol} if(this.options.paymentCurrency==='CAD'){var formatted=symbol+num.toString().replace(/\B(?=(\d{3})+(?!\d))/g,',');if(showCurrencyCode&&num>0){return''+formatted+'CAD'} return formatted} return symbol+num.toString().replace(/\B(?=(\d{3})+(?!\d))/g,',')},formatPriceWithCommas:function(price){let parsedPrice=parseFloat(price);let roundedDownPrice=Math.floor(parsedPrice);return roundedDownPrice.toString().replace(/\B(?=(\d{3})+(?!\d))/g,",")},handleTogglePricingSidebarButtonClick:function(evt){evt.preventDefault();let _this=this;if($(window).width()>576){this.$root.find('#multiple-room-select-sidebar').toggle();if(this.$root.find('#multiple-room-select-sidebar').css('display')==='none'){_this.hidePricingSidebar(!0)} return} this.$root.find('#multiple-room-select-sidebar').removeClass('active').addClass('active');this.$root.find('#multiple-room-select-sidebar').removeClass('open').addClass('open');this.$root.find('#multiple-room-select-sidebar').show();this.$root.find('#multiple-room-select-sidebar-overlay').show();$("#chatstack-launcher-frame").hide()},handleDocumentClick:function(evt){let _this=this;const $sidebar=this.$root.find('#multiple-room-select-sidebar');const $overlay=this.$root.find('#multiple-room-select-sidebar-overlay');const isClickInside=$sidebar.has(evt.target).length>0;const isClickOnToggleButton=$(evt.target).closest('.togglePricingSidebar').length>0;if($sidebar.hasClass('active')&&!isClickInside&&!isClickOnToggleButton){$sidebar.removeClass('active');$sidebar.removeClass('open');$overlay.hide();$("#chatstack-launcher-frame").show()}},handleClosePricingSidebarButtonClick:function(evt){evt.preventDefault();let _this=this;_this.hidePricingSidebar()},hidePricingSidebar:function(hideOnAllViewports=!1){let _this=this;if($(window).width()>576&&!hideOnAllViewports) return;const $sidebar=this.$root.find('#multiple-room-select-sidebar');const $overlay=this.$root.find('#multiple-room-select-sidebar-overlay');$sidebar.removeClass('active');$sidebar.removeClass('open');$overlay.hide();$("#chatstack-launcher-frame").show()},checkScreenWidth:function(){const $toggleSidebarBtn=this.$root.find('#dropdownCaret');if($(window).width()<=576){$toggleSidebarBtn.addClass('disabled');$toggleSidebarBtn.attr('aria-disabled','true')}else{$toggleSidebarBtn.removeClass('disabled');$toggleSidebarBtn.attr('aria-disabled','false')}},handleMobileCaptionClick:function(evt){evt.preventDefault();let _this=this;let $target=$(evt.target);let $roomFrame=$(evt.currentTarget);if($target.hasClass('roomQtyDrp')){return} if($(window).width()>576) return;let $controls=$roomFrame.find('.controls');let $roomSelectionContainer=$roomFrame.parent('.room-selection-container');let qtyInput=$controls.find('#rooms_'+$roomFrame.data('id'));let numberLabel=qtyInput.next('.number-label');if($roomFrame.hasClass('default')&&parseInt(qtyInput.val())>0){return} if($controls.css('visibility')==='hidden'){_this.toggleVisibility($controls);$roomFrame.addClass('active');$roomSelectionContainer.addClass('active');if(parseInt(qtyInput.val())===0){qtyInput.val(1);numberLabel.text(1);this.calculateTotalPrice()}}else{_this.toggleVisibility($controls);$roomFrame.removeClass('active');$roomSelectionContainer.removeClass('active');qtyInput.val(0);numberLabel.text(0);this.calculateTotalPrice()}},hideMobileSidebarPricingControlsOnLoad:function(){let _this=this;if($(window).width()>576){return} this.$root.find('.room-frame').each(function(){if(!$(this).hasClass('active')){let $controls=$(this).find('.controls');_this.toggleVisibility($controls,'hide')}else{let $controls=$(this).find('.controls');_this.toggleVisibility($controls,'show')}})},toggleVisibility:function($element,useOption=null){if(useOption==='hide'){$element.removeClass('v-show').addClass('v-hide')}else if(useOption==='show'){$element.removeClass('v-hide').addClass('v-show')}else{if($element.hasClass('v-hide')){$element.removeClass('v-hide').addClass('v-show')}else{$element.removeClass('v-show').addClass('v-hide')}}},handleCurrencySelectChange:function(evt){const $item=$(evt.currentTarget);const currency=$item.data('value');if(!currency||!this.options.roomTypePricesByCurrency||!this.options.roomTypePricesByCurrency[currency]){return} this.$root.find('.pricing-row .pricing-section,.loading-row img').addClass('d-none');this.$root.find('.pricing-row').addClass('short');this.$root.find('.loading-row').removeClass('d-none');this.applySelection({currency:currency,currencyLabel:$item.find('.dropdown-item-text').text().trim()||$item.data('text')||'',roomTitle:this.$root.find('.pricing-row .header .dropdown-text .room-title').text(),});this.$root.find('.loading-row').addClass('d-none');this.$root.find('.pricing-row').removeClass('short');this.$root.find('.pricing-row .pricing-section').removeClass('d-none');this.$root.find('.loading-row img').removeClass('d-none')},applySelection:function(values){if(!values.currency)return;this.options.paymentCurrency=values.currency;this.options.roomTypePrices=this.options.roomTypePricesByCurrency[values.currency];this.calculateTotalPrice();this.updateStaticPrices(values.currency);const $dropdown=this.$root.find('.currency-switch-section .form-dropdown');$dropdown.find('.dropdown-toggle-text').html(values.currencyLabel||'');$dropdown.find('.dropdown-item').removeClass('active');$dropdown.find('.dropdown-item[data-value="'+values.currency+'"]').addClass('active');$dropdown.find('.form-dropdown-hidden').val(values.currency);if(values.roomTitle!==undefined){this.$root.find('.pricing-row .header .dropdown-text .room-title').text(values.roomTitle)} const url=new URL(window.location.href);url.searchParams.set('currency',values.currency);history.pushState(null,'',url.toString())},updateStaticPrices:function(currency){const currencySymbols=JSON.parse(this.options.currencySymbols);const symbol=this.options.fallbackCurrencySymbol?this.options.fallbackCurrencySymbol:(currencySymbols[currency]||'$');const rates=this.options.hrRatesByCurrency&&this.options.hrRatesByCurrency[currency];if(rates){const fromStr=this.formatPriceForCurrency(rates.from,symbol,!1);const toStr=this.formatPriceForCurrency(rates.to,symbol,!1);this.$root.find('.hourly-rate-from').html(fromStr);this.$root.find('.hourly-rate-to').html(toStr)} const platinumPrice=this.options.minimumPlatinumPriceByCurrency&&this.options.minimumPlatinumPriceByCurrency[currency];if(platinumPrice){this.$root.find('.platinum-price-value').html(this.formatPriceForCurrency(platinumPrice,symbol,!0))}},})})