/* Login — branded sign-in gate. Sign in with Google (Workspace). Assigns window.LedgerLogin */
(function () {
  const { Button } = window.LawCrimeDesignSystem_e18d68;

  function Login({ error }) {
    const [busy, setBusy] = React.useState(false);
    React.useEffect(() => { setTimeout(() => window.lucide && window.lucide.createIcons(), 30); });

    async function go() {
      setBusy(true);
      try { await window.LedgerAuth.signInWithGoogle(); }
      catch (e) { setBusy(false); alert(e.message || "Sign-in failed"); }
    }

    return (
      <div className="login">
        <div className="login__card">
          <div className="login__top">
            <img src="vendor/design/assets/logos/lawandcrime-wordmark-white.png" alt="Law and Crime" />
            <span className="login__tape">LEDGER</span>
          </div>
          <div className="login__body">
            <h1>Matters Workspace</h1>
            <p>Sign in with your Law&amp;Crime account to create, enrich, and search matters.</p>
            {error && <div className="login__err">{error}</div>}
            <Button variant="primary" icon="log-in" onClick={go} disabled={busy} style={{ width: "100%" }}>
              {busy ? "Redirecting…" : "Sign in with Google"}
            </Button>
            <div className="login__foot">Restricted to @{window.LEDGER_ALLOWED_DOMAIN} accounts.</div>
          </div>
        </div>
      </div>
    );
  }

  window.LedgerLogin = Login;
})();
