<?php if (!empty($error)): ?>
    <div class="alert alert-danger py-2 small"><?= e($error) ?></div>
<?php endif; ?>
<?php if (!empty($msg)): ?>
    <div class="alert alert-info py-2 small"><?= e($msg) ?></div>
<?php endif; ?>

<form method="post" action="<?= url('/Login/authenticate') ?>">
    <input type="hidden" name="_csrf" value="<?= e($csrf) ?>">

    <div class="mb-3">
        <label class="form-label">Company</label>
        <select name="tenant_id" class="form-select" required>
            <?php if (empty($tenants)): ?>
                <option value="">— no companies configured —</option>
            <?php else: ?>
                <?php foreach ($tenants as $t): ?>
                    <option value="<?= (int) $t['tenant_id'] ?>"><?= e($t['name']) ?></option>
                <?php endforeach; ?>
            <?php endif; ?>
        </select>
    </div>

    <div class="mb-3">
        <label class="form-label">Username</label>
        <input type="text" name="username" class="form-control" autocomplete="username" required autofocus>
    </div>

    <div class="mb-4">
        <label class="form-label">Password</label>
        <input type="password" name="password" class="form-control" autocomplete="current-password" required>
    </div>

    <button type="submit" class="btn btn-signin">
        <i class="fas fa-arrow-right-to-bracket me-2"></i>Sign in
    </button>
</form>
