(function(){
'use strict';

const qs  = (s, ctx) => (ctx||document).querySelector(s);
const qsa = (s, ctx) => [...(ctx||document).querySelectorAll(s)];

/* ── Service row interactivity */
const svcRows     = qsa('.svc-row');
const svcPanel    = qs('#svcPanel');
const svcPanelIco   = qs('#svcPanelIco');
const svcPanelIcon  = qs('#svcPanelIcon');
const svcPanelTitle = qs('#svcPanelTitle');
const svcPanelDesc  = qs('#svcPanelDesc');

const svcData = [
  { icon:'fa-robot',                  title:'AI Optimisation',         desc:'Automate workflows, integrate AI tools, and build intelligent digital products that work harder for your business.' },
  { icon:'fa-magnifying-glass-chart', title:'SEO, GEO & AI Strategy',  desc:'Rank higher on Google and AI search platforms with strategies built for the modern search landscape.' },
  { icon:'fa-chart-line',             title:'Performance Marketing',   desc:'Data-driven marketing strategies for measurable growth — from funnel design to conversion optimisation.' },
];

if(svcPanel) {
  svcRows.forEach(row => {
    row.addEventListener('mouseenter', () => {
      const idx = +row.dataset.idx;
      svcRows.forEach(r => r.classList.remove('active'));
      row.classList.add('active');
      svcPanel.dataset.active = idx;
      if(svcPanelIco)   svcPanelIco.className   = 'fas ' + svcData[idx].icon;
      if(svcPanelTitle) svcPanelTitle.textContent = svcData[idx].title;
      if(svcPanelDesc)  svcPanelDesc.textContent  = svcData[idx].desc;
      if(svcPanelIcon){
        svcPanelIcon.style.transition = 'transform .38s cubic-bezier(.34,1.56,.64,1)';
        svcPanelIcon.style.transform  = 'scale(1.18) rotate(8deg)';
        setTimeout(() => { svcPanelIcon.style.transform = ''; }, 400);
      }
    });
  });
}


/* ── Count-up: stat widgets ([data-hc]) */
const statWidgetObs = new IntersectionObserver((entries) => {
  entries.forEach(entry => {
    if(entry.isIntersecting) {
      qsa('[data-hc]').forEach(el => {
        const end = +el.dataset.hc;
        if (typeof window.countUp === 'function') window.countUp(el, end, 1600);
      });
      statWidgetObs.disconnect();
    }
  });
}, { threshold: 0.3 });
const statGrid = qs('.stat-grid');
if(statGrid) statWidgetObs.observe(statGrid);

})();
