<?= $this->extend('layouts/main') ?>
<?= $this->section('content') ?>

<h1 class="h3 mb-3">New Staff User</h1>

<div class="card shadow-sm" style="max-width: 720px;">
    <div class="card-body">
        <form action="<?= site_url('users') ?>" method="post">
            <?= csrf_field() ?>

            <div class="row">
                <div class="col-md-6 mb-3">
                    <label class="form-label" for="full_name">Full Name</label>
                    <input type="text" class="form-control" id="full_name" name="full_name" required value="<?= esc(old('full_name')) ?>">
                </div>

                <div class="col-md-6 mb-3">
                    <label class="form-label" for="role">Role</label>
                    <select class="form-select" id="role" name="role" required>
                        <?php foreach ($lookups->staffRoles as $key => $meta): ?>
                            <option value="<?= esc($key) ?>" <?= old('role') === $key ? 'selected' : '' ?>><?= esc($meta['label']) ?></option>
                        <?php endforeach; ?>
                    </select>
                </div>

                <div class="col-md-6 mb-3">
                    <label class="form-label" for="email">Email</label>
                    <input type="email" class="form-control" id="email" name="email" required value="<?= esc(old('email')) ?>">
                </div>

                <div class="col-md-6 mb-3">
                    <label class="form-label" for="phone">Phone</label>
                    <input type="text" class="form-control" id="phone" name="phone" value="<?= esc(old('phone')) ?>">
                </div>

                <div class="col-md-6 mb-3">
                    <label class="form-label" for="password">Password (min 8 characters)</label>
                    <input type="password" class="form-control" id="password" name="password" required minlength="8">
                </div>
            </div>

            <hr class="my-1">
            <p class="text-muted small mt-3 mb-2">
                Payroll &amp; Identification <span class="fw-normal">— all optional now, and can also be filled in or changed later from the staff member's own profile page.</span>
            </p>
            <div class="row">
                <div class="col-md-4 mb-3">
                    <label class="form-label small text-muted" for="basic_salary">Monthly Basic Salary (GHS)</label>
                    <input type="number" step="0.01" min="0" class="form-control form-control-sm" id="basic_salary" name="basic_salary" value="<?= esc(old('basic_salary')) ?>" placeholder="Not set">
                </div>
                <div class="col-md-4 mb-3">
                    <label class="form-label small text-muted" for="employee_id">Employee ID</label>
                    <input type="text" class="form-control form-control-sm" id="employee_id" name="employee_id" value="<?= esc(old('employee_id')) ?>" placeholder="Not set">
                </div>
                <div class="col-md-4 mb-3">
                    <label class="form-label small text-muted" for="ssnit_number">SSNIT Number</label>
                    <input type="text" class="form-control form-control-sm" id="ssnit_number" name="ssnit_number" value="<?= esc(old('ssnit_number')) ?>" placeholder="Not set">
                </div>
                <div class="col-md-4 mb-3">
                    <label class="form-label small text-muted" for="ghana_card_number">Ghana Card Number</label>
                    <input type="text" class="form-control form-control-sm" id="ghana_card_number" name="ghana_card_number" value="<?= esc(old('ghana_card_number')) ?>" placeholder="Not set">
                </div>
                <div class="col-md-4 mb-3">
                    <label class="form-label small text-muted" for="bank_name">Bank Name</label>
                    <input type="text" class="form-control form-control-sm" id="bank_name" name="bank_name" value="<?= esc(old('bank_name')) ?>" placeholder="Not set">
                </div>
                <div class="col-md-4 mb-3">
                    <label class="form-label small text-muted" for="bank_branch">Bank Branch</label>
                    <input type="text" class="form-control form-control-sm" id="bank_branch" name="bank_branch" value="<?= esc(old('bank_branch')) ?>" placeholder="Not set">
                </div>
                <div class="col-md-4 mb-3">
                    <label class="form-label small text-muted" for="bank_account_number">Bank Account Number</label>
                    <input type="text" class="form-control form-control-sm" id="bank_account_number" name="bank_account_number" value="<?= esc(old('bank_account_number')) ?>" placeholder="Not set">
                </div>
            </div>

            <div class="d-flex gap-2 mt-2">
                <button type="submit" class="btn btn-primary">Create User</button>
                <a href="<?= site_url('users') ?>" class="btn btn-outline-secondary">Cancel</a>
            </div>
        </form>
    </div>
</div>

<?= $this->endSection() ?>
