/* global React, ReactDOM, Logo, ArrowRight, FloatCTA, FooterCTA */

/* =====================================================================
   ABOUT PAGE — app-about.jsx
   Team, what we believe, and the two ways to reach us (the old contact
   options live here now; contact.html stays as the booking page).
   ===================================================================== */

/* ---------------------- NavMulti ---------------------- */

const NavMulti = () => {
  const [open, setOpen] = React.useState(false);
  return (
  <nav className="nav">
    <div className="wrap nav-inner">
      <a href="/" className="brand">
        <Logo size={64} />
        <span className="brand-name">
          octocrew<span className="tld">.ai</span>
        </span>
      </a>
      <div className="nav-links">
        <a href="agents.html">{window.t("AI Crew")}</a>
        <a href="case-studies.html">{window.t("Case Studies")}</a>
        <a href="/blog/">{window.t("Blog")}</a>
        <a href="about.html" style={{ color: "var(--brand)", fontWeight: 600 }}>{window.t("About us")}</a>
      </div>
      <LangToggle />
      <a href="contact.html" className="nav-cta" data-octocrew-cal="booking">
        {window.t("Book a discovery call")} <ArrowRight />
      </a>
      <button
        className="nav-burger"
        aria-label="Menu"
        aria-expanded={open}
        onClick={() => setOpen(!open)}
      >
        <span /><span /><span />
      </button>
    </div>
    <div className={"nav-mobile" + (open ? " open" : "")}>
      <div className="wrap">
        <a href="agents.html">{window.t("AI Crew")}</a>
        <a href="case-studies.html">{window.t("Case Studies")}</a>
        <a href="/blog/">{window.t("Blog")}</a>
        <a href="about.html">{window.t("About us")}</a>
        <a href="contact.html" className="nav-mobile-cta" data-octocrew-cal="booking">{window.t("Book a discovery call")}</a>
        <LangToggle />
      </div>
    </div>
  </nav>
  );
};

/* ---------------------- Hero ---------------------- */

const AboutHero = () => (
  <section className="hero" id="top" style={{ position: "relative", overflow: "hidden" }}>
    <div className="aura aura-violet" style={{ width: "62vmin", height: "62vmin", top: "-18%", left: "-6%" }} />
    <div className="aura aura-lime" style={{ width: "48vmin", height: "48vmin", bottom: "-22%", right: "-8%" }} />
    <div className="wrap" style={{ position: "relative", zIndex: 1 }}>
      <div style={{ maxWidth: "820px" }}>
        <h1 className="h-display" dangerouslySetInnerHTML={{ __html: window.t('The people behind the <em class="accent">crew</em>') }} />
        <p className="sub">
          {window.t("Octocrew is built by operators who ran these agents in their own businesses first. The octopus does more with what it has, and so do our clients.")}
        </p>
      </div>
    </div>
  </section>
);

/* ---------------------- What we believe ---------------------- */

const AboutBeliefs = () => (
  <section className="section" id="beliefs">
    <div className="wrap">
      <div className="block-head">
        <h2 className="sec-h" dangerouslySetInnerHTML={{ __html: window.t('What we <span class="accent">believe</span>') }} />
      </div>
      <div className="scope-grid">
        {[
          ["Volume and quality are not a trade-off", "Octocrew adds volume and quality to your marketing output at the same time. The agents carry the volume, the specialists behind them hold the bar."],
          ["Experts belong behind the agents", "Behind every agent is a highly qualified specialist in that niche who follows the field closely and folds best practices and new approaches into its playbooks."],
          ["Trust is earned, not assumed", "You approve every output at first. Each workflow graduates to running on its own only after it proves itself on your real work."],
        ].map(([h, p]) => (
          <div className="scope-item" key={h} style={{ gridTemplateColumns: "1fr", gap: 12 }}>
            <div>
              <h5 style={{ fontSize: 19, letterSpacing: "-0.01em", marginBottom: 8 }}>{window.t(h)}</h5>
              <p>{window.t(p)}</p>
            </div>
          </div>
        ))}
      </div>
    </div>
  </section>
);

/* ---------------------- Team ---------------------- */

const TEAM = [
  {
    name: "Aleksey Nikitin",
    initials: "AN",
    role: "Co-founder · Product & Engineering",
    bio: "Builds the agents. Architected the first Octocrew fleet, seven agents running a live e-commerce business end to end, and turns everything it learns into the product.",
  },
  {
    name: "Yaroslav Lehenchuk",
    initials: "YL",
    role: "Co-founder · Business & Operations",
    bio: "Runs the business side: partnerships, operations, and making sure every client engagement is set up to succeed from the first call.",
  },
  {
    name: "Alina Uvarova",
    initials: "AU",
    role: "Co-founder · Marketing & Brand",
    bio: "Owns positioning, research, and the client funnel. Runs her own crew of agents every day and turns that practice into Octocrew's playbooks.",
  },
];

const AboutTeam = () => (
  <section className="section sunken" id="team">
    <div className="wrap">
      <div className="block-head">
        <h2 className="sec-h" dangerouslySetInnerHTML={{ __html: window.t('The <span class="accent">team</span>') }} />
        <p className="sec-lead">
          {window.t("A small senior team, backed by a network of niche specialists who build and supervise each agent in their own field.")}
        </p>
      </div>
      <div className="agent-grid">
        {TEAM.map((m) => (
          <div key={m.name} className="glass agent-card" style={{ padding: "clamp(24px, 3vw, 32px)", textAlign: "center" }}>
            <div aria-hidden="true" style={{
              width: 84,
              height: 84,
              borderRadius: "50%",
              margin: "0 auto 18px",
              display: "flex",
              alignItems: "center",
              justifyContent: "center",
              fontFamily: "var(--display)",
              fontSize: 26,
              fontWeight: 600,
              color: "#fff",
              background: "linear-gradient(135deg, var(--brand) 0%, #7A2AD0 100%)",
            }}>{m.initials}</div>
            <div style={{
              fontFamily: "var(--display)",
              fontSize: 20,
              fontWeight: 600,
              letterSpacing: "-0.01em",
              color: "var(--ink)",
              marginBottom: 6,
            }}>{m.name}</div>
            <div style={{
              fontFamily: "var(--mono)",
              fontSize: 12,
              textTransform: "uppercase",
              letterSpacing: "0.08em",
              color: "var(--brand)",
              marginBottom: 14,
            }}>{window.t(m.role)}</div>
            <p style={{ fontSize: 15, lineHeight: 1.55, color: "var(--ink-2)", margin: 0 }}>{window.t(m.bio)}</p>
          </div>
        ))}
      </div>
      <p style={{
        textAlign: "center",
        marginTop: 28,
        color: "var(--ink-2)",
        fontSize: 15,
        lineHeight: 1.6,
        maxWidth: "64ch",
        marginLeft: "auto",
        marginRight: "auto",
      }}>
        {window.t("Behind the core team: senior specialists in social, paid media, email, SEO, content, web, and analytics who keep every agent on current best practices.")}
      </p>
    </div>
  </section>
);

/* ---------------------- Lead form (same as contact page) ---------------------- */

const VERTICAL_OPTIONS = [
  ["", "Select…"],
  ["marketing-agency", "Marketing agency"],
  ["ecommerce", "E-commerce / DTC"],
  ["igaming", "iGaming / Affiliate"],
  ["saas", "SaaS / Tech"],
  ["other", "Other"],
];

const LeadForm = () => {
  const [status, setStatus] = React.useState("idle"); // idle | sending | ok | error
  const [form, setForm] = React.useState({ name: "", email: "", company: "", website: "", vertical: "", message: "" });
  const upd = (k) => (e) => setForm((f) => ({ ...f, [k]: e.target.value }));

  const submit = async (e) => {
    e.preventDefault();
    if (status === "sending") return;
    if (!form.name.trim() || !form.email.trim()) { setStatus("error"); return; }
    setStatus("sending");
    try {
      const r = await fetch("/api/lead", {
        method: "POST",
        headers: { "Content-Type": "application/json" },
        body: JSON.stringify(form),
      });
      const data = await r.json().catch(() => ({}));
      setStatus(r.ok && data.ok ? "ok" : "error");
    } catch (_) {
      setStatus("error");
    }
  };

  if (status === "ok") {
    return (
      <div className="lead-form-done">
        <span className="tick">&#10003;</span>
        <h3>{window.t("Got it — we'll be in touch.")}</h3>
        <p>{window.t("We'll reply within 24 hours. Prefer to book straight away?")}</p>
        <div style={{ paddingTop: 10 }}>
          <a className="btn btn-primary" href="contact.html" data-octocrew-cal="booking">
            {window.t("Book a discovery call")} <ArrowRight />
          </a>
        </div>
      </div>
    );
  }

  return (
    <form className="lead-form" onSubmit={submit} noValidate>
      <div className="lf-row">
        <label className="lf-field">
          <span>{window.t("Your name")} *</span>
          <input type="text" name="name" required value={form.name} onChange={upd("name")} autoComplete="name" />
        </label>
        <label className="lf-field">
          <span>{window.t("Work email")} *</span>
          <input type="email" name="email" required value={form.email} onChange={upd("email")} autoComplete="email" />
        </label>
      </div>
      <div className="lf-row">
        <label className="lf-field">
          <span>{window.t("Company")}</span>
          <input type="text" name="company" value={form.company} onChange={upd("company")} autoComplete="organization" />
        </label>
        <label className="lf-field">
          <span>{window.t("Website")}</span>
          <input type="text" name="website" value={form.website} onChange={upd("website")} placeholder="example.com" />
        </label>
      </div>
      <label className="lf-field">
        <span>{window.t("What kind of business?")}</span>
        <select name="vertical" value={form.vertical} onChange={upd("vertical")}>
          {VERTICAL_OPTIONS.map(([v, l]) => (
            <option key={v} value={v}>{window.t(l)}</option>
          ))}
        </select>
      </label>
      <label className="lf-field">
        <span>{window.t("What's draining your hours?")}</span>
        <textarea name="message" rows={3} value={form.message} onChange={upd("message")} />
      </label>
      {status === "error" && (
        <p className="lf-error">{window.t("Something went wrong. Please email us at hello@octocrew.ai.")}</p>
      )}
      <button type="submit" className="btn btn-primary" disabled={status === "sending"}>
        {status === "sending"
          ? window.t("Sending…")
          : <React.Fragment>{window.t("Send brief")} <ArrowRight /></React.Fragment>}
      </button>
    </form>
  );
};

/* ---------------------- Reach us ---------------------- */

const AboutContact = () => (
  <section className="section" id="reach">
    <div className="wrap">
      <div className="block-head">
        <h2 className="sec-h" dangerouslySetInnerHTML={{ __html: window.t('Two ways to <span class="accent">start</span>') }} />
        <p className="sec-lead">{window.t("Pick the one that fits how you work.")}</p>
      </div>

      <div className="promises">
        <div className="promise">
          <div className="promise-tag">
            <span className="icon">
              <svg width="16" height="16" viewBox="0 0 16 16" fill="none">
                <path d="M8 13V3M3 8l5-5 5 5" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round" />
              </svg>
            </span>
            {window.t("Discovery call · 30 minutes")}
          </div>
          <h3>{window.t("Hire your AI crew.")}</h3>
          <p>
            {window.t("We'll map where your ops are leaking and show the math for your specific stack. Walk away with the numbers either way.")}
          </p>
          <div className="receipt" style={{ justifyContent: "flex-start", gap: 16, padding: "16px 0" }}>
            <span><span className="tick">&#10003;</span> {window.t("No deck")}</span>
            <span><span className="tick">&#10003;</span> {window.t("No sales pitch")}</span>
            <span><span className="tick">&#10003;</span> {window.t("Numbers walk-away")}</span>
          </div>
          <div style={{ paddingTop: 8 }}>
            <a className="btn btn-primary" href="contact.html" data-octocrew-cal="booking">
              {window.t("Book a discovery call")} <ArrowRight />
            </a>
          </div>
        </div>

        <div className="promise">
          <div className="promise-tag">
            <span className="icon">
              <svg width="16" height="16" viewBox="0 0 16 16" fill="none">
                <path d="M3 8h10M9 4l4 4-4 4" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round" />
              </svg>
            </span>
            {window.t("Send a brief")}
          </div>
          <h3>{window.t("Send us a note.")}</h3>
          <p>
            {window.t("Prefer async? Tell us about your team, your stack, and what's draining your hours. We'll reply within 24 hours with whether a crew makes sense.")}
          </p>
          <LeadForm />
          <div className="lf-fallback">
            {window.t("Prefer email?")} <a href="mailto:hello@octocrew.ai">hello@octocrew.ai</a>
          </div>
        </div>
      </div>
    </div>
  </section>
);

/* ---------------------- App ---------------------- */

function AboutApp() {
  return (
    <React.Fragment>
      <NavMulti />
      <main id="main-content">
        <AboutHero />
        <AboutBeliefs />
        <AboutTeam />
        <AboutContact />
        <FooterCTA />
      </main>
      <FloatCTA />
    </React.Fragment>
  );
}

Object.assign(window, { AboutApp });

ReactDOM.createRoot(document.getElementById("root")).render(<AboutApp />);
