/* Evolve Edge — the signed-out landing (#120).
 *
 * WHAT THIS IS NOT ANY MORE: a sign-in route. There is no email field, no password field, and no
 * call to `POST /api/auth/login` — a route that no longer exists either (pitchiq#461). Marcos ruled
 * the Suite is the only place anyone signs in, and for THIS file that is satisfied by removing the
 * FORM — not by removing this page.
 *
 * WHY THE PAGE SURVIVES THE FORM. `suite-redirect.js` has EIGHT conditions, each sufficient on its
 * own, that return `stay()` — authed, signedOutMarker, localOverride, `/auth/verify`,
 * `/onboarding`, not-a-fresh-arrival, a shared session that is anything but proven-absent, and no
 * configured Suite URL. Its docblock states the rule: "every unknown, every outage, every
 * misconfiguration, every cookie we could not read: the visitor stays here." **`stay()` renders
 * THIS COMPONENT.** It is not a page beside the one-way door; it is the door's safe harbour, and
 * eight code paths land on it.
 *
 * AND DELETING IT WOULD NOT 404. Edge is a hash-routed SPA with no bundler-enforced module graph.
 * `app.jsx:293` records what that costs: "#83: VerifyPage was deleted with the magic-link flow, but
 * this route outlived it and threw ReferenceError on every hit, killing the whole SPA render." This
 * component is the repair for that incident.
 *
 * The copy here is NOT new. The heading, tagline, footer and promo panel all shipped already and
 * are unrelated to the form; removing the form leaves them untouched. The single exception is the
 * call to action below, which is marked provisional.
 */

/* PROVISIONAL COPY — NOT APPROVED. Owned by the copy question filed against this ticket, and
 * shared with Coach's `matchiq-for-sellers#1018`, which faces the identical wording problem. Ships
 * marked rather than blocking on an absent approver, on the precedent of #716's titleless email.
 * Everything else on this page is shipped text kept as-is. */
const SUITE_CTA_LABEL = "Sign in at Evolve Suite";

/* pitchiq#312 — Edge's own routes for the two legal pages. The server answers each with a 302 to the
 * Suite's page (server/src/app.ts, #387: Edge keeps no copy of either) and with a 404 when no Suite is
 * configured, so the footer offers them only when a Suite URL is known. */
const PRIVACY_PATH = "/privacy";
const TERMS_PATH = "/terms";

function LoginPage({ suiteUrl = null }) {
  // Built exactly as `suite-redirect.js` builds it, so a visitor who follows this link and one who
  // is redirected automatically arrive at the same place: trailing slashes stripped, `app=edge`,
  // and a returnUrl of `<origin>/app` — NOT the bare origin, which only 302s here (pitchiq#387).
  //
  // NULL-GUARDED, and this is the case that matters most rather than an edge case: "no configured
  // Suite URL" is one of the eight conditions that sends a visitor HERE. Rendering a link to
  // `null/sign-in` for exactly the visitor whose Suite we could not locate would turn the safe
  // harbour into a dead end — the one outcome this whole change exists to avoid.
  const suiteHref = suiteUrl
    ? String(suiteUrl).replace(/\/+$/, "")
      + "/sign-in?app=edge&returnUrl="
      + encodeURIComponent(((window.location && window.location.origin) || "").replace(/\/+$/, "") + "/app")
    : null;

  return (
    <div className="mp-login mp-fade">
      <div className="mp-login__left">
        <div className="mp-login__wrap">
            <div className="mp-login__anim mp-login__fields">
              <EvolveSuiteLogo />
              <div className="mp-login__greet">
                <p className="text-heading-3" style={{ margin: 0 }}>Welcome to Evolve Edge</p>
                <p className="mp-login__tag">Walk in ready. Every time.</p>
              </div>
              {suiteHref && (
                <a className="tm-btn tm-btn--primary tm-btn--block" href={suiteHref}>{SUITE_CTA_LABEL}</a>
              )}
            </div>
        </div>
        {/* pitchiq#312 — these were `href="#"` with the click prevented: links that did nothing. Shown
            only with a Suite to land on, like the call to action above — never a dead one. The
            "Need help?" link that sat under that button is gone for the same reason: there is no
            signed-out help page in either product to point it at. */}
        <div className="mp-login__foot">
          <span>© 2026 Evolve Edge</span>
          {suiteHref && <span>·</span>}
          {suiteHref && <a href={PRIVACY_PATH}>Privacy</a>}
          {suiteHref && <a href={TERMS_PATH}>Terms</a>}
        </div>
      </div>

      <div className="mp-login__right">
        <img className="mp-login__bg" src="app/assets/login-image.avif" alt="" />
        <div className="mp-login__overlay"></div>
        <div className="mp-login__promo">
          <span className="mp-promo-eyebrow">Your pre-call wingman, built for sales</span>
          <h2>Know more than they expect. Before you say hello.</h2>
          <ul className="mp-promo-list">
            <li><Icon name="Target" size={18} /><span>We match <b>what you sell</b> to <b>what they need</b> — real fit, scored before the call.</span></li>
            <li><Icon name="Zap" size={18} /><span>A ready-to-use Game Day Brief in about a minute — not 3–4 hours of digging.</span></li>
            <li><Icon name="ListChecks" size={18} /><span>What to say, what to ask, what they'll push back on — all in one place.</span></li>
          </ul>
        </div>
      </div>
    </div>
  );
}

Object.assign(window, { LoginPage });
