/// file: public/assets/js/app.js

import { initPreloader } from './modules/preloader.js';
import { initMenu } from './modules/menu.js';
import { initCursor } from './modules/cursor.js';
import { initPageTransitions } from './modules/page-transitions.js';
import { initSmoothScroll } from './modules/smooth-scroll.js';
import { initTextReveal } from './modules/text-reveal.js';
import { initParallax } from './modules/parallax.js';
import { initMagnetic } from './modules/magnetic.js';
import { initHomeTouch } from './modules/home-touch.js';
import { initHomeDiamondHero } from './modules/home-diamond-hero.js';
import { initHomeAmbientLights } from './modules/home-ambient-lights.js';
import { initHomeIntro } from './modules/home-intro.js';
import { initMenuCrystal } from './modules/webgl-hero.js';
import { initForms } from './modules/forms.js';
import { initWorkPage } from './page-work.js';

document.addEventListener('DOMContentLoaded', () => {
  const cfg = window.__SANEKSA__ || {};
  const page = cfg.page || '';

  initSmoothScroll();
  initPreloader();
  initMenu();
  initMenuCrystal();
  initCursor();
  initPageTransitions();
  initTextReveal();
  initParallax();
  initMagnetic();
  if (page === 'home') {
    initHomeIntro();
    initHomeDiamondHero();
    initHomeTouch();
    initHomeAmbientLights();
  }
  if (page === 'work') {
    initWorkPage();
  }
  initForms();
  initProjectMedia();
});

function initProjectMedia() {
  document.querySelectorAll('.project-card').forEach((card) => {
    const vid = card.querySelector('.project-card__video');
    card.addEventListener('mouseenter', () => {
      if (vid && vid instanceof HTMLVideoElement) {
        vid.play().catch(() => {});
      }
    });
    card.addEventListener('mouseleave', () => {
      if (vid && vid instanceof HTMLVideoElement) {
        vid.pause();
        vid.currentTime = 0;
      }
    });
  });
}
