<?php $pageTitle = 'Onboard a company'; require __DIR__ . '/../partials/standalone-head.php'; ?>
<?php require __DIR__ . '/_nav.php'; ?>

<div class="standalone-wrap">
  <div class="standalone-card">
    <h2 class="mb-1">Onboard a company manually</h2>
    <p class="text-muted mb-4">Creates the company, its subdomain, and its first (admin) user — activated immediately, no card or code needed.</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('platform/companies/onboard') ?>">
      <?= 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">Subdomain</label>
        <input type="text" name="subdomain" class="form-control" value="<?= old('subdomain') ?>" placeholder="companyname" required>
      </div>

      <div class="row g-2 mb-3">
        <div class="col-6">
          <label class="form-label">Admin 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">Admin 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">Admin email</label>
        <input type="email" name="email" class="form-control" value="<?= old('email') ?>" required>
      </div>

      <div class="mb-4">
        <label class="form-label">Activate for how many months?</label>
        <input type="number" name="duration_months" class="form-control" value="<?= old('duration_months', '12') ?>" min="1" max="60" required>
      </div>

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

</body>
</html>
