// ── Footer ────────────────────────────────────────────────────────────────────

const Footer = ({ setPage }) => (
  <footer style={{ background:'#090D13', padding:'clamp(3rem,6vh,5rem) clamp(1.5rem,8vw,8rem) 2rem', borderTop:'1px solid rgba(255,255,255,0.04)' }}>
    <div style={{ display:'grid', gridTemplateColumns:'repeat(auto-fit, minmax(200px, 1fr))', gap:'3rem', marginBottom:'3rem' }}>
      {/* Brand */}
      <div>
        <div style={{ fontFamily:'Bricolage Grotesque,Inter,sans-serif', fontSize:'1.3rem', fontWeight:800, color:'#F8FAFC', display:'flex', alignItems:'center', gap:8, marginBottom:'1rem' }}>
          <span>Smartek</span>
          <span style={{ display:'inline-flex', alignItems:'center', justifyContent:'center', width:22, height:22, borderRadius:6, background:'#E8FF47', color:'#0D1117', fontSize:'0.7rem', fontWeight:900 }}>X</span>
        </div>
        <p style={{ fontFamily:'Inter,sans-serif', fontSize:'0.88rem', color:'#64748B', lineHeight:1.7, maxWidth:260 }}>
          Business-First Technology Partner. Teknologi yang bekerja untuk bisnis Anda.
        </p>
        <p style={{ fontFamily:'Inter,sans-serif', fontSize:'0.78rem', color:'#475569', marginTop:'0.75rem' }}>PT Smartek Sistem Kreasi Alpha</p>
      </div>

      {/* Navigasi */}
      <div>
        <p style={{ fontFamily:'Inter,sans-serif', fontSize:'0.75rem', fontWeight:700, color:'#475569', textTransform:'uppercase', letterSpacing:'0.08em', marginBottom:'1rem' }}>Navigasi</p>
        {[['home','Beranda'],['essentials','Essentials'],['enterprise','Enterprise'],['portfolio','Portfolio'],['insights','Insights'],['about','Tentang Kami'],['contact','Kontak']].map(([id, label]) => (
          <button key={id} onClick={() => setPage(id)} style={{ display:'block', background:'none', border:'none', cursor:'pointer', fontFamily:'Inter,sans-serif', fontSize:'0.9rem', color:'#64748B', padding:'4px 0', textAlign:'left', transition:'color 0.2s' }}
          onMouseEnter={e => e.target.style.color = '#B3D4FF'}
          onMouseLeave={e => e.target.style.color = '#64748B'}
          >{label}</button>
        ))}
      </div>

      {/* Layanan */}
      <div>
        <p style={{ fontFamily:'Inter,sans-serif', fontSize:'0.75rem', fontWeight:700, color:'#475569', textTransform:'uppercase', letterSpacing:'0.08em', marginBottom:'1rem' }}>Layanan</p>
        {[
          ['AI Audit Gratis ✦', 'contact', '→ Gratis, tanpa komitmen'],
          ['Smartek X Essentials', 'essentials', 'untuk UMKM & bisnis berkembang'],
          ['Smartek X Enterprise', 'enterprise', 'untuk korporasi & pemerintah'],
          ['AI Transformation Consulting', 'enterprise', null],
          ['Custom Software Development', 'enterprise', null],
        ].map(([label, page, sub]) => (
          <div key={label} style={{ marginBottom:'0.6rem' }}>
            <button onClick={() => setPage(page)}
            onMouseEnter={e => e.currentTarget.style.color = label.includes('✦') ? '#E8FF47' : '#B3D4FF'}
            onMouseLeave={e => e.currentTarget.style.color = label.includes('✦') ? '#C8DC20' : '#64748B'}
            style={{ display:'block', background:'none', border:'none', cursor:'pointer', fontFamily:'Inter,sans-serif', fontSize:'0.88rem', color: label.includes('✦') ? '#E8FF47' : '#64748B', padding:'0', textAlign:'left', transition:'color 0.2s', fontWeight: label.includes('✦') ? 600 : 400 }}>
              {label}
            </button>
            {sub && <p style={{ fontFamily:'Inter,sans-serif', fontSize:'0.7rem', color:'#374151', marginTop:2 }}>{sub}</p>}
          </div>
        ))}
      </div>

      {/* Kontak */}
      <div>
        <p style={{ fontFamily:'Inter,sans-serif', fontSize:'0.75rem', fontWeight:700, color:'#475569', textTransform:'uppercase', letterSpacing:'0.08em', marginBottom:'1rem' }}>Kontak</p>
        <p style={{ fontFamily:'Inter,sans-serif', fontSize:'0.88rem', color:'#64748B', lineHeight:1.6, marginBottom:'0.75rem' }}>BITC Cimahi, Jawa Barat, Indonesia</p>
        <p style={{ fontFamily:'Inter,sans-serif', fontSize:'0.88rem', color:'#64748B', marginBottom:'0.5rem' }}>hello@smarteksistem.com</p>
        <a href="https://wa.me/6281211008850?text=Halo%20Smartek%20X%2C%20saya%20ingin%20berdiskusi%20lebih%20lanjut." target="_blank" rel="noreferrer" style={{ display:'inline-flex', alignItems:'center', gap:6, marginTop:'0.5rem', color:'#25D366', fontFamily:'Inter,sans-serif', fontSize:'0.88rem', fontWeight:600, textDecoration:'none' }}>
          <svg width="14" height="14" viewBox="0 0 24 24" fill="#25D366"><path d="M17.472 14.382c-.297-.149-1.758-.867-2.03-.967-.273-.099-.471-.148-.67.15-.197.297-.767.966-.94 1.164-.173.199-.347.223-.644.075-.297-.15-1.255-.463-2.39-1.475-.883-.788-1.48-1.761-1.653-2.059-.173-.297-.018-.458.13-.606.134-.133.298-.347.446-.52.149-.174.198-.298.298-.497.099-.198.05-.371-.025-.52-.075-.149-.669-1.612-.916-2.207-.242-.579-.487-.5-.669-.51-.173-.008-.371-.01-.57-.01-.198 0-.52.074-.792.372-.272.297-1.04 1.016-1.04 2.479 0 1.462 1.065 2.875 1.213 3.074.149.198 2.096 3.2 5.077 4.487.709.306 1.262.489 1.694.625.712.227 1.36.195 1.871.118.571-.085 1.758-.719 2.006-1.413.248-.694.248-1.289.173-1.413-.074-.124-.272-.198-.57-.347z"/><path d="M12 0C5.373 0 0 5.373 0 12c0 2.118.549 4.107 1.51 5.831L0 24l6.335-1.487A11.945 11.945 0 0012 24c6.627 0 12-5.373 12-12S18.627 0 12 0zm0 21.818a9.8 9.8 0 01-5.03-1.385l-.36-.214-3.762.883.932-3.654-.235-.376A9.79 9.79 0 012.182 12C2.182 6.57 6.57 2.182 12 2.182S21.818 6.57 21.818 12 17.43 21.818 12 21.818z"/></svg>
          WhatsApp
        </a>
      </div>
    </div>
    <div style={{ borderTop:'1px solid rgba(255,255,255,0.04)', paddingTop:'1.5rem', display:'flex', flexWrap:'wrap', justifyContent:'space-between', gap:'0.75rem', alignItems:'center' }}>
      <p style={{ fontFamily:'Inter,sans-serif', fontSize:'0.78rem', color:'#374151' }}>© 2026 PT Smartek Sistem Kreasi Alpha. Semua hak dilindungi.</p>
      <p style={{ fontFamily:'Inter,sans-serif', fontSize:'0.78rem', color:'#374151' }}>Bandung Innovation &amp; Technology Center</p>
    </div>
  </footer>
);

// ── WhatsApp FAB ──────────────────────────────────────────────────────────────

const WAButton = () => (
  <a href="https://wa.me/6281211008850?text=Halo%20Smartek%20X%2C%20saya%20ingin%20berdiskusi." target="_blank" rel="noreferrer" title="Chat via WhatsApp" style={{
    position:'fixed', bottom:28, right:28, zIndex:200,
    width:56, height:56, borderRadius:'50%',
    background:'#25D366', color:'#fff',
    display:'flex', alignItems:'center', justifyContent:'center',
    boxShadow:'0 4px 24px rgba(37,211,102,0.4)',
    transition:'transform 0.2s, box-shadow 0.2s',
    textDecoration:'none',
  }}
  onMouseEnter={e => { e.currentTarget.style.transform = 'scale(1.08)'; e.currentTarget.style.boxShadow = '0 6px 32px rgba(37,211,102,0.5)'; }}
  onMouseLeave={e => { e.currentTarget.style.transform = 'none'; e.currentTarget.style.boxShadow = '0 4px 24px rgba(37,211,102,0.4)'; }}
  >
    <svg width="28" height="28" viewBox="0 0 24 24" fill="#fff">
      <path d="M17.472 14.382c-.297-.149-1.758-.867-2.03-.967-.273-.099-.471-.148-.67.15-.197.297-.767.966-.94 1.164-.173.199-.347.223-.644.075-.297-.15-1.255-.463-2.39-1.475-.883-.788-1.48-1.761-1.653-2.059-.173-.297-.018-.458.13-.606.134-.133.298-.347.446-.52.149-.174.198-.298.298-.497.099-.198.05-.371-.025-.52-.075-.149-.669-1.612-.916-2.207-.242-.579-.487-.5-.669-.51-.173-.008-.371-.01-.57-.01-.198 0-.52.074-.792.372-.272.297-1.04 1.016-1.04 2.479 0 1.462 1.065 2.875 1.213 3.074.149.198 2.096 3.2 5.077 4.487.709.306 1.262.489 1.694.625.712.227 1.36.195 1.871.118.571-.085 1.758-.719 2.006-1.413.248-.694.248-1.289.173-1.413-.074-.124-.272-.198-.57-.347z"/>
      <path d="M12 0C5.373 0 0 5.373 0 12c0 2.118.549 4.107 1.51 5.831L0 24l6.335-1.487A11.945 11.945 0 0012 24c6.627 0 12-5.373 12-12S18.627 0 12 0zm0 21.818a9.8 9.8 0 01-5.03-1.385l-.36-.214-3.762.883.932-3.654-.235-.376A9.79 9.79 0 012.182 12C2.182 6.57 6.57 2.182 12 2.182S21.818 6.57 21.818 12 17.43 21.818 12 21.818z"/>
    </svg>
  </a>
);

// ── Hash Router ───────────────────────────────────────────────────────────────

const SLUG_TO_PAGE = {
  '/':              'home',
  '/services':      'services',
  '/essentials':    'essentials',
  '/enterprise':    'enterprise',
  '/case-studies':  'portfolio',
  '/insights':      'insights',
  '/why-smartek-x': 'about',
  '/contact':       'contact',
};

const PAGE_TO_SLUG = {
  home:      '/',
  services:  '/services',
  essentials: '/essentials',
  enterprise: '/enterprise',
  portfolio:  '/case-studies',
  insights:   '/insights',
  about:      '/why-smartek-x',
  contact:    '/contact',
};

const getPageFromHash = () => {
  const slug = window.location.hash.replace(/^#/, '') || '/';
  return SLUG_TO_PAGE[slug] || 'home';
};

// ── App ───────────────────────────────────────────────────────────────────────

const App = () => {
  const [page, setPage] = React.useState(getPageFromHash);

  React.useEffect(() => {
    const onHashChange = () => {
      setPage(getPageFromHash());
      window.scrollTo({ top: 0, behavior: 'instant' });
    };
    window.addEventListener('hashchange', onHashChange);
    return () => window.removeEventListener('hashchange', onHashChange);
  }, []);

  const navigate = (p) => {
    const slug = PAGE_TO_SLUG[p] || '/';
    window.location.hash = slug;
  };

  const pages = {
    home:       HomePage,
    services:   ServicesPage,
    essentials: EssentialsPage,
    enterprise: EnterprisePage,
    portfolio:  PortfolioPage,
    insights:   InsightsPage,
    about:      AboutPage,
    contact:    ContactPage,
  };
  const Page = pages[page] || HomePage;

  return (
    <>
      <Nav page={page} setPage={navigate} />
      <main><Page setPage={navigate} /></main>
      <Footer setPage={navigate} />
      <WAButton />
    </>
  );
};

const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(<App />);
