// ff-services.jsx — "What we do" section with 2 variants

const SERVICE_STACKS = [
  ["n8n", "Make", "Temporal"],
  ["openai", "claude", "pgvector"],
  ["langgraph", "browser-use", "tool-calling"],
  ["bitrix", "hubspot", "supabase"],
];
const SERVICE_KEYS = ["auto", "ai", "agents", "integrations"];

function Services({ variant = "cards", s }) {
  return (
    <section id="services" data-screen-label="02 Services" className="section section-services">
      <div className="wrap">
        <Reveal className="section-head" as="div">
          <div>
            <SectionEyebrow index={2} label={s.services.eyebrow} />
            <h2>{s.services.title}</h2>
          </div>
        </Reveal>

        {variant === "cards" ? <ServicesCards s={s} /> : <ServicesList s={s} />}
      </div>
    </section>
  );
}

function ServicesCards({ s }) {
  return (
    <div className="services-grid">
      {s.services.items.map((item, i) => (
        <ServiceCardKinetic
          key={i}
          item={item}
          index={i}
          delay={(i % 4) + 1}
          stacks={SERVICE_STACKS[i]}
          moreLabel={s.services.more}
        />
      ))}
    </div>
  );
}

function ServiceCardKinetic({ item, index, delay, stacks, moreLabel }) {
  const handleMouseMove = (e) => {
    const el = e.currentTarget;
    const r = el.getBoundingClientRect();
    el.style.setProperty("--mx", `${e.clientX - r.left}px`);
    el.style.setProperty("--my", `${e.clientY - r.top}px`);
  };
  return (
    <Reveal as="article" delay={delay} className="svc-card" onMouseMove={handleMouseMove}>
      <span className="svc-spotlight" aria-hidden="true" />
      <div className="svc-card-top">
        <div className="svc-icon-tile" aria-hidden="true">
          <ServiceIcon kind={SERVICE_KEYS[index]} />
        </div>
        <span className="svc-card-label">{item.label}</span>
      </div>
      <h3 className="svc-card-title">{item.title}</h3>
      <p className="svc-card-desc">{item.desc}</p>
      <ul className="svc-bullets">
        {item.bullets.map((b) => (
          <li key={b}>
            <span className="svc-bullet-mark">+</span>
            <span>{b}</span>
          </li>
        ))}
      </ul>
      <div className="svc-foot">
        <div className="svc-stack">
          {stacks.map((t) => (
            <span key={t} className="svc-chip">{t}</span>
          ))}
        </div>
        <a href="#contact" className="svc-cta" aria-label={moreLabel}>
          <span className="svc-cta-icon" aria-hidden="true">
            <svg viewBox="0 0 24 24" fill="none">
              <path fill="currentColor" opacity=".5" fillRule="evenodd" clipRule="evenodd" d="M3.25 12a.75.75 0 0 1 .75-.75h9.25v1.5H4a.75.75 0 0 1-.75-.75" />
              <path fill="currentColor" d="M13.25 12.75V18a.75.75 0 0 0 1.28.53l6-6a.75.75 0 0 0 0-1.06l-6-6a.75.75 0 0 0-1.28.53z" />
            </svg>
          </span>
          <span className="svc-cta-label">{moreLabel}</span>
        </a>
      </div>
    </Reveal>
  );
}

function ServicesList({ s }) {
  return (
    <div className="services-list">
      {s.services.items.map((item, i) => (
        <Reveal key={i} as="article" delay={(i % 4) + 1} className="service-row">
          <div className="service-row-label">{item.label}</div>
          <div className="service-row-icon"><ServiceIcon kind={SERVICE_KEYS[i]} /></div>
          <div className="service-row-body">
            <h3 className="service-row-title">{item.title}</h3>
            <p className="service-row-desc">{item.desc}</p>
          </div>
          <div className="service-row-stack">
            {SERVICE_STACKS[i].map((t) => <span key={t} className="tag">{t}</span>)}
          </div>
          <a href="#contact" className="service-row-more">
            <span className="arrow">→</span>
          </a>
        </Reveal>
      ))}
    </div>
  );
}

// Solar Icons — Bold Duotone. Primary path opaque, secondary at .5 opacity.
function ServiceIcon({ kind }) {
  switch (kind) {
    case "auto": // Widget-2 — process blocks
      return (
        <svg viewBox="0 0 24 24" fill="none" aria-hidden="true">
          <path fill="currentColor" fillRule="evenodd" clipRule="evenodd" d="M2 6.634a4.634 4.634 0 1 1 9.268 0a4.634 4.634 0 0 1-9.268 0" />
          <path fill="currentColor" opacity=".5" fillRule="evenodd" clipRule="evenodd" d="M12.732 17.366a4.634 4.634 0 1 1 9.269 0a4.634 4.634 0 0 1-9.269 0" />
          <path fill="currentColor" d="M2 17.5c0-2.121 0-3.182.659-3.841S4.379 13 6.5 13s3.182 0 3.841.659S11 15.379 11 17.5s0 3.182-.659 3.841S8.621 22 6.5 22s-3.182 0-3.841-.659S2 19.621 2 17.5" />
          <path fill="currentColor" opacity=".5" d="M13 6.5c0-2.121 0-3.182.659-3.841S15.379 2 17.5 2s3.182 0 3.841.659S22 4.379 22 6.5s0 3.182-.659 3.841S19.621 11 17.5 11s-3.182 0-3.841-.659S13 8.621 13 6.5" />
        </svg>
      );
    case "ai": // CPU-Bolt — AI chip
      return (
        <svg viewBox="0 0 24 24" fill="none" aria-hidden="true">
          <path fill="currentColor" opacity=".5" d="M9.18 9.18c.054-.052.149-.118.451-.159c.323-.043.761-.044 1.439-.044h1.86c.678 0 1.116.001 1.438.044c.303.041.398.107.45.16c.054.053.12.148.16.45c.044.323.045.761.045 1.439v1.86c0 .678-.001 1.116-.045 1.438c-.04.303-.106.398-.16.45c-.052.054-.147.12-.45.16c-.322.044-.76.045-1.438.045h-1.86c-.678 0-1.116-.001-1.439-.045c-.302-.04-.397-.106-.45-.16c-.053-.052-.119-.147-.16-.45c-.043-.322-.044-.76-.044-1.438v-1.86c0-.678.001-1.116.044-1.439c.041-.302.107-.397.16-.45" />
          <path fill="currentColor" fillRule="evenodd" clipRule="evenodd" d="M12.698 2.698a.698.698 0 0 0-1.396 0v2.79q-.764 0-1.395.017V2.698a.698.698 0 0 0-1.395 0v2.79q0 .056.008.108c-.936.115-1.585.353-2.078.846s-.731 1.142-.846 2.078a1 1 0 0 0-.108-.008h-2.79a.698.698 0 0 0 0 1.395h2.807q-.016.63-.016 1.395H2.698a.698.698 0 0 0 0 1.396h2.79q0 .764.017 1.395H2.698a.698.698 0 0 0 0 1.395h2.79a1 1 0 0 0 .108-.008c.115.936.353 1.585.846 2.078s1.142.731 2.078.846a1 1 0 0 0-.008.108v2.79a.698.698 0 0 0 1.395 0v-2.807q.63.016 1.395.016v2.791a.698.698 0 0 0 1.396 0v-2.79q.764 0 1.395-.017v2.807a.698.698 0 0 0 1.395 0v-2.79a1 1 0 0 0-.008-.108c.936-.115 1.585-.353 2.078-.846s.731-1.142.846-2.078q.053.009.108.008h2.79a.698.698 0 0 0 0-1.395h-2.807q.016-.63.016-1.395h2.791a.698.698 0 0 0 0-1.396h-2.79q0-.764-.017-1.395h2.807a.698.698 0 0 0 0-1.395h-2.79a1 1 0 0 0-.108.008c-.115-.936-.353-1.585-.846-2.078s-1.142-.731-2.078-.846a1 1 0 0 0 .008-.108v-2.79a.698.698 0 0 0-1.395 0v2.807a56 56 0 0 0-1.395-.016zm-3.252 4.94c.426-.057.96-.057 1.578-.057h1.952c.619 0 1.151 0 1.578.058c.458.061.896.2 1.252.555c.355.356.494.794.555 1.252c.058.426.058.96.058 1.578v1.952c0 .619 0 1.151-.058 1.578c-.061.458-.2.896-.555 1.252c-.356.355-.794.494-1.252.555c-.427.058-.96.058-1.578.058h-1.952c-.619 0-1.152 0-1.578-.058c-.458-.061-.896-.2-1.252-.555c-.355-.356-.494-.794-.555-1.252c-.058-.427-.058-.96-.058-1.578v-1.952c0-.619 0-1.152.058-1.578c.061-.458.2-.896.555-1.252c.356-.355.794-.494 1.252-.555" />
          <path fill="currentColor" d="M12.966 10.545a.698.698 0 0 0-1.135-.811l-1.329 1.86a.698.698 0 0 0 .568 1.103h.505l-.541.758a.698.698 0 1 0 1.135.81l1.329-1.86a.698.698 0 0 0-.568-1.103h-.505z" />
        </svg>
      );
    case "agents": // Programming — dev/agents
      return (
        <svg viewBox="0 0 24 24" fill="none" aria-hidden="true">
          <path fill="currentColor" opacity=".5" d="M2 12c0-4.714 0-7.071 1.464-8.536C4.93 2 7.286 2 12 2s7.071 0 8.535 1.464C22 4.93 22 7.286 22 12s0 7.071-1.465 8.535C19.072 22 16.714 22 12 22s-7.071 0-8.536-1.465C2 19.072 2 16.714 2 12" />
          <path fill="currentColor" d="M6.424 9.52a.75.75 0 0 1 1.056-.096l.277.23c.605.504 1.12.933 1.476 1.328c.379.42.674.901.674 1.518s-.295 1.099-.674 1.518c-.356.395-.871.824-1.476 1.328l-.277.23a.75.75 0 1 1-.96-1.152l.234-.195c.659-.55 1.09-.91 1.366-1.216c.262-.29.287-.427.287-.513s-.025-.222-.287-.513c-.277-.306-.707-.667-1.366-1.216l-.234-.195a.75.75 0 0 1-.096-1.056M17.75 15a.75.75 0 0 1-.75.75h-5a.75.75 0 0 1 0-1.5h5a.75.75 0 0 1 .75.75" />
        </svg>
      );
    case "integrations": // Routing-2 — network/wiring
      return (
        <svg viewBox="0 0 24 24" fill="none" aria-hidden="true">
          <path fill="currentColor" opacity=".5" fillRule="evenodd" clipRule="evenodd" d="M18.5 14c-1.933 0-3.5 1.458-3.5 3.257c0 1.785 1.117 3.868 2.86 4.613c.406.173.874.173 1.28 0c1.743-.745 2.86-2.828 2.86-4.613C22 15.458 20.433 14 18.5 14M5.5 2C3.567 2 2 3.458 2 5.257C2 7.042 3.117 9.125 4.86 9.87c.406.173.874.173 1.28 0C7.883 9.125 9 7.042 9 5.257C9 3.458 7.433 2 5.5 2" />
          <path fill="currentColor" d="M19.5 17.5a1 1 0 1 1-2 0a1 1 0 0 1 2 0m-13-12a1 1 0 1 1-2 0a1 1 0 0 1 2 0" />
          <path fill="currentColor" fillRule="evenodd" clipRule="evenodd" d="M11.25 5a.75.75 0 0 1 .75-.75h4.132c2.751 0 3.797 3.593 1.476 5.07l-10.41 6.625c-1.056.672-.58 2.305.67 2.305h2.321l-.22-.22a.75.75 0 1 1 1.061-1.06l1.5 1.5a.75.75 0 0 1 0 1.06l-1.5 1.5a.75.75 0 1 1-1.06-1.06l.22-.22H7.867c-2.751 0-3.797-3.593-1.476-5.07l10.411-6.625c1.055-.672.58-2.305-.671-2.305H12a.75.75 0 0 1-.75-.75" />
        </svg>
      );
    default:
      return null;
  }
}

window.Services = Services;
