<?php
/**
 * @var string $csrf
 * @var string|null $message
 * @var string|null $error
 */
?>

<div class="row justify-content-center">
    <div class="col-lg-8">
        <div class="card shadow-sm">
            <div class="card-body">
                <h4 class="card-title mb-3">Pendaftaran Pekerja</h4>
                <?php if (!empty($message)): ?>
                    <div class="alert alert-success"><?= htmlspecialchars($message) ?></div>
                <?php endif; ?>
                <?php if (!empty($error)): ?>
                    <div class="alert alert-danger"><?= htmlspecialchars($error) ?></div>
                <?php endif; ?>
                <?php if (empty($locations)): ?>
                    <div class="alert alert-warning">
                        Tambah senarai lokasi terlebih dahulu di <a href="index.php?route=admin/settings"><strong>Tetapan Syarikat</strong></a>.
                        Lokasi diperlukan untuk mendaftarkan pekerja baharu.
                    </div>
                <?php endif; ?>
                <form method="post" action="index.php?route=admin/employees/store" class="row g-3">
                    <?= $csrf ?>
                    <div class="col-md-6">
                        <label class="form-label">Nama Pekerja</label>
                        <input type="text" name="staff_name" class="form-control" required>
                    </div>
                    <div class="col-md-6">
                        <label class="form-label">No. Kad Pengenalan (12 digit)</label>
                        <input type="text" name="staff_ic" class="form-control" pattern="\d{12}" maxlength="12" placeholder="Contoh: 123456789012" required>
                    </div>
                    <div class="col-12">
                        <label class="form-label">Alamat</label>
                        <textarea name="staff_address" class="form-control" rows="2"></textarea>
                    </div>
                    <div class="col-md-6">
                        <label class="form-label">Email (untuk notifikasi)</label>
                        <input type="email" name="staff_email" class="form-control">
                    </div>
                    <div class="col-md-6">
                        <label class="form-label">No. Telefon</label>
                        <input type="text" name="staff_phone" class="form-control">
                    </div>
                    <div class="col-md-6">
                        <label class="form-label">Tarikh Lantikan</label>
                        <input type="date" name="staff_hire_date" class="form-control">
                    </div>
                    <div class="col-md-6">
                        <label class="form-label">Lokasi Bekerja</label>
                        <select name="staff_location" class="form-select" <?= empty($locations) ? 'disabled' : 'required' ?>>
                            <option value="">Pilih lokasi</option>
                            <?php foreach ($locations as $loc): ?>
                                <option value="<?= htmlspecialchars($loc) ?>"><?= htmlspecialchars($loc) ?></option>
                            <?php endforeach; ?>
                        </select>
                        <small class="text-muted">Lokasi diambil daripada Tetapan Syarikat.</small>
                    </div>
                    <div class="col-md-6">
                        <label class="form-label">Bank</label>
                        <input type="text" name="staff_bank" class="form-control">
                    </div>
                    <div class="col-md-6">
                        <label class="form-label">No. Akaun</label>
                        <input type="text" name="staff_account" class="form-control">
                    </div>
                    <div class="col-md-6">
                        <label class="form-label">Jumlah Cuti Dibenarkan (hari)</label>
                        <input type="number" name="staff_allowed_leave" class="form-control" min="0" value="0">
                    </div>
                    <div class="col-12">
                        <p class="text-muted small mb-0">
                            Selepas daftar, sistem akan jana user role <strong>Staff</strong> dengan
                            ID Pengguna dan Password sama seperti No. Kad Pengenalan.
                        </p>
                    </div>
                    <div class="col-12">
                        <button class="btn btn-primary w-100" <?= empty($locations) ? 'disabled' : '' ?>>Daftar Pekerja</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>


