<?php $pageTitle = 'Start your CRM'; require __DIR__ . '/../partials/standalone-head.php'; ?>

<div class="standalone-wrap">
  <div class="d-flex align-items-center gap-2 mb-4">
    <div class="brand-mark">CRM</div>
    <div class="fw-bold fs-5">Get started</div>
  </div>

  <div class="standalone-card">
    <h2 class="mb-1">Create your company's account</h2>
    <p class="text-muted mb-4">14-day free trial. No card required to get started — you can activate with a card or a subscription code on the next step.</p>

    <?php $errors = \App\Core\Session::getFlash('_errors', []); ?>
    <?php if ($errors): ?>
      <div class="alert alert-danger">
        <ul class="mb-0">
          <?php foreach ($errors as $field => $messages): foreach ((array) $messages as $m): ?>
            <li><?= e($m) ?></li>
          <?php endforeach; endforeach; ?>
        </ul>
      </div>
    <?php endif; ?>

    <form method="POST" action="<?= base_url('signup') ?>">
      <?= csrf_field() ?>

      <div class="mb-3">
        <label class="form-label">Company name</label>
        <input type="text" name="company_name" class="form-control" value="<?= old('company_name') ?>" required>
      </div>

      <div class="mb-3">
        <label class="form-label">Choose your subdomain</label>
        <div class="input-group">
          <input type="text" name="subdomain" class="form-control" value="<?= old('subdomain') ?>" placeholder="yourcompany" required>
          <span class="input-group-text">.<?= e($appDomain) ?></span>
        </div>
        <div class="form-text">Letters, numbers, and hyphens only. This is where your team will log in.</div>
      </div>

      <div class="row g-2 mb-3">
        <div class="col-6">
          <label class="form-label">Your first name</label>
          <input type="text" name="first_name" class="form-control" value="<?= old('first_name') ?>" required>
        </div>
        <div class="col-6">
          <label class="form-label">Your last name</label>
          <input type="text" name="last_name" class="form-control" value="<?= old('last_name') ?>" required>
        </div>
      </div>

      <div class="mb-3">
        <label class="form-label">Work email</label>
        <input type="email" name="email" class="form-control" value="<?= old('email') ?>" required>
      </div>

      <div class="mb-4">
        <label class="form-label">Password</label>
        <input type="password" name="password" class="form-control" minlength="10" required>
        <div class="form-text">At least 10 characters.</div>
      </div>

      <button type="submit" class="btn btn-primary w-100">Continue</button>
    </form>
  </div>

  <p class="text-center text-muted small mt-3">Already have an account? <a href="<?= base_url('login') ?>">Sign in</a></p>
</div>

</body>
</html>
