'use client';

import { useEffect, useRef } from 'react';
import Image from 'next/image';

export default function HeroSection() {
  const punchlineRef = useRef<HTMLDivElement>(null);
  const punchlineSmallRef = useRef<HTMLDivElement>(null);
  const strip1Ref = useRef<HTMLDivElement>(null);
  const strip2Ref = useRef<HTMLDivElement>(null);
  const strip3Ref = useRef<HTMLDivElement>(null);

  useEffect(() => {
    const t1 = setTimeout(() => {
      punchlineRef.current?.classList.add('slide-in-blurred-bottom');
      punchlineSmallRef.current?.classList.add('slide-in-blurred-bottom');
    }, 100);
    const t2 = setTimeout(() => {
      strip1Ref.current?.classList.add('slide-in-blurred-bottom');
      strip2Ref.current?.classList.add('slide-in-blurred-bottom');
      strip3Ref.current?.classList.add('slide-in-blurred-bottom');
    }, 700);
    return () => { clearTimeout(t1); clearTimeout(t2); };
  }, []);

  const scrollToNext = (e: React.MouseEvent) => {
    e.preventDefault();
    const sections = document.querySelectorAll('main > section');
    if (sections[1]) sections[1].scrollIntoView({ behavior: 'smooth' });
  };

  return (
    <section
      style={{
        height: '100vh',
        display: 'flex',
        justifyContent: 'center',
        alignItems: 'center',
        position: 'relative',
        zIndex: 2,
        overflow: 'hidden',
      }}
    >
      {/* ── Background builder ── */}
      <div
        style={{
          position: 'absolute',
          width: '100%',
          height: '100%',
          top: 0,
          left: 0,
          overflow: 'hidden',
        }}
      >
        {/* black-strip */}
        <div
          ref={strip1Ref}
          className="hero-strip-black"
          style={{
            visibility: 'hidden',
            position: 'absolute',
            backgroundColor: 'rgba(0,0,0,0.45)',
            width: '60%',
            height: '40%',
            top: '37%',
            left: '-20%',
            transform: 'skewX(-30deg) scaleY(0.86)',
            zIndex: 1,
          }}
        />

        {/* blue-strip */}
        <div
          ref={strip2Ref}
          className="hero-strip-blue"
          style={{
            visibility: 'hidden',
            position: 'absolute',
            backgroundColor: 'rgba(31,113,163,0.6)',
            width: '50%',
            height: '40%',
            top: '23%',
            right: '-23%',
            transform: 'skewX(-30deg) scaleY(0.86)',
            zIndex: 1,
          }}
        />

        {/* red-strip — float wrapper isolates translateY from the slide-in transform */}
        <div
          className="hero-orange-float"
          style={{
            position: 'absolute',
            width: '50%',
            height: '50%',
            top: '25%',
            left: '25%',
            zIndex: 3,
            filter:
              'drop-shadow(0px 28px 48px rgba(0,0,0,0.55)) drop-shadow(0px 6px 18px rgba(216,82,24,0.35))',
          }}
        >
          <div
            ref={strip3Ref}
            className="hero-strip-orange"
            style={{
              visibility: 'hidden',
              position: 'absolute',
              inset: 0,
              backgroundColor: '#d85218',
              transform: 'skewX(-25deg) scaleY(0.86)',
            }}
          />
        </div>

        {/* Mobile hint tiles — peek in from corners, desktop-hidden via CSS */}
        <div
          className="hero-tile-hint hero-tile-hint-br"
          style={{
            position: 'absolute',
            width: '70%',
            height: '70%',
            bottom: '-18%',
            right: '-18%',
            backgroundImage: "url('/img/bitsia-logo-orange-hint.svg')",
            backgroundRepeat: 'no-repeat',
            backgroundPosition: 'center',
            backgroundSize: 'contain',
            zIndex: 2,
          }}
        />
        <div
          className="hero-tile-hint hero-tile-hint-tl"
          style={{
            position: 'absolute',
            width: '55%',
            height: '55%',
            top: '-16%',
            left: '-16%',
            backgroundImage: "url('/img/bitsia-logo-orange-hint.svg')",
            backgroundRepeat: 'no-repeat',
            backgroundPosition: 'center',
            backgroundSize: 'contain',
            zIndex: 2,
          }}
        />

        {/* Mobile overlay */}
        <div
          className="mob-overlay"
          style={{ position: 'absolute', top: 0, left: 0, width: '100%', height: '100%', zIndex: 5 }}
        />
      </div>

      {/* ── Content ── */}
      <div
        style={{
          position: 'relative',
          zIndex: 6,
          textAlign: 'center',
          display: 'flex',
          flexDirection: 'column',
          alignItems: 'center',
        }}
      >
        <div
          ref={punchlineRef}
          className="hero-punchline"
          style={{
            visibility: 'hidden',
            color: '#fff',
            fontFamily: "'canada-type-gibson', Arial, Helvetica, sans-serif",
            fontSize: '4em',
            fontWeight: 'bold',
            letterSpacing: '-3px',
            lineHeight: 1,
            paddingBottom: 8,
            marginBottom: 20,
          }}
        >
          <Image
            src="/img/bitsia-logo-orange-simple-inverse.svg"
            alt="Bitsia"
            width={100}
            height={100}
            priority
            style={{ display: 'block', margin: '0 auto 20px', width: 100, height: 100, maxWidth: '28vw', maxHeight: '28vw' }}
          />
          <h1 style={{ margin: 0, padding: 0, lineHeight: 0, fontSize: 0 }}>
            <Image
              src="/img/bitsia-logo-orange-bitsia-only-inverse-tight.svg"
              alt="Bitsia"
              width={180}
              height={58}
              priority
              style={{ display: 'block', margin: '0 auto', maxWidth: '55vw', height: 'auto', paddingBottom: '17px' }}
            />
          </h1>
          <div style={{ fontSize: '0.625em', letterSpacing: 0 }}>IT solutions with a business mind</div>
        </div>

        <div
          ref={punchlineSmallRef}
          style={{
            visibility: 'hidden',
            maxWidth: 480,
            fontSize: '1.063em',
            color: '#fff',
            lineHeight: '22px',
            padding: '0 16px',
          }}
        >
          Every project gets our complete team — developers, designers, marketers, and business consultants
          working together toward your goals. Not just code. Real solutions.
        </div>
      </div>

      {/* ── Scroll down ── */}
      <a
        href="#"
        onClick={scrollToNext}
        aria-label="Scroll down"
        className="hero-scroll-down"
        style={{
          position: 'absolute',
          minWidth: 50,
          minHeight: 50,
          bottom: 36,
          left: '50%',
          transform: 'translateX(-50%)',
          backgroundImage: "url('/img/scroll-down-orange.svg')",
          backgroundRepeat: 'no-repeat',
          backgroundPosition: 'center',
          zIndex: 999,
          display: 'block',
        }}
      >
        <div className="hero-scroll-dot" style={{ position: 'absolute', width: 2, height: 2, borderRadius: 20, backgroundColor: '#d85218', top: 'calc(50% - 2px)', left: 'calc(50% + 9px)', marginTop: -10, marginLeft: -10 }} />
        <div className="scroll-down-infinite hero-scroll-dot" style={{ position: 'absolute', width: 4, height: 4, borderRadius: 20, backgroundColor: '#d85218', top: 'calc(50% - 9px)', left: 'calc(50% + 8px)', marginTop: -10, marginLeft: -10 }} />
      </a>
    </section>
  );
}
