<?php

declare(strict_types=1);

require __DIR__ . '/includes/bootstrap.php';

$pageTitle = 'Sign in';
$pageScript = 'login';

ob_start();
?>
<div class="col-xl-5 col-lg-6 col-md-7 position-relative mx-auto">
  <div class="auth-content flex-column pt-8 pb-md-8 pb-13">
    <div class="uh-auth-brand text-center mb-4">
      <span class="uh-auth-brand-mark" aria-hidden="true"><?= uh_brand_svg('icon', 'uh-auth-brand-svg uh-brand-adaptive', '') ?></span>
      <span class="navbar-brand me-0 fw-bold fs-3"><?= h(UH_APP_NAME) ?></span>
    </div>
    <div class="uh-auth-divider mb-6" aria-hidden="true"></div>

    <!-- Step 1: email + password -->
    <form class="w-100" id="uh-login-form" novalidate>
      <div class="row">
        <div class="col-xl-7 col-sm-10 mx-auto">
          <div class="text-center mb-4">
            <h4 class="uh-auth-title">Sign in to your account</h4>
            <p class="text-muted uh-auth-subtitle">Use your Developer Console email and password.</p>
          </div>
          <div class="row gx-3">
            <div class="form-group col-lg-12">
              <div class="form-label-group"><label for="uh-login-email" class="uh-auth-label">Email</label></div>
              <input class="form-control" id="uh-login-email" name="email" placeholder="Email@example.com" type="email" autocomplete="email" required>
            </div>
            <div class="form-group col-lg-12">
              <div class="form-label-group"><label for="uh-login-password" class="uh-auth-label">Password</label></div>
              <div class="uh-password-field">
                <input class="form-control" id="uh-login-password" name="password" placeholder="Enter your password" type="password" autocomplete="current-password" required>
                <button type="button" class="uh-password-toggle" id="uh-login-password-toggle" aria-controls="uh-login-password" aria-pressed="false" aria-label="Show password">
                  <span class="uh-password-toggle-icon uh-password-toggle-icon--show"><?= uh_icon('eye', 18) ?></span>
                  <span class="uh-password-toggle-icon uh-password-toggle-icon--hide"><?= uh_icon('eye-off', 18) ?></span>
                </button>
              </div>
            </div>
          </div>
          <button type="submit" class="btn btn-primary btn-uppercase btn-block" id="uh-login-submit">Continue</button>
          <div class="text-center mt-4 fs-8">
            <a href="<?= h(uh_url('forgot-password.php')) ?>">Forgot password?</a>
            <span class="text-muted mx-1">&middot;</span>
            <a href="<?= h(uh_url('team-login.php')) ?>">Sign in as a team member</a>
          </div>
          <div class="text-center mt-2 fs-8 text-muted">
            Don't have an account? <a href="<?= h(uh_url('register.php')) ?>">Create one</a>
          </div>
        </div>
      </div>
    </form>

    <!-- Step 2: MFA verification (hidden until step 1 reports mfa_required) -->
    <form class="w-100 d-none" id="uh-mfa-form" novalidate>
      <div class="row">
        <div class="col-xl-7 col-sm-10 mx-auto">
          <div class="text-center mb-4">
            <h4 class="uh-auth-title">Verify it's you</h4>
            <p class="text-muted uh-auth-subtitle">Enter the 6-digit verification code sent to your email.</p>
          </div>
          <div class="form-group col-lg-12">
            <div class="form-label-group"><label for="uh-mfa-code" class="uh-auth-label">Verification code</label></div>
            <input class="form-control uh-auth-otp-input" id="uh-mfa-code" name="code" inputmode="numeric" autocomplete="one-time-code" placeholder="123456" required>
          </div>
          <div class="form-group form-check mb-3">
            <input type="checkbox" class="form-check-input" id="uh-mfa-trust-device">
            <label class="form-check-label fs-8" for="uh-mfa-trust-device">Trust this device for 30 days</label>
          </div>
          <div class="text-center mb-3 fs-8" id="uh-mfa-status" role="status" aria-live="polite"></div>
          <button type="submit" class="btn btn-primary btn-uppercase btn-block" id="uh-mfa-submit">Verify &amp; Sign In</button>
          <div class="text-center mt-3 fs-8">
            <span class="text-muted d-none" id="uh-mfa-resend-timer">Resend available in <span id="uh-mfa-resend-countdown">3:00</span></span>
            <button type="button" class="btn btn-link p-0 fs-8 d-none" id="uh-mfa-resend-btn">Resend code</button>
          </div>
          <button type="button" class="btn btn-flush-primary btn-block mt-2" id="uh-mfa-back">Back</button>
        </div>
      </div>
    </form>

    <!-- Step 3: forced password change (hidden unless login reports must_reset_password) —
         reuses developer/v1/auth/change-password.php with the just-entered
         current password, since the client already proved they know it. -->
    <form class="w-100 d-none" id="uh-force-reset-form" novalidate>
      <div class="row">
        <div class="col-xl-7 col-sm-10 mx-auto">
          <div class="text-center mb-4">
            <h4 class="uh-auth-title">Choose a new password</h4>
            <p class="text-muted uh-auth-subtitle">Your team requires you to set a new password before continuing.</p>
          </div>
          <div class="form-group">
            <label class="form-label" for="uh-force-reset-password">New password</label>
            <input class="form-control" id="uh-force-reset-password" name="new_password" placeholder="At least 8 characters" type="password" autocomplete="new-password" required>
          </div>
          <button type="submit" class="btn btn-primary btn-uppercase btn-block" id="uh-force-reset-submit">Set password &amp; continue</button>
        </div>
      </div>
    </form>
  </div>
  <div class="hk-footer border-0">
    <?php require __DIR__ . '/layouts/footer.php'; ?>
  </div>
</div>
<?php
// Hero copy: none set here — auth-hero.php's own default is now the
// platform-wide positioning statement (this page's old override named
// five services individually; that's the exact narrowness this pass
// replaced it to avoid).
require __DIR__ . '/includes/auth-hero.php';
$content = ob_get_clean();
require __DIR__ . '/layouts/auth.php';
