"use client";

import { useState } from "react";
import type { Dictionary } from "@/lib/i18n";

/**
 * 09 — Our Expertise (PDF p.8): eight disciplines as an editorial index.
 * No images or floating previews. Hover / keyboard focus: a soft background sweep, the title
 * shifts and turns gold, the numeral fills gold and the hairline draws across.
 * Click / Enter selects a discipline (aria-pressed) and keeps that state visible.
 */
export default function Expertise({ t }: { t: Dictionary["expertise"] }) {
  const [active, setActive] = useState<number | null>(null);

  return (
    <section id="expertise" data-theme="light" aria-labelledby="expertise-title" className="section-y relative bg-white text-navy">
      <div className="container-x">
        <div className="grid gap-8 lg:grid-cols-12 lg:items-end">
          <div className="lg:col-span-8">
            <p className="eyebrow text-gold-dark" data-reveal="fade">
              {t.eyebrow}
            </p>
            <h2 id="expertise-title" className="display display-lg mt-8" data-reveal="words">
              {t.title.split(" ").map((w, i) => (
                <span key={i} className="split-word">
                  <span>{w}</span>{" "}
                </span>
              ))}
            </h2>
          </div>
          <p className="text-sm uppercase tracking-[0.2em] text-ink/60 lg:col-span-4 lg:text-right" data-reveal="fade" data-delay="0.2">
            {t.hint}
          </p>
        </div>

        <ol className="expertise-list relative mt-16 grid border-t border-navy/15 md:grid-cols-2 lg:mt-24" data-stagger>
          {t.items.map((item, i) => (
            <li key={item.title} data-reveal="rise" className="border-b border-navy/15 md:odd:pr-6 md:even:border-l md:even:pl-6">
              <button
                type="button"
                aria-pressed={active === i}
                onClick={() => setActive((a) => (a === i ? null : i))}
                className="expertise-item group relative flex w-full items-center gap-5 overflow-hidden px-2 py-6 text-left md:px-4 md:py-9"
              >
                <span aria-hidden="true" className="expertise-sweep absolute inset-0 -z-0" />
                <span className="expertise-num numeral relative flex h-10 w-10 shrink-0 items-center justify-center rounded-full border border-gold/50 text-base text-gold-dark">
                  {String(i + 1).padStart(2, "0")}
                </span>
                <h3 className="expertise-title display relative text-[clamp(1.5rem,2.6vw,2.5rem)] leading-tight">{item.title}</h3>
                <span aria-hidden="true" className="expertise-line absolute bottom-[-1px] left-0 h-px w-full bg-gold" />
              </button>
            </li>
          ))}
        </ol>
      </div>
    </section>
  );
}
