---
/**
 * MOREMINIMORE - KINETIC HERO COMPONENT (LIGHT THEME)
 * Yellow/white/black editorial — no dark bg
 */
import Icon from './Icon.astro';

interface Props {
  badge?: string;
  title: string;
  subtitle?: string;
  showCTA?: boolean;
  ctaText?: string;
  ctaLink?: string;
}

const {
  badge = 'Moreminimore',
  title = 'เราจะช่วยคุณเพิ่มกำไร',
  subtitle = 'เราช่วยวางระบบงาน และใช้สถิติวางกลยุทธ์ทางการตลาด',
  showCTA = true,
  ctaText = 'เริ่มปรึกษาฟรี',
  ctaLink = '/contact',
  pains = [
    { surface: 'yellow', text: 'ยิ่งขาย กำไรยิ่งลด?' },
    { surface: 'purple-soft', text: 'มีเว็บไซต์ เหมือนไม่มี?' },
    { surface: 'mint', text: 'พนักงานทำงานได้น้อยกว่าที่ต้องการ?' },
    { surface: 'teal', text: 'เอา AI มาให้ใช้ แต่งานไม่ได้มากขึ้นตามที่คิด?' },
  ],
} = Astro.props;

// Split title into words for kinetic animation
const titleWords = title.split(' ');
---

<section class="kinetic-hero">
  <!-- Animated Background Pattern (LIGHT THEME) -->
  <div class="hero-bg">
    <div class="bg-grid"></div>
    <div class="bg-gradient"></div>
  </div>

  <!-- Floating Geometric Elements (yellow, subtle) -->
  <div class="hero-geometric">
    <div class="geo-circle geo-1"></div>
    <div class="geo-circle geo-2"></div>
    <div class="geo-circle geo-3"></div>
    <div class="geo-ring ring-1"></div>
    <div class="geo-ring ring-2"></div>
    <div class="geo-line line-1"></div>
    <div class="geo-line line-2"></div>
  </div>

  <div class="container hero-container">
    <!-- 2-COLUMN LAYOUT: text (left) + pain stack (right) -->
    <div class="hero-grid">
      <!-- LEFT: text content -->
      <div class="hero-text">
        <!-- Badge -->
        <div class="hero-badge" data-animate="fade-in">
          <span class="badge-dot"></span>
          {badge}
        </div>

        <!-- Main Title - Kinetic Typography -->
        <h1 class="hero-title kinetic-title">
          {titleWords.map((word, index) => (
            <span class="word-wrapper">
              <span
                class="word"
                style={`--delay: ${0.4 + index * 0.12}s`}
              >
                {word}
              </span>
            </span>
          ))}
        </h1>

        <!-- Accent Line -->
        <div class="hero-accent-line">
          <div class="accent-fill"></div>
        </div>

        <!-- Subtitle -->
        <p class="hero-subtitle" data-animate="fade-in-up">
          <Fragment set:html={subtitle} />
        </p>

        <!-- CTA Buttons -->
        {showCTA && (
          <div class="hero-actions" data-animate="fade-in-up">
            <a href={ctaLink} class="btn btn-primary btn-magnetic">
              <span class="btn-text">{ctaText}</span>
              <svg class="btn-arrow" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="3">
                <path d="M5 12h14M12 5l7 7-7 7"/>
              </svg>
            </a>
            <slot name="hero-cta-secondary" />
          </div>
        )}

        <slot name="hero-trust" />
      </div>

      <!-- RIGHT: pain card stack -->
      <div class="hero-pain-stack" data-animate="fade-in-up">
        {pains.map((p, i) => (
          <div class={`pain-card pain-${p.surface}`} style={`--pain-delay: ${0.6 + i * 0.15}s`}>
            <div class="pain-eyebrow">คุณกำลังเจอปัญหา</div>
            <div class="pain-text">{p.text}</div>
          </div>
        ))}
      </div>
    </div>
  </div>

  <!-- Giant Background Typography -->
  <div class="hero-bg-text" aria-hidden="true">
    AI
  </div>

  <!-- Scroll Indicator -->
  <div class="scroll-indicator">
    <span class="scroll-text">เลื่อนลง</span>
    <div class="scroll-line">
      <div class="scroll-dot"></div>
    </div>
  </div>
</section>

<style>
  /* ============================================
     HERO BASE — LIGHT THEME (white bg, yellow accent)
     ============================================ */

  .kinetic-hero {
    position: relative;
    min-height: 100vh;
    display: flex;
    align-items: center;
    background: var(--color-white);
    overflow: hidden;
  }

  /* ============================================
     BACKGROUND
     ============================================ */

  .hero-bg {
    position: absolute;
    inset: 0;
    z-index: 0;
  }

  .bg-grid {
    position: absolute;
    inset: 0;
    background-image:
      linear-gradient(rgba(254, 212, 0, 0.08) 1px, transparent 1px),
      linear-gradient(90deg, rgba(254, 212, 0, 0.08) 1px, transparent 1px);
    background-size: 60px 60px;
    animation: gridMove 20s linear infinite;
  }

  @keyframes gridMove {
    0% { transform: translate(0, 0); }
    100% { transform: translate(60px, 60px); }
  }

  .bg-gradient {
    position: absolute;
    inset: 0;
    background: radial-gradient(ellipse at 30% 20%, rgba(254, 212, 0, 0.15) 0%, transparent 50%),
                radial-gradient(ellipse at 70% 80%, rgba(254, 212, 0, 0.08) 0%, transparent 50%);
  }

  /* ============================================
     GEOMETRIC ELEMENTS (yellow on light — very subtle)
     ============================================ */

  .hero-geometric {
    position: absolute;
    inset: 0;
    pointer-events: none;
    overflow: hidden;
  }

  .geo-circle {
    position: absolute;
    border-radius: 50%;
    background: var(--color-primary);
  }

  .geo-1 {
    width: 400px;
    height: 400px;
    top: -100px;
    right: 10%;
    opacity: 0.08;
    animation: floatGeo1 12s ease-in-out infinite;
  }

  .geo-2 {
    width: 250px;
    height: 250px;
    bottom: 10%;
    left: -50px;
    opacity: 0.12;
    animation: floatGeo2 10s ease-in-out infinite;
  }

  .geo-3 {
    width: 150px;
    height: 150px;
    top: 40%;
    right: 30%;
    opacity: 0.06;
    animation: floatGeo3 8s ease-in-out infinite;
  }

  @keyframes floatGeo1 {
    0%, 100% { transform: translate(0, 0) rotate(0deg); }
    50% { transform: translate(-30px, -50px) rotate(45deg); }
  }

  @keyframes floatGeo2 {
    0%, 100% { transform: translate(0, 0); }
    50% { transform: translate(40px, -30px); }
  }

  @keyframes floatGeo3 {
    0%, 100% { transform: translate(0, 0) scale(1); }
    50% { transform: translate(-20px, 30px) scale(1.1); }
  }

  .geo-ring {
    position: absolute;
    border: 2px solid var(--color-primary);
    border-radius: 50%;
    opacity: 0.2;
  }

  .ring-1 {
    width: 300px;
    height: 300px;
    top: 10%;
    left: 60%;
    animation: rotateRing 20s linear infinite;
  }

  .ring-2 {
    width: 180px;
    height: 180px;
    bottom: 20%;
    right: 20%;
    animation: rotateRing 15s linear infinite reverse;
  }

  @keyframes rotateRing {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
  }

  .geo-line {
    position: absolute;
    background: var(--color-primary);
    opacity: 0.2;
  }

  .line-1 {
    width: 200px;
    height: 2px;
    top: 25%;
    right: 15%;
    animation: lineSlide 8s ease-in-out infinite;
  }

  .line-2 {
    width: 2px;
    height: 150px;
    bottom: 30%;
    left: 25%;
    animation: lineSlide 10s ease-in-out infinite reverse;
  }

  @keyframes lineSlide {
    0%, 100% { transform: translateX(0); opacity: 0.2; }
    50% { transform: translateX(30px); opacity: 0.3; }
  }

  /* ============================================
     CONTAINER & CONTENT
     ============================================ */

  .hero-container {
    position: relative;
    z-index: 1;
    padding: 140px var(--gutter) 100px;
    max-width: 1600px;
  }

  /* ============================================
     HERO GRID — 2 COLUMNS (text + pain stack)
     ============================================ */

  .hero-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 60px;
    align-items: center;
  }

  .hero-text {
    min-width: 0;
  }

  .hero-pain-stack {
    display: flex;
    flex-direction: column;
    gap: 20px;
    min-width: 0;
  }

  .pain-card {
    padding: 28px 32px;
    border-radius: var(--radius-xl);
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.08);
    border: 1px solid transparent;
    opacity: 0;
    transform: translateY(20px);
    animation: painReveal 0.7s var(--ease-out-expo) var(--pain-delay, 0s) forwards;
    transition: transform 0.4s var(--ease-out-expo);
  }
  .pain-card:hover {
    transform: translateY(-4px);
  }

  @keyframes painReveal {
    to {
      opacity: 1;
      transform: translateY(0);
    }
  }

  .pain-yellow {
    background: var(--color-primary);
    color: var(--color-black);
  }
  .pain-purple-soft {
    background: var(--color-purple-soft);
    color: var(--color-black);
  }
  .pain-mint {
    background: var(--color-mint-soft);
    color: var(--color-black);
  }
  .pain-teal {
    background: var(--color-teal);
    color: var(--color-white);
  }
  .pain-teal .pain-eyebrow { color: var(--color-primary); }

  .pain-eyebrow {
    font-family: var(--font-display);
    font-size: 11px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 2px;
    opacity: 0.7;
    margin-bottom: 8px;
  }

  .pain-text {
    font-family: var(--font-display);
    font-size: 22px;
    font-weight: 800;
    line-height: 1.3;
  }

  @media (max-width: 1024px) {
    .hero-grid {
      grid-template-columns: 1fr;
      gap: 40px;
    }
    .hero-text {
      order: 1;
    }
    .hero-pain-stack {
      order: 2;
    }
  }

  @media (max-width: 640px) {
    .pain-text { font-size: 18px; }
    .pain-card { padding: 20px 24px; }
  }

  /* ============================================
     BADGE
     ============================================ */

  .hero-badge {
    display: inline-flex;
    align-items: center;
    gap: 12px;
    padding: 12px 24px;
    background: var(--color-primary);
    border: 1px solid var(--color-primary);
    border-radius: var(--radius-full);
    font-family: var(--font-display);
    font-size: 13px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 3px;
    color: var(--color-black);
    margin-bottom: 40px;
    opacity: 0;
    animation: fadeIn 0.6s var(--ease-out-expo) 0.2s forwards;
  }

  .badge-dot {
    width: 8px;
    height: 8px;
    background: var(--color-black);
    border-radius: 50%;
    animation: pulse 2s ease-in-out infinite;
  }

  @keyframes pulse {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.5); opacity: 0.5; }
  }

  @keyframes fadeIn {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
  }

  /* ============================================
     KINETIC TITLE — DARK TEXT on white bg
     ============================================ */

  .hero-title {
    font-family: var(--font-display);
    font-size: clamp(40px, 8vw, 90px);
    font-weight: 900;
    /* CRITICAL: line-height must be >1.2 to prevent Thai vowel clipping
       when combined with overflow:hidden on .word-wrapper. */
    line-height: 1.3;
    letter-spacing: -0.01em;
    color: var(--color-black);
    margin-bottom: 32px;
  }

  .word-wrapper {
    display: inline-block;
    /* Use padding (not overflow:hidden) so Thai descenders stay visible. */
    padding: 0.1em 0.05em;
    margin: -0.1em -0.05em;
  }

  .word {
    display: inline-block;
    opacity: 0;
    transform: translateY(100%) skewY(10deg);
    animation: wordReveal 0.9s var(--ease-out-expo) forwards;
    animation-delay: var(--delay);
  }

  @keyframes wordReveal {
    0% {
      opacity: 0;
      transform: translateY(100%) skewY(10deg);
    }
    60% {
      opacity: 1;
      transform: translateY(-5%) skewY(-2deg);
    }
    100% {
      opacity: 1;
      transform: translateY(0) skewY(0);
    }
  }

  /* ============================================
     ACCENT LINE (yellow)
     ============================================ */

  .hero-accent-line {
    width: 200px;
    height: 6px;
    background: var(--color-gray-200);
    border-radius: 3px;
    margin-bottom: 32px;
    overflow: hidden;
    opacity: 0;
    animation: fadeIn 0.6s var(--ease-out-expo) 1s forwards;
  }

  .accent-fill {
    width: 100%;
    height: 100%;
    background: var(--color-primary);
    border-radius: 3px;
    transform-origin: left;
    animation: accentDraw 1s var(--ease-out-expo) 1.2s forwards;
    transform: scaleX(0);
  }

  @keyframes accentDraw {
    to { transform: scaleX(1); }
  }

  /* ============================================
     SUBTITLE
     ============================================ */

  .hero-subtitle {
    font-size: 20px;
    line-height: 1.7;
    color: var(--color-gray-700);
    max-width: 600px;
    margin-bottom: 32px;
    opacity: 0;
    animation: fadeInUp 0.8s var(--ease-out-expo) 0.8s forwards;
  }

  @keyframes fadeInUp {
    from {
      opacity: 0;
      transform: translateY(30px);
    }
    to {
      opacity: 1;
      transform: translateY(0);
    }
  }

  /* ============================================
     CTA BUTTONS
     ============================================ */

  .hero-actions {
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
    margin-bottom: 32px;
    opacity: 0;
    animation: fadeInUp 0.8s var(--ease-out-expo) 1s forwards;
  }

  .btn-magnetic {
    position: relative;
    padding: 22px 44px;
    font-size: 16px;
  }

  .btn-arrow {
    width: 24px;
    height: 24px;
    transition: transform 0.3s var(--ease-out-expo);
  }

  .btn-magnetic:hover .btn-arrow {
    transform: translateX(8px);
  }

  /* ============================================
     TRUST STRIP
     ============================================ */

  .hero-trust {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    font-size: 14px;
    color: var(--color-gray-600);
    opacity: 0;
    animation: fadeInUp 0.8s var(--ease-out-expo) 1.2s forwards;
  }

  .trust-item {
    display: inline-flex;
    align-items: center;
    gap: 4px;
  }
  .trust-icon { color: var(--color-primary); flex-shrink: 0; }

  /* ============================================
     BACKGROUND TEXT (light yellow watermark)
     ============================================ */

  .hero-bg-text {
    position: absolute;
    right: -5%;
    top: 50%;
    transform: translateY(-50%);
    font-family: var(--font-display);
    font-size: clamp(200px, 30vw, 400px);
    font-weight: 900;
    text-transform: uppercase;
    color: var(--color-primary);
    opacity: 0.08;
    pointer-events: none;
    user-select: none;
    line-height: 1;
  }

  /* ============================================
     SCROLL INDICATOR (dark on light)
     ============================================ */

  .scroll-indicator {
    position: absolute;
    bottom: 40px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    opacity: 0;
    animation: fadeIn 0.6s var(--ease-out-expo) 1.5s forwards;
  }

  .scroll-text {
    font-family: var(--font-display);
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 3px;
    color: var(--color-gray-500);
  }

  .scroll-line {
    width: 2px;
    height: 60px;
    background: var(--color-gray-200);
    border-radius: 1px;
    position: relative;
    overflow: hidden;
  }

  .scroll-dot {
    width: 4px;
    height: 4px;
    background: var(--color-primary);
    border-radius: 50%;
    position: absolute;
    left: -1px;
    animation: scrollDot 2s ease-in-out infinite;
  }

  @keyframes scrollDot {
    0% { top: 0; opacity: 1; }
    80% { top: 100%; opacity: 0; }
    100% { top: 100%; opacity: 0; }
  }

  /* ============================================
     RESPONSIVE
     ============================================ */

  @media (max-width: 1024px) {
    .hero-title {
      font-size: clamp(32px, 7vw, 64px);
    }

    .hero-container {
      padding: 120px var(--gutter) 80px;
    }

    .hero-bg-text {
      display: none;
    }

    .scroll-indicator {
      bottom: 60px;
    }
  }

  @media (max-width: 640px) {
    .hero-title {
      font-size: clamp(28px, 9vw, 48px);
    }

    .hero-subtitle {
      font-size: 16px;
    }

    .hero-actions {
      flex-direction: column;
      width: 100%;
    }

    .hero-actions .btn {
      width: 100%;
      justify-content: center;
    }

    .hero-badge {
      font-size: 11px;
      padding: 10px 16px;
    }

    .hero-accent-line {
      width: 120px;
    }

    .scroll-indicator {
      display: none;
    }
  }
</style>
