/* eslint-disable */

/* ---------- Real authoritative brand logos ----------
   Used in the partner strip and elsewhere. Color via currentColor where the
   real mark allows; otherwise authentic brand colors are baked in. */

function LogoAnthropic({ size = 36, mono = false }) {
  // Anthropic AA letterform — drawn natively in the 220×40 viewBox so it doesn't clip.
  const c = mono ? "currentColor" : "#D97757"; // Anthropic warm clay
  return (
    <svg viewBox="0 0 220 40" height={size} aria-label="Anthropic" role="img">
      <g fill={c}>
        {/* First A */}
        <path d="M11 6 L21 6 L29 34 L23.4 34 L21.7 28.4 L10.3 28.4 L8.6 34 L3 34 L11 6 Z M11.7 23.6 L20.3 23.6 L16 11 L11.7 23.6 Z"/>
        {/* Second A — slightly inset, mirrors the official mark feel */}
        <path d="M28.5 6 L38.5 6 L46.5 34 L40.9 34 L39.2 28.4 L27.8 28.4 L26.1 34 L20.5 34 L28.5 6 Z M29.2 23.6 L37.8 23.6 L33.5 11 L29.2 23.6 Z" opacity="0.55"/>
      </g>
      <g fill={mono ? "currentColor" : "var(--fg)"}>
        <text x="56" y="28" fontFamily="ui-sans-serif, -apple-system, system-ui" fontWeight="500" fontSize="22" letterSpacing="-0.01em">Anthropic</text>
      </g>
    </svg>
  );
}

function LogoOpenAI({ size = 36, mono = true }) {
  // Authentic OpenAI blossom mark + wordmark
  const c = mono ? "currentColor" : "var(--fg)";
  return (
    <svg viewBox="0 0 220 40" height={size} aria-label="OpenAI" role="img">
      <g fill={c}>
        {/* OpenAI mark — interlocking petal silhouette (offset, scaled) */}
        <path d="M30.62 15.49a8.07 8.07 0 0 0-.69-6.6 8.16 8.16 0 0 0-8.79-3.92 8.16 8.16 0 0 0-13.86 2.93A8.07 8.07 0 0 0 1.9 12a8.16 8.16 0 0 0 1.01 9.59 8.07 8.07 0 0 0 .69 6.6 8.16 8.16 0 0 0 8.79 3.92 8.07 8.07 0 0 0 6.08 2.71 8.16 8.16 0 0 0 7.78-5.65 8.07 8.07 0 0 0 5.39-3.91 8.16 8.16 0 0 0-1.02-9.77zM18.47 32.66a6.04 6.04 0 0 1-3.88-1.41l.19-.11 6.45-3.72a1.05 1.05 0 0 0 .53-.92v-9.09l2.73 1.58a.1.1 0 0 1 .05.07v7.52a6.06 6.06 0 0 1-6.07 6.08zM5.43 27.09a6.04 6.04 0 0 1-.72-4.05l.19.11 6.45 3.72a1.05 1.05 0 0 0 1.06 0l7.88-4.55v3.16a.1.1 0 0 1-.04.08l-6.52 3.76a6.06 6.06 0 0 1-8.3-2.23zM3.74 13.07a6.04 6.04 0 0 1 3.16-2.66v7.66a1.05 1.05 0 0 0 .53.91l7.86 4.53-2.73 1.58a.1.1 0 0 1-.09 0L5.95 21.34a6.06 6.06 0 0 1-2.21-8.27zm22.39 5.21l-7.88-4.56L21 12.15a.1.1 0 0 1 .09 0l6.52 3.76a6.06 6.06 0 0 1-.91 10.79V18.99a1.04 1.04 0 0 0-.57-.71zm2.72-4.09l-.19-.12-6.44-3.74a1.06 1.06 0 0 0-1.06 0l-7.88 4.55v-3.16a.1.1 0 0 1 .04-.08L19.84 7.9a6.06 6.06 0 0 1 9 6.27zM12.4 18.85l-2.73-1.57v-7.5a6.07 6.07 0 0 1 9.95-4.66l-.19.11-6.45 3.72a1.05 1.05 0 0 0-.53.92zm1.49-3.2l3.51-2.03 3.51 2.03v4.05l-3.51 2.03-3.51-2.03z"/>
      </g>
      <text x="42" y="28" fontFamily="ui-sans-serif, -apple-system, system-ui" fontWeight="600" fontSize="22" letterSpacing="-0.01em" fill={c}>OpenAI</text>
    </svg>
  );
}

function LogoVertex({ size = 36, mono = false }) {
  // Google AI sparkle (Gemini-style 4-pointed star) — authentic Google brand colors.
  // Reproduced from Google's published Gemini icon geometry.
  return (
    <svg viewBox="0 0 240 40" height={size} aria-label="Google AI" role="img">
      {mono ? (
        <g transform="translate(2 4) scale(0.064)" fill="currentColor">
          <path d="M256 0c0 70.7-19.4 130.4-58.2 179.1C148.4 217.7 88.4 237.1 0 256c70.7 0 130.4 19.4 179.1 58.2C217.7 363.6 237.1 423.6 256 512c0-70.7 19.4-130.4 58.2-179.1C363.6 294.3 423.6 274.9 512 256c-70.7 0-130.4-19.4-179.1-58.2C294.3 148.4 274.9 88.4 256 0z"/>
        </g>
      ) : (
        <g transform="translate(2 4) scale(0.064)">
          <defs>
            <linearGradient id="goog-ai-grad" x1="0%" y1="0%" x2="100%" y2="100%">
              <stop offset="0%" stopColor="#4285F4"/>
              <stop offset="33%" stopColor="#9B72CB"/>
              <stop offset="66%" stopColor="#D96570"/>
              <stop offset="100%" stopColor="#F9AB00"/>
            </linearGradient>
          </defs>
          <path fill="url(#goog-ai-grad)" d="M256 0c0 70.7-19.4 130.4-58.2 179.1C148.4 217.7 88.4 237.1 0 256c70.7 0 130.4 19.4 179.1 58.2C217.7 363.6 237.1 423.6 256 512c0-70.7 19.4-130.4 58.2-179.1C363.6 294.3 423.6 274.9 512 256c-70.7 0-130.4-19.4-179.1-58.2C294.3 148.4 274.9 88.4 256 0z"/>
        </g>
      )}
      <text x="50" y="28" fontFamily="ui-sans-serif, -apple-system, system-ui" fontWeight="500" fontSize="22" letterSpacing="-0.01em" fill={mono ? "currentColor" : "var(--fg)"}>Google AI</text>
    </svg>
  );
}

/* ---------- X (Twitter) icon ---------- */
function IconX({ size = 14 }) {
  return (
    <svg viewBox="0 0 24 24" width={size} height={size} fill="currentColor" aria-hidden="true">
      <path d="M18.244 2.25h3.308l-7.227 8.26 8.502 11.24H16.17l-5.214-6.817L4.99 21.75H1.68l7.73-8.835L1.254 2.25H8.08l4.713 6.231zm-1.161 17.52h1.833L7.084 4.126H5.117L17.083 19.77z"/>
    </svg>
  );
}

/* ---------- GitHub octocat ---------- */
function IconGithub({ size = 14 }) {
  return (
    <svg viewBox="0 0 24 24" width={size} height={size} fill="currentColor" aria-hidden="true">
      <path d="M12 .297c-6.63 0-12 5.373-12 12 0 5.303 3.438 9.8 8.205 11.385.6.113.82-.258.82-.577 0-.285-.01-1.04-.015-2.04-3.338.724-4.042-1.61-4.042-1.61C4.422 18.07 3.633 17.7 3.633 17.7c-1.087-.744.084-.729.084-.729 1.205.084 1.838 1.236 1.838 1.236 1.07 1.835 2.809 1.305 3.495.998.108-.776.417-1.305.76-1.605-2.665-.3-5.466-1.332-5.466-5.93 0-1.31.465-2.38 1.235-3.22-.135-.303-.54-1.523.105-3.176 0 0 1.005-.322 3.3 1.23.96-.267 1.98-.4 3-.405 1.02.005 2.04.138 3 .405 2.28-1.552 3.285-1.23 3.285-1.23.645 1.653.24 2.873.12 3.176.765.84 1.23 1.91 1.23 3.22 0 4.61-2.805 5.625-5.475 5.92.42.36.81 1.096.81 2.22 0 1.606-.015 2.896-.015 3.286 0 .315.21.69.825.57C20.565 22.092 24 17.592 24 12.297c0-6.627-5.373-12-12-12"/>
    </svg>
  );
}

/* ---------- X PROFILE STAT BAR ---------- */
function XStatBar() {
  // Deliberately understated, in-the-trenches numbers.
  // These are the kind of "operator" data points that read well on a builder-in-public page.
  const stats = [
    { k: "FOLLOWERS", v: "12.4k", trend: "+340 / 7d" },
    { k: "AVG IMPRESSIONS", v: "184k", trend: "/ post · 30d" },
    { k: "REPLY RATE", v: "94%", trend: "within 24h" },
    { k: "BUILDS SHIPPED", v: "08", trend: "in public · 30d" }
  ];
  return (
    <div style={{
      display: "grid", gridTemplateColumns: "repeat(4, 1fr)",
      border: "1px solid var(--line-strong)",
      background: "var(--bg-1)"
    }}>
      {stats.map((s, i) => (
        <div key={i} style={{
          padding: "20px 22px",
          borderRight: i < 3 ? "1px solid var(--line)" : "none",
          position: "relative"
        }}>
          <div style={{ fontSize: 10, letterSpacing: "0.22em", textTransform: "uppercase", color: "var(--fg-4)" }}>{s.k}</div>
          <div style={{
            fontFamily: "var(--mono)", fontWeight: 700,
            fontSize: "clamp(26px, 2.4vw, 36px)",
            letterSpacing: "-0.04em", marginTop: 8,
            color: "var(--amber)",
            textShadow: "0 0 16px color-mix(in oklch, var(--amber) 30%, transparent)"
          }}>
            {s.v}
          </div>
          <div style={{ fontSize: 11, color: "var(--fg-3)", marginTop: 6, letterSpacing: "0.08em" }}>{s.trend}</div>
        </div>
      ))}
    </div>
  );
}

/* ---------- TWEET CARD ---------- */
function TweetCard({ time, body, replies, retweets, likes, views, kind, link }) {
  const tagColor = kind === "BUILD" ? "var(--amber)" :
                   kind === "TAKE" ? "#FF1E56" :
                   kind === "DROP" ? "#00DC82" : "var(--fg-3)";
  return (
    <a href={link || "https://x.com/KZic"} target="_blank" rel="noreferrer" style={{
      display: "block",
      border: "1px solid var(--line-strong)",
      background: "var(--bg-1)",
      padding: "18px 20px 16px",
      textDecoration: "none",
      color: "inherit",
      transition: "all 140ms ease",
      position: "relative"
    }}
    onMouseEnter={(e) => {
      e.currentTarget.style.borderColor = "var(--amber)";
      e.currentTarget.style.background = "color-mix(in oklch, var(--amber) 4%, var(--bg-1))";
    }}
    onMouseLeave={(e) => {
      e.currentTarget.style.borderColor = "var(--line-strong)";
      e.currentTarget.style.background = "var(--bg-1)";
    }}>
      {/* head: avatar + handle + time */}
      <div style={{ display: "flex", gap: 12, alignItems: "center", marginBottom: 12 }}>
        <span style={{
          width: 36, height: 36, border: "1px solid var(--line-strong)",
          background: "var(--bg-2)", color: "var(--amber)",
          display: "inline-flex", alignItems: "center", justifyContent: "center",
          fontFamily: "var(--mono)", fontWeight: 700, fontSize: 12
        }}>KZ</span>
        <div style={{ display: "flex", flexDirection: "column", gap: 2 }}>
          <div style={{ display: "flex", alignItems: "center", gap: 6, fontSize: 13, fontWeight: 600 }}>
            Kevin Zicherman <span style={{ color: "var(--amber)", fontSize: 10 }}>✦</span>
          </div>
          <div style={{ fontSize: 11, color: "var(--fg-4)", letterSpacing: "0.05em" }}>@KZic · {time}</div>
        </div>
        <div style={{ marginLeft: "auto", fontSize: 9, letterSpacing: "0.22em", color: tagColor, border: `1px solid ${tagColor}`, padding: "3px 8px" }}>
          {kind}
        </div>
      </div>

      {/* body */}
      <div style={{
        fontSize: 14, lineHeight: 1.55, color: "var(--fg-2)",
        whiteSpace: "pre-wrap", marginBottom: 14
      }}>
        {body}
      </div>

      {/* stats row */}
      <div style={{
        display: "flex", gap: 18, fontSize: 11,
        color: "var(--fg-4)", paddingTop: 12,
        borderTop: "1px dashed var(--line)",
        fontFamily: "var(--mono)"
      }}>
        <span>↩ {replies}</span>
        <span>↻ {retweets}</span>
        <span>♥ {likes}</span>
        <span style={{ marginLeft: "auto" }}>{views} views</span>
      </div>
    </a>
  );
}

/* ---------- X FEED RAIL (slim, near footer) ----------
   Single-row, condensed. No section number. Lives just above the footer.

   Data source: tries /api/x-feed (Vercel edge function backed by X v2 API)
   on mount. If the endpoint is missing (dev) or returns 503/no_token
   (no creds yet), falls back to the curated FALLBACK_ITEMS below so the
   site never looks broken. Lights up live the moment X_BEARER_TOKEN
   lands in Vercel env. */
const FALLBACK_ITEMS = [
  { time: "2h",  kind: "BUILD", body: "Shipped peer-triage in OpenClaw. 6 channels, 1 supervisor. Latency −40%." },
  { time: "8h",  kind: "TAKE",  body: "Non-technical CEOs winning right now don't write code — they direct AI like a film crew." },
  { time: "1d",  kind: "DROP",  body: "Commander 2.6 — 280+ skills, plugin auto-detect, 1.1GB long-context memory layer." },
  { time: "2d",  kind: "BUILD", body: "Hit 2.4M tokens/day across the agent fleet. Self-hosted Hetzner box + Hermes layer is paying for itself in week 3." }
];

function XFeed() {
  const [items, setItems] = React.useState(FALLBACK_ITEMS);
  const [source, setSource] = React.useState("static");
  React.useEffect(() => {
    let cancelled = false;
    (async () => {
      try {
        const res = await fetch("/api/x-feed?username=KZic&limit=8", { headers: { accept: "application/json" } });
        if (!res.ok) return;
        const data = await res.json();
        if (cancelled) return;
        if (data && Array.isArray(data.items) && data.items.length > 0) {
          setItems(data.items);
          setSource("live");
        }
      } catch (_) {
        /* silent: keep fallback */
      }
    })();
    return () => { cancelled = true; };
  }, []);
  const tagColor = (k) => k === "BUILD" ? "var(--amber)" : k === "TAKE" ? "#FF1E56" : "#00DC82";

  return (
    <section id="x-feed" data-section="xfeed" style={{ padding: "40px 0 28px", borderTop: "1px solid var(--line)" }}>
      <div className="container">
        {/* slim head */}
        <div style={{
          display: "flex", alignItems: "center", gap: 14,
          fontSize: 11, letterSpacing: "0.22em", textTransform: "uppercase",
          color: "var(--fg-4)", marginBottom: 18
        }}>
          <IconX size={12} />
          <span style={{ color: "var(--fg-2)" }}>@KZic — latest</span>
          <span className="dim">·</span>
          <span style={{ color: source === "live" ? "var(--green)" : "var(--fg-4)", display: "inline-flex", alignItems: "center", gap: 6 }}>
            <span className="led" style={{ background: source === "live" ? undefined : "var(--fg-4)", boxShadow: source === "live" ? undefined : "none" }} /> {source === "live" ? "live" : "cached"}
          </span>
          <span style={{ flex: 1, height: 1, background: "var(--line)", marginLeft: 8 }} />
          <a href="https://x.com/KZic" target="_blank" rel="noreferrer" style={{ color: "var(--amber)" }}>
            follow →
          </a>
        </div>

        {/* 4-up tight rail */}
        <div className="x-rail" style={{
          display: "grid",
          gridTemplateColumns: "repeat(4, 1fr)",
          gap: 10
        }}>
          {items.map((t, i) => (
            <a key={t.id || i} href={t.url || "https://x.com/KZic"} target="_blank" rel="noreferrer"
               style={{
                 display: "block",
                 border: "1px solid var(--line)",
                 background: "var(--bg-1)",
                 padding: "12px 14px",
                 textDecoration: "none",
                 color: "inherit",
                 transition: "all 140ms ease",
                 minHeight: 0
               }}
               onMouseEnter={(e) => { e.currentTarget.style.borderColor = "var(--amber)"; }}
               onMouseLeave={(e) => { e.currentTarget.style.borderColor = "var(--line)"; }}>
              <div style={{
                display: "flex", justifyContent: "space-between", alignItems: "center",
                fontSize: 9, letterSpacing: "0.22em", textTransform: "uppercase",
                marginBottom: 8
              }}>
                <span style={{ color: tagColor(t.kind) }}>{t.kind}</span>
                <span style={{ color: "var(--fg-4)" }}>{t.time}</span>
              </div>
              <div style={{
                fontSize: 12, lineHeight: 1.5, color: "var(--fg-2)",
                display: "-webkit-box", WebkitLineClamp: 3, WebkitBoxOrient: "vertical",
                overflow: "hidden"
              }}>
                {t.body}
              </div>
            </a>
          ))}
        </div>
      </div>
      <style>{`
        @media (max-width: 900px) { .x-rail { grid-template-columns: repeat(2, 1fr) !important; } }
        @media (max-width: 520px) { .x-rail { grid-template-columns: 1fr !important; } }
      `}</style>
    </section>
  );
}

Object.assign(window, {
  LogoAnthropic, LogoOpenAI, LogoVertex,
  IconX, IconGithub,
  XStatBar, TweetCard, XFeed
});
