{"version":3,"file":"lightbox.js","sources":["../../FrontEnd/PDP-FE/src/scripts/modules/lightbox.ts"],"sourcesContent":["import { Component } from '@verndale/core';\nimport Swiper from 'swiper';\nimport { Navigation, Keyboard, Pagination, Controller } from 'swiper/modules';\nimport 'swiper/css/bundle';\nimport YouTubeIframeLoader from 'youtube-iframe';\nimport '../../scss/modules/_lightbox.scss';\n\ntype YoutubePlayer = {\n playVideo: () => void;\n pauseVideo: () => void;\n};\n\nclass Lightbox extends Component {\n private videoId: string;\n private player: YoutubePlayer | null = null;\n public lightBoxSwiper: { slideToLoop?: (index: number) => void | undefined, activeIndex?: number };\n\n constructor(el: HTMLElement) {\n super(el);\n this.videoId = this.el.dataset.videoId || '';\n this.lightBoxSwiper = {};\n this.initSwiper();\n }\n\n setupDefaults() {\n this.dom = {\n el: this.el,\n swiperContainer: this.el.querySelector('.swiper'),\n swiperWrapper: this.el.querySelector('.swiper-wrapper'),\n swiperItems: this.el.querySelectorAll('.swiper-slide'),\n pagination: this.el.querySelector('.swiper-pagination'),\n closeBtn: this.el.querySelector('.close'),\n videoContainer: this.el.querySelector('.video-container'),\n shareBtn: this.el.querySelector('.lightbox__share-btn'),\n toastElement: document.querySelector('#toast'),\n boatHeaderTitle: document.querySelector('.boat-header__title')\n };\n\n this.initYoutubePlayer();\n }\n\n addListeners() {\n (this.dom.closeBtn as HTMLElement).addEventListener('click', () => {\n (this.dom.el as HTMLElement).classList.remove('show');\n this.player?.pauseVideo();\n });\n window.addEventListener('mediaGallerySlideChange', e =>\n this.handleGallerySlideChange(e as CustomEvent)\n );\n (this.dom.shareBtn as HTMLElement).addEventListener('click', this.handleShareClick.bind(this));\n }\n\n handleShareClick() {\n if (navigator.share) {\n navigator\n .share({\n title: document.title,\n text: (this.dom.boatHeaderTitle as HTMLElement).textContent || '',\n url: window.location.href\n })\n .then(() => console.log('Successful share'))\n .catch(error => console.log('Error sharing', error));\n } else {\n navigator.clipboard.writeText(window.location.href);\n (this.dom.toastElement as HTMLElement)?.classList.add('show');\n setTimeout(() => {\n (this.dom.toastElement as HTMLElement)?.classList.remove('show');\n }, 3000);\n }\n }\n\n initYoutubePlayer() {\n YouTubeIframeLoader.load(YT => {\n this.player = new YT.Player(this.dom.videoContainer, {\n width: '100%',\n height: '100%',\n videoId: this.videoId\n });\n });\n }\n\n initSwiper() {\n Swiper.use([Navigation, Keyboard, Pagination, Controller]);\n const hash = window.location.hash.substring(1);\n const [mediaType, slideIndex] = hash.split(',');\n const initialSlide = mediaType?.includes('image') && slideIndex ? parseInt(slideIndex) - 1 : 0;\n\n this.lightBoxSwiper = new Swiper(this.dom.swiperContainer as HTMLElement, {\n pagination: {\n el: this.dom.pagination as HTMLElement,\n type: 'fraction'\n },\n initialSlide,\n slidesPerView: 'auto',\n centeredSlides: true,\n loop: true,\n spaceBetween: 16,\n on: {\n realIndexChange: swiper => {\n if (this.el.classList.contains('show')) {\n window.dispatchEvent(\n new CustomEvent('lightboxSlideChange', { detail: swiper.realIndex })\n );\n }\n }\n }\n });\n }\n\n handleGallerySlideChange(e: CustomEvent) {\n if (this.lightBoxSwiper?.slideToLoop) {\n this.lightBoxSwiper.slideToLoop(e.detail);\n }\n }\n}\n\nexport default Lightbox;"],"names":["Lightbox","Component","el","__publicField","_a","error","YouTubeIframeLoader","YT","Swiper","Navigation","Keyboard","Pagination","Controller","hash","mediaType","slideIndex","initialSlide","swiper"],"mappings":"0SAYA,MAAMA,UAAiBC,CAAU,CAK/B,YAAYC,EAAiB,CAC3B,MAAMA,CAAE,EALFC,EAAA,gBACAA,EAAA,cAA+B,MAChCA,EAAA,uBAIL,KAAK,QAAU,KAAK,GAAG,QAAQ,SAAW,GAC1C,KAAK,eAAiB,GACtB,KAAK,WAAW,CAClB,CAEA,eAAgB,CACd,KAAK,IAAM,CACT,GAAI,KAAK,GACT,gBAAiB,KAAK,GAAG,cAA2B,SAAS,EAC7D,cAAe,KAAK,GAAG,cAA2B,iBAAiB,EACnE,YAAa,KAAK,GAAG,iBAA8B,eA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