/* global React */
const { useState } = React;

function LogoWordmark({ width = 180, tagline = false }) {
  const src = tagline ? "./assets/leaguecast-wordmark.svg" : "./assets/leaguecast-wordmark-simple.svg";
  return <img src={src} alt="Leaguecast" style={{ width, display: "block" }} />;
}

const DiscordIcon = ({ size = 14 }) => (
  <svg width={size} height={size} viewBox="0 0 24 24" fill="currentColor" aria-hidden="true">
    <path d="M20.317 4.37a19.79 19.79 0 0 0-4.885-1.515.074.074 0 0 0-.079.037c-.21.375-.444.864-.608 1.25a18.27 18.27 0 0 0-5.487 0 12.64 12.64 0 0 0-.617-1.25.077.077 0 0 0-.079-.037A19.74 19.74 0 0 0 3.677 4.37a.07.07 0 0 0-.032.027C.533 9.046-.32 13.58.099 18.057a.082.082 0 0 0 .031.056 19.9 19.9 0 0 0 5.993 3.03.078.078 0 0 0 .084-.028c.462-.63.873-1.295 1.226-1.994a.076.076 0 0 0-.041-.106 13.1 13.1 0 0 1-1.872-.892.077.077 0 0 1-.008-.128 10.2 10.2 0 0 0 .372-.292.074.074 0 0 1 .077-.01c3.928 1.793 8.18 1.793 12.062 0a.074.074 0 0 1 .078.009c.12.098.246.198.373.292a.077.077 0 0 1-.006.127 12.3 12.3 0 0 1-1.873.892.077.077 0 0 0-.041.107c.36.699.772 1.364 1.225 1.993a.076.076 0 0 0 .084.028 19.84 19.84 0 0 0 6.002-3.03.077.077 0 0 0 .032-.054c.5-5.177-.838-9.674-3.548-13.66a.061.061 0 0 0-.03-.028zM8.02 15.331c-1.183 0-2.157-1.085-2.157-2.419 0-1.333.956-2.419 2.157-2.419 1.21 0 2.176 1.096 2.157 2.42 0 1.333-.956 2.418-2.157 2.418zm7.975 0c-1.183 0-2.157-1.085-2.157-2.419 0-1.333.955-2.419 2.157-2.419 1.21 0 2.176 1.096 2.157 2.42 0 1.333-.946 2.418-2.157 2.418z"/>
  </svg>
);

function HostsPage() {
  const hosts = [
    { name: "Aidan R", role: "Host", photo: "./assets/hosts/aidan.jpg",
      bio: "[TODO: write Aidan's bio. Keep it short — a sentence or two of voice. The other two are placeholders too.]" },
    { name: "Nick C", role: "Host", photo: "./assets/hosts/nick.jpg",
      bio: "[TODO: write Nick's bio. Replace this filler before launch.]" },
    { name: "Colton S", role: "Host", photo: "./assets/hosts/colton.jpg",
      bio: "[TODO: write Colton's bio. Replace this filler before launch.]" },
  ];
  return (
    <section style={{ padding: "80px 0 120px" }}>
      <div style={{ maxWidth: 920, margin: "0 auto", padding: "0 32px" }}>
        <div style={{
          fontFamily: "var(--font-display)", fontWeight: 600, fontSize: 13,
          letterSpacing: ".22em", textTransform: "uppercase",
          color: "var(--lc-yellow)", marginBottom: 14,
        }}>The voices you're stuck with</div>
        <h1 style={{
          fontFamily: "var(--font-display)", fontWeight: 900,
          fontSize: "clamp(40px, 5.6vw, 72px)", lineHeight: .98,
          textTransform: "uppercase", margin: "0 0 12px",
        }}>The hosts</h1>
        <p style={{
          fontFamily: "var(--font-body)", fontSize: 18, lineHeight: 1.55,
          color: "var(--fg-2)", maxWidth: 580, margin: "0 0 56px",
        }}>Three friends who've been talking League for longer than is probably healthy.</p>

        <div style={{ display: "grid", gridTemplateColumns: "repeat(3, 1fr)", gap: 28 }}>
          {hosts.map((h) => (
            <article key={h.name} style={{
              background: "var(--bg-2)", border: "1px solid var(--bg-line)",
              borderRadius: 10, overflow: "hidden",
            }}>
              <div style={{
                aspectRatio: "1 / 1",
                backgroundImage: `url('${h.photo}')`,
                backgroundSize: "cover",
                backgroundPosition: "center",
                borderBottom: "1px solid var(--bg-line)",
              }} />
              <div style={{ padding: "22px 20px 24px" }}>
                <h3 style={{
                  fontFamily: "var(--font-display)", fontWeight: 800,
                  fontSize: 24, textTransform: "uppercase",
                  color: "var(--fg-1)", margin: "0 0 4px",
                }}>{h.name}</h3>
                <div style={{
                  fontFamily: "var(--font-display)", fontWeight: 600, fontSize: 11,
                  letterSpacing: ".18em", textTransform: "uppercase",
                  color: "var(--lc-yellow)",
                }}>{h.role}</div>
              </div>
            </article>
          ))}
        </div>
      </div>
    </section>
  );
}

function ContactPage() {
  const [tab, setTab] = useState("listener");
  return (
    <section style={{ padding: "80px 0 120px" }}>
      <div style={{ maxWidth: 720, margin: "0 auto", padding: "0 32px" }}>
        <div style={{
          fontFamily: "var(--font-display)", fontWeight: 600, fontSize: 13,
          letterSpacing: ".22em", textTransform: "uppercase",
          color: "var(--lc-yellow)", marginBottom: 14,
        }}>Say hi</div>
        <h1 style={{
          fontFamily: "var(--font-display)", fontWeight: 900,
          fontSize: "clamp(40px, 5.6vw, 72px)", lineHeight: .98,
          textTransform: "uppercase", margin: "0 0 12px",
        }}>Get in touch</h1>
        <p style={{
          fontFamily: "var(--font-body)", fontSize: 18, lineHeight: 1.55,
          color: "var(--fg-2)", margin: "0 0 36px",
        }}>
          Everything below lands at <a href="mailto:mail@leaguecastpodcast.com"
          style={{ color: "var(--lc-yellow)", textDecoration: "none" }}>mail@leaguecastpodcast.com</a>.
          We read all of it.
        </p>

        <div style={{
          display: "inline-flex", padding: 4, background: "var(--bg-2)",
          border: "1px solid var(--bg-line)", borderRadius: 8, marginBottom: 24,
        }}>
          {[
            { id: "listener", lbl: "Listener mail" },
            { id: "sponsor", lbl: "Sponsorship" },
          ].map((t) => (
            <button key={t.id} onClick={() => setTab(t.id)} style={{
              fontFamily: "var(--font-display)", fontWeight: 700,
              fontSize: 12, letterSpacing: ".12em", textTransform: "uppercase",
              padding: "10px 18px", border: 0, borderRadius: 6, cursor: "pointer",
              background: tab === t.id ? "var(--lc-yellow)" : "transparent",
              color: tab === t.id ? "var(--lc-ink)" : "var(--fg-2)",
            }}>{t.lbl}</button>
          ))}
        </div>

        <ContactForm variant={tab} />
      </div>
    </section>
  );
}

function ContactForm({ variant }) {
  const isSponsor = variant === "sponsor";
  // Replace this with your Formspree form ID (https://formspree.io)
  // e.g. "https://formspree.io/f/abcdwxyz". Both forms route to the same
  // address (mail@leaguecastpodcast.com) — the subject line distinguishes them.
  const FORMSPREE_ENDPOINT = "https://formspree.io/f/mzdoewbw";
  return (
    <form action={FORMSPREE_ENDPOINT} method="POST" style={{
      background: "var(--bg-2)", border: "1px solid var(--bg-line)",
      borderRadius: 10, padding: 28,
      display: "flex", flexDirection: "column", gap: 16,
    }}>
      <input type="hidden" name="_subject" value={isSponsor ? "Sponsorship inquiry" : "Listener mail"} />
      <input type="hidden" name="category" value={isSponsor ? "sponsor" : "listener"} />
      <div style={{
        fontFamily: "var(--font-body)", fontSize: 14, lineHeight: 1.55,
        color: "var(--fg-3)", marginBottom: 4,
      }}>
        {isSponsor
          ? "Pitch us your product, ad read, or partnership. We'll reply with rates and the current lineup."
          : "Question, hot take, or an embarrassing ranked story? We read the good ones on air."}
      </div>
      <Field label="Your name"><input name="name" required style={inpStyle} placeholder={isSponsor ? "Jane Doe" : "Summoner name works too"} /></Field>
      <Field label="Email"><input name="email" type="email" required style={inpStyle} placeholder="you@example.com" /></Field>
      {isSponsor && <Field label="Company"><input name="company" style={inpStyle} placeholder="Brand / agency" /></Field>}
      <Field label={isSponsor ? "What are you thinking?" : "Your message"}>
        <textarea name="message" rows={6} required style={{ ...inpStyle, resize: "vertical", fontFamily: "var(--font-body)" }}
          placeholder={isSponsor ? "Product, budget ballpark, flight window…" : "Tell us anything."}/>
      </Field>
      <button type="submit" style={{
        fontFamily: "var(--font-display)", fontWeight: 700,
        fontSize: 13, letterSpacing: ".1em", textTransform: "uppercase",
        padding: "14px 22px", background: "var(--lc-yellow)", color: "var(--lc-ink)",
        border: 0, borderRadius: 4, cursor: "pointer", alignSelf: "flex-start",
      }}>
        {isSponsor ? "Send sponsorship inquiry →" : "Send to the show →"}
      </button>
      <div style={{
        fontFamily: "var(--font-mono)", fontSize: 11, color: "var(--fg-3)",
      }}>
        Prefer email? Write us directly: <a href={`mailto:mail@leaguecastpodcast.com?subject=${isSponsor ? "Sponsorship" : "Listener mail"}`}
          style={{ color: "var(--lc-blue-hot)" }}>mail@leaguecastpodcast.com</a>
      </div>
    </form>
  );
}

function Field({ label, children }) {
  return (
    <label style={{ display: "flex", flexDirection: "column", gap: 6 }}>
      <span style={{
        fontFamily: "var(--font-display)", fontWeight: 600,
        fontSize: 11, letterSpacing: ".16em", textTransform: "uppercase",
        color: "var(--fg-2)",
      }}>{label}</span>
      {children}
    </label>
  );
}

const inpStyle = {
  background: "var(--bg-1)", border: "1px solid var(--bg-line)",
  borderRadius: 4, padding: "12px 14px",
  fontFamily: "var(--font-body)", fontSize: 14, color: "var(--fg-1)",
  outline: "none", width: "100%", boxSizing: "border-box",
};

Object.assign(window, { LogoWordmark, DiscordIcon, HostsPage, ContactPage });
