/******/ (() => { // webpackBootstrap
/*!***********************************************!*\
  !*** ./assets/src/blocks/video-popup/view.js ***!
  \***********************************************/
document.addEventListener('DOMContentLoaded', function () {
  const buttons = document.querySelectorAll('.video-popup-button');
  buttons.forEach(button => {
    button.addEventListener('click', () => {
      const videoURL = button.getAttribute('data-video-url');
      const videoType = button.getAttribute('data-video-type');
      if (!videoURL || !videoType) return;
      const embedURL = getEmbedURL(videoURL, videoType);
      if (!embedURL) return;
      const overlay = document.createElement('div');
      overlay.className = 'video-popup-overlay';
      overlay.innerHTML = `
				<div class="video-popup-modal">
					<button class="video-popup-close">&times;</button>
					<iframe
						src="${embedURL}?autoplay=1"
						frameborder="0"
						allow="autoplay; fullscreen"
						allowfullscreen
					></iframe>
				</div>
			`;
      document.body.appendChild(overlay);
      overlay.querySelector('.video-popup-close').addEventListener('click', () => {
        document.body.removeChild(overlay);
      });
      overlay.addEventListener('click', e => {
        if (e.target === overlay) {
          document.body.removeChild(overlay);
        }
      });
    });
  });
});

/**
 * Get embed URL for supported platforms
 * @param {string} url - Original video URL
 * @param {string} type - 'youtube' or 'vimeo'
 * @returns {string|null} - Embed URL
 */
function getEmbedURL(url, type) {
  if (type === 'youtube') {
    if (url.includes('youtube.com/embed/')) return url;
    const match = url.match(/(?:youtube\.com\/watch\?v=|youtu\.be\/)([\w-]+)/);
    return match ? `https://www.youtube.com/embed/${match[1]}` : null;
  }
  if (type === 'vimeo') {
    if (url.includes('player.vimeo.com/video/')) return url;
    const match = url.match(/vimeo\.com\/(\d+)/);
    return match ? `https://player.vimeo.com/video/${match[1]}` : null;
  }
  return null;
}
/******/ })()
;
//# sourceMappingURL=view.js.map