(function($){const store=new Vuex.Store({state:{product:null,monogram:{},popups:{delivery:!1,monogram:!1,notify:!1,pickup:!1,review:!1,stock:!1,stores:!1,swatch:!1,zoom:!1,},},getters:{defaultStoreId(state){return Object.keys(state.product.storestock.stores).filter((storeId)=>{return state.product.storestock.stores[storeId].name==='Superette Newmarket'})[0]},selectedStoreId(state,getters){return Object.keys(state.product.storestock.stores).filter((storeId)=>{return state.product.storestock.stores[storeId].selected})[0]||getters.defaultStoreId},selectedStore(state,getters){return state.product.storestock.stores[getters.selectedStoreId]},},mutations:{SET_DELIVERY_DETAILS(state,delivery){state.product.deliveryinfo.details=delivery},SET_SELECTED_STORE(state,selectedStoreId){if(selectedStoreId===null)return;var{stores}=state.product.storestock;state.product.storestock.stores=Object.keys(stores).reduce((updatedStores,storeId)=>{updatedStores[storeId]=stores[storeId];updatedStores[storeId].selected=storeId===selectedStoreId;return updatedStores},{})},SET_STYLE_COLOUR(state,styleColourId){state.product.stylecolour=state.product.stylecolours[styleColourId]},SET_VARIANT(state,variantId){var variant=state.product.stylecolour.variants.filter((variant)=>{return variant.barcode===variantId});state.product.stylecolour.variant=variant.length&&variant[0]},SET_WISHLIST_STATUS(state,status){state.product.stylecolour.inwishlist=status},SET_INITIAL_PRODUCT(state,product){state.product=product},SET_MONOGRAM(state,monogram){state.monogram=monogram},OPEN_POPUP(state,payload){state.popups[payload.name]=typeof payload.data==='undefined'||payload.data},CLOSE_POPUP(state,popup){state.popups[popup]=!1},},actions:{getData(context,payload){return $.ajax({url:payload.route,type:'get',})},postData(context,payload){return $.ajax({url:payload.route,type:'post',dataType:'json',data:payload.data,})},setStyleColour(context,id){context.commit('SET_STYLE_COLOUR',id)},setVariant(context,id){context.commit('SET_VARIANT',id)},setWishlistStatus(context){context.commit('SET_WISHLIST_STATUS',!context.state.product.stylecolour.inwishlist)},getDeliveryDetails(context,payload){return context.dispatch('postData',{route:'/api/product/delivery',data:JSON.stringify(payload),dataType:'json',}).then((response)=>{if(response.status){context.commit('SET_DELIVERY_DETAILS',response.data)}
return response})},getProductData(context,payload){context.commit('SET_INITIAL_PRODUCT',payload)},setMonogram(context,payload){context.commit('SET_MONOGRAM',payload)},setSelectedStore(context,storeId){return context.dispatch('postData',{route:'/api-customer/apicustomersetstore',data:{storeid:storeId,},dataType:'json',}).then(()=>{context.commit('SET_SELECTED_STORE',storeId)})},},});const vmProduct={data(){return{size:null,qty:1,}},computed:{product(){return this.$store.state.product},styleColour(){return this.product.stylecolour},styleColourOptions(){return Object.keys(this.product.stylecolours).map(function(colour){return this.product.stylecolours[colour]})},variant(){return this.styleColour.variant},variantOptions(){var options=[];this.styleColour.variants.forEach((variant)=>{var item={...variant};if(item.status==='disabled'){item.disabled=!0}
options.push(item)});return options},},methods:{addToCart(barcode,quantity){var payload={variantid:barcode,quantity:quantity,};if(Object.keys(this.$store.state.monogram).length){payload.extras=JSON.stringify(this.$store.state.monogram)}
peppercheckout.globals.$eventbus.$emit('addproducttocart',payload)},getMatchingSize(variants){var self=this;if(!self.size)return!1;var matchingVariant=variants.filter((variant)=>{return variant.size===self.size&&variant.status!=='disabled'})[0];return matchingVariant&&matchingVariant.barcode},selectStyleColour(option){this.$store.dispatch('setStyleColour',option.stylecolourid);this.$store.dispatch('setVariant',this.getMatchingSize(option.variants)||option.variant.barcode);$(document).trigger('psevent',['detail',this.variant.gadata]);window.history.replaceState({style:option.stylecolourid},'',option.url)},selectVariant(option){this.size=option.size;this.$store.dispatch('setVariant',option.barcode);$(document).trigger('psevent',['detail',this.variant.gadata])},selectQty(qty){this.qty=qty},showInstalmentPopup(payment){loadpopup('popup-payments','/popup-payments',{paymenttype:payment.type.toLowerCase()})},toggleWishlist(){var self=this;peppercheckout.globals.$eventbus.$emit('togglewishlistitem',{stylecolourid:self.styleColour.stylecolourid,},(response)=>{if(response.status){var gaData={eventCategory:'Product Page',eventAction:'Wishlists',eventLabel:response.data.message,};$(document).trigger('psevent',['productClickWishlist',gaData]);self.$store.dispatch('setWishlistStatus')}else{loadslidein('slide-in--login-register','/slide-in-login-register')}})},openPopup(popup,data){this.$store.commit('OPEN_POPUP',{name:popup,data})},closePopup(popup){this.$store.commit('CLOSE_POPUP',popup)},},mounted(){this.size=this.variant.size},};const vcProductSlider={template:'#vc-component-product-slider',props:{items:{type:Array,default(){return[]},},slidertype:{type:String,default:'product',},label:{type:String,default:'',},},data(){return{slickOptions:{prevArrow:'<button type="button" data-role="none" class="slick-prev slick-arrow" aria-label="Previous" role="button" style=""><span class="icon-arrow-left"></span></button>',nextArrow:'<button type="button" data-role="none" class="slick-next slick-arrow" aria-label="Next" role="button" style=""><span class="icon-arrow-right"></span></button>',infinite:!1,slidesToShow:4,slidesToScroll:4,responsive:[{breakpoint:ps.breakpoints.lg,settings:{slidesToShow:3.5,slidesToScroll:2,},},{breakpoint:ps.breakpoints.md,settings:{arrows:!1,slidesToShow:1.5,slidesToScroll:1,},}],},}},methods:{initSlider(){if(!this.$refs.gallery.$el.classList.contains('slick-initialized')){this.$refs.gallery.create()}},reInitSlider(){if(this.$refs.gallery.$el.classList.contains('slick-initialized')){this.destroySlider();this.$nextTick(this.initSlider)}},destroySlider(){if(this.$refs.gallery.$el.classList.contains('slick-initialized')){this.$refs.gallery.destroy()}},},mounted(){if(this.$refs.gallery){$(this.$refs.gallery.$el).verticallyPosition({elem:'.slick-arrow',image:'.s-prod__gallery img',position:'centre',})}},watch:{items(){this.reInitSlider()},},};const vcProductPopupSwatch={template:'#vc-component-product-popup-swatch',mixins:[vmProduct],computed:{swatch(){return this.styleColour.images.fabricswatch[0]},},};const vcProductPopupZoom={template:'#vc-component-product-popup-zoom',mixins:[vmProduct],computed:{selected(){if(!this.$store.state.popups.zoom)return'';return this.$store.state.popups.zoom.selected},images(){return this.styleColour.images[this.styleColour.primaryimagegroup]||[]},},methods:{initImageZoom(){var self=this;$(self.$el).imagesLoaded(()=>{var selectedImage=document.getElementById(self.selected);if(selectedImage!==null){selectedImage.scrollIntoView()}})},},};const vcProductPopupNotify={template:'#vc-component-product-popup-notify',mixins:[vmProduct],data(){return{isUser:window.customer&&!!window.customer.loggedin,fields:{name:'',email:window.customer&&window.customer.email,subscribe:'',barcode:'',csrftoken:'',},success:'',errors:{},error:'',}},methods:{notifyCustomer(){var self=this;this.success='';this.errors={};this.error='';$.ajax({url:'/api/product/notifycustomer',type:'post',dataType:'json',data:this.fields,}).then((response)=>{if(response.status){self.success=response.data.message||''}else{self.errors=response.data.errors||{};self.error=response.data.error||''}})},},mounted(){this.fields.csrftoken=this.product.csrftoken.notify;this.fields.barcode=this.$store.state.popups.notify.barcode},};const vcProductPopupDelivery={template:'#vc-component-product-popup-delivery',mixins:[vmProduct],data(){return{fields:{country:'New Zealand',city:'Auckland',},icons:{'New Zealand':'icon-flag-nz','Australia':'icon-flag-au',},}},computed:{countries(){var self=this;return Object.keys(this.product.deliveryinfo.popupdata).map((country)=>{return{country:country,icon:self.icons[country]||null,}})||[]},cities(){return Object.keys(this.product.deliveryinfo.popupdata[this.fields.country])||[]},deliveryInfo(){return this.product.deliveryinfo.popupdata[this.fields.country][this.fields.city]},},methods:{updateField(field,option){this.fields[field]=option.value.country},},mounted(){var{country}=this.product.deliveryinfo.details;var{city}=this.product.deliveryinfo.details;if(country&&city){this.fields.country=country;this.fields.city=city}},watch:{'fields.country':function(country){this.fields.city=Object.keys(this.product.deliveryinfo.popupdata[country])[0]},'fields.city':function(city){this.$store.dispatch('getDeliveryDetails',{country:this.fields.country,city,})},},};const vcProductPopupMonogram={template:'#vc-component-product-popup-monogram',mixins:[vmProduct],data(){return{colours:{'#FFDF00':'Gold','#D3D3D3':'Silver',},fields:{initials:'',colourname:'Silver',colour:'#D3D3D3',checkterms:'',},validation:{initials:!0,checkterms:!0,},}},methods:{addMonogram(){if(this.validate()){this.$store.dispatch('setMonogram',this.fields);this.closePopup('monogram')}},validate(){var self=this;this.validation.initials=!!this.fields.initials;this.validation.checkterms=!!this.fields.checkterms;return Object.keys(this.validation).every((key)=>{return self.validation[key]})},},watch:{'fields.colour':function(hexCode){this.fields.colourname=this.colours[hexCode]},},};const vcProductPopupReview={template:'#vc-component-product-popup-review',mixins:[vmProduct],data(){return{fields:{csrftoken:'',style:'',name:'',title:'',comment:'',quality:'',fit:'',purchasedsize:'',usualsize:'',},success:'',errors:{},error:'',}},computed:{sizes(){return this.variantOptions.map((variant)=>{return variant.size})},},methods:{submitReview(){var self=this;this.errors={};this.error='';$.ajax({url:'/api/product/submit-review',type:'post',dataType:'json',data:this.fields,}).then((response)=>{if(response.status){self.success=response.message}else{self.errors=response.errors;self.error=response.error}})},},mounted(){this.fields.csrftoken=this.product.csrftoken.review;this.fields.style=this.product.style},};const vcProductPopupStock={template:'#vc-component-product-popup-stock',mixins:[vmProduct],data(){return{legend:{'Coming Soon':'soon','Sold Out':'none','Nearly Gone':'low','In Stock':'high',},}},methods:{extractLabel(storeId,size){var extractLabel='';if(this.product.storestock&&this.product.storestock.stock[this.styleColour.stylecolourid]&&this.product.storestock.stock[this.styleColour.stylecolourid][storeId]&&this.product.storestock.stock[this.styleColour.stylecolourid][storeId][size]){extractLabel=this.product.storestock.stock[this.styleColour.stylecolourid][storeId][size].label}
return extractLabel},},};const vcProductPopupStores={template:'#vc-component-product-popup-stores',mixins:[vmProduct],data(){return{changedStoreId:null,}},computed:{selectedStore(){if(this.changedStoreId!==null){return this.product.storestock.stores[this.changedStoreId]}
return this.$store.getters.selectedStore},storeOptions(){var{stores}=this.product.storestock;return Object.keys(stores).map((storeId)=>{return Object.assign(stores[storeId],{id:storeId})})},},methods:{changeStore(storeId){this.changedStoreId=storeId},confirmChangeStore(){this.$store.dispatch('setSelectedStore',this.changedStoreId);this.changedStoreId=null;this.closePopup('stores')},},};const vcProductPopupPickup={template:'#vc-component-product-popup-pickup',mixins:[vmProduct],computed:{selectedStore(){return this.$store.getters.selectedStore},},};const vcProductFixedAddToCart={template:'#vc-component-product-fixed-add-to-cart',mixins:[vmProduct],data(){return{isActive:!1,}},methods:{toggleAddToCartHeader(){var $productSummary=$('.j-product-summary');var productSummaryBottom=$productSummary.offset().top+$productSummary.outerHeight();this.isActive=$(window).scrollTop()>productSummaryBottom},},mounted(){$(window).on('scroll resize',$.throttle(this.toggleAddToCartHeader,100))},};const vmGallery={mixins:[vmProduct],data(){return{galleryOptions:{arrows:!1,dots:!0,slidesToScroll:1,slidesToShow:1,mobileFirst:!0,responsive:[{breakpoint:750,settings:{slidesToShow:2,arrows:!0,dots:!1,prevArrow:'<button type="button" data-role="none" class="slick-prev slick-arrow product-gallery__prev" aria-label="Previous" role="button" style=""><span class="icon-arrow-left"></span></button>',nextArrow:'<button type="button" data-role="none" class="slick-next slick-arrow product-gallery__next" aria-label="Next" role="button" style=""><span class="icon-arrow-right"></span></button>',}}],},isVideoPlaying:!1,videoIndex:1,}},computed:{gallery(){if(!this.images.length)return[];var gallery=this.images.slice(0);if(this.styleColour.video&&gallery.length>1){gallery.splice(this.videoIndex,0,{video:`${this.styleColour.video  }#t=0.5`,poster:gallery[1].src,})}
return gallery},hasVideo(){return this.gallery.some((item)=>{return item.video})},images(){return this.styleColour.images[this.styleColour.primaryimagegroup]||[]},},methods:{initSlider(){if(!this.$refs.productGallery.$el.classList.contains('slick-initialized')){this.$refs.productGallery.create()}},reInitSlider(){if(this.$refs.productGallery.$el.classList.contains('slick-initialized')){this.destroySlider();this.$nextTick(this.initSlider)}},destroySlider(){if(this.$refs.productGallery.$el.classList.contains('slick-initialized')){this.$refs.productGallery.destroy()}},showImageZoom(name){this.openPopup('zoom',{selected:`image-${  name}`})},playVideo(){this.isVideoPlaying=!0;this.$refs.video[0].play();if(this.$refs.productGallery.$el.classList.contains('slick-initialized')){this.$refs.productGallery.goTo(this.videoIndex)}},stopVideo(){this.isVideoPlaying=!1;this.$refs.video[0].pause()},},mounted(){if(this.styleColour.video&&ps.currentBreakpoint==='lg'){this.playVideo()}
this.initSlider()},watch:{'styleColour.colour':function(){this.reInitSlider()},},};const vcProductGallery={template:'#vc-component-product-gallery',mixins:[vmGallery],};const vcProductGalleryInternational={template:'#vc-component-product-gallery-international',mixins:[vmGallery],};const vcProductHeader={template:'#vc-component-product-header',mixins:[vmProduct],};const vcProductInstalments={template:'#vc-component-product-instalments',mixins:[vmProduct],data(){return{sliderOptions:{infinite:!1,slidesToShow:1,slidesToScroll:1,arrows:!1,fade:!0,autoplay:!0,autoplaySpeed:4000,},}},};const vcProductCallToAction={template:'#vc-component-product-call-to-action',mixins:[vmProduct],data(){return{legend:{'Coming Soon':'soon','Sold Out':'none','Nearly Gone':'low','In Stock':'high',},isStockAvailabilityVisible:!0,}},computed:{monogram(){return this.$store.state.monogram},},methods:{getStockStatus(option){var statuses={high:{className:'high',label:'In Stock',},limitedstock:{className:'low',label:'Nearly Gone',},disabled:{className:'none',label:'Sold Out',},};return statuses[option.status]||statuses.high},toggleStockAvailability(){this.isStockAvailabilityVisible=!this.isStockAvailabilityVisible},extractLabel(storeId,size){var extractLabel='Sold Out';if(this.product.storestock&&this.product.storestock.stock&&this.product.storestock.stock[this.styleColour.stylecolourid]&&this.product.storestock.stock[this.styleColour.stylecolourid][storeId]&&this.product.storestock.stock[this.styleColour.stylecolourid][storeId][size]){extractLabel=this.product.storestock.stock[this.styleColour.stylecolourid][storeId][size].label}
return extractLabel},extractStock(storeId,size){var extractStock=0;if(this.product.storestock&&this.product.storestock.stock&&this.product.storestock.stock[this.styleColour.stylecolourid]&&this.product.storestock.stock[this.styleColour.stylecolourid][storeId]&&this.product.storestock.stock[this.styleColour.stylecolourid][storeId][size]){extractStock=this.product.storestock.stock[this.styleColour.stylecolourid][storeId][size].stock}
return extractStock},scrollToSize:function(){$('#sizeAndFit-tab-button').click();var selectedTab=$('#sizeAndFit-tab');$([document.documentElement,document.body]).animate({scrollTop:$('.product-details-nav').offset().top-120},500);$(selectedTab).addClass('is-highlighted');setTimeout(function(){$(selectedTab).removeClass('is-highlighted')},2500)},},mounted(){$(document).on('change','.j-sizeguideselect',function(e){e.preventDefault();$('.j-sizeguideoption').removeClass('j-active');$('.size-guide-table-wrap').removeClass('j-active').addClass('is-hidden');$(this).children(':selected').addClass('j-active');$(`.${  $(this).val()  }-table`).removeClass('is-hidden').addClass('j-active')})},};const vcProductDelivery={template:'#vc-component-product-delivery',mixins:[vmProduct],computed:{availableStock(){var selectedStoreStock=this.product.storestock.stock[this.styleColour.stylecolourid][this.selectedStoreId];var availableStoreStock=Object.keys(selectedStoreStock).reduce((availableSizes,size)=>{if(['Sold Out','Coming Soon'].indexOf(selectedStoreStock[size].label)===-1){availableSizes.push(size)}
return availableSizes},[]);return availableStoreStock.length?availableStoreStock.join(', '):'None Available'},selectedStore(){return this.$store.getters.selectedStore},selectedStoreId(){return this.$store.getters.selectedStoreId},},};const vcProductDetails={template:'#vc-component-product-details',mixins:[vmProduct],data:function(){return{activeTab:'details-tab',}},computed:{bullets(){if(typeof this.styleColour.attributes.Bullets==='undefined')return[];return this.styleColour.attributes.Bullets.split('\n')},careInstruction(){return[].concat(this.styleColour.attributes.CareInstruction)},hasSizeFit(){var self=this;var attributes=['ModelName','ModelSize','FitNote'];return attributes.some((attribute)=>{return!!self.styleColour.attributes[attribute]})},tabs:function(){var tabs={};tabs.details='Product Details';if(this.hasSizeFit){tabs.sizeAndFit='Size & Fit'}
if(this.styleColour.attributes.CareInstruction){tabs.careInstructions='Fabric & Care Guide'}
return tabs},},methods:{newlinesToBreaks(text){return text.split('\r\n').join('<br>')},scrollToTab:function(tabKey){var selectedTab=this.$refs[tabKey+'-tab'];$([document.documentElement,document.body]).animate({scrollTop:$(selectedTab).offset().top-120},500)},toggleTab:function(tabKey){var selectedTab=this.$refs[tabKey+'-tab'];this.activeTab=tabKey+'-tab'},openSizeGuidePopup(){loadslidein('slide-in-size-guide',`/slide-in-size-guide?i=${  this.product.brand.brandid  }&s=${  this.product.style}`)},},};const vcProductUpsell={template:'#vc-component-product-upsell',mixins:[vmProduct],components:{'product-slider':vcProductSlider,},computed:{theLook(){var theLookItems=this.product.thelookitems;if(typeof theLookItems==='undefined'||!theLookItems)return[];if(typeof this.styleColour.thelook==='undefined')return[];return this.styleColour.thelook.map((style)=>{return theLookItems[style]}).filter(Boolean)},},};const vcProductReviews={template:'#vc-component-product-reviews',mixins:[vmProduct],data(){return{isUser:window.customer&&!!window.customer.loggedin,visible:2,}},computed:{visibleReviews(){return this.product.reviews.slice(0,this.visible)},},methods:{getDate(date){return new Intl.DateTimeFormat('en-NZ').format(new Date(date))},loadMore(){this.visible+=2},openReviewPopup(){if(this.isUser){this.openPopup('review')}else{loadslidein('slide-in--login-register','/slide-in-login-register')}},},};new Vue({el:'#v-product',name:'Product',store,mixins:[vmProduct],components:{'product-fixed-add-to-cart':vcProductFixedAddToCart,'product-gallery':vcProductGallery,'product-gallery-international':vcProductGalleryInternational,'product-header':vcProductHeader,'product-instalments':vcProductInstalments,'product-call-to-action':vcProductCallToAction,'product-delivery':vcProductDelivery,'product-details':vcProductDetails,'product-upsell':vcProductUpsell,'product-reviews':vcProductReviews,'product-popup-notify':vcProductPopupNotify,'product-popup-delivery':vcProductPopupDelivery,'product-popup-monogram':vcProductPopupMonogram,'product-popup-pickup':vcProductPopupPickup,'product-popup-review':vcProductPopupReview,'product-popup-stock':vcProductPopupStock,'product-popup-stores':vcProductPopupStores,'product-popup-swatch':vcProductPopupSwatch,'product-popup-zoom':vcProductPopupZoom,},computed:{popups(){return this.$store.state.popups},},created(){this.$store.dispatch('getProductData',window.product)},mounted(){$(document).trigger('psevent',['detail',this.$store.state.product.stylecolour.variant.gadata])},})}(jQuery))