<?php
$stores = isset($stores) ? $stores : array();
?>

<div class="container-fluid py-4">
    <div class="row justify-content-center">
        <div class="col-lg-8">
            <div class="d-flex align-items-center justify-content-between mb-4">
                <div>
                    <h4 class="fw-bold mb-1"><i class="fa-solid fa-user-plus text-primary me-2"></i>Add Staff Member</h4>
                    <p class="text-muted mb-0">Register staff credentials, designation &amp; branch store assignment.</p>
                </div>
                <a href="<?php echo base_url('admin/staff'); ?>" class="btn btn-outline-secondary">
                    <i class="fa-solid fa-arrow-left me-1"></i> Back to Staff List
                </a>
            </div>

            <div class="card border-0 shadow-sm rounded-4">
                <div class="card-body p-4 p-md-5">
                    <form action="<?php echo base_url('admin/add_staff'); ?>" method="post">
                        <div class="row g-3">
                            <div class="col-md-8">
                                <label class="form-label fw-semibold">Full Name <span class="text-danger">*</span></label>
                                <input type="text" name="fullName" class="form-control form-control-lg rounded-3" placeholder="e.g. Ahmad Khan" required>
                            </div>

                            <div class="col-md-4">
                                <label class="form-label fw-semibold">Staff ID <span class="text-danger">*</span></label>
                                <input type="text" name="staffId" class="form-control form-control-lg rounded-3 font-monospace" value="ST-<?php echo rand(100, 999); ?>" placeholder="ST-100" required>
                            </div>

                            <div class="col-md-6">
                                <label class="form-label fw-semibold">Designation</label>
                                <input type="text" name="designation" class="form-control rounded-3" placeholder="e.g. Shift Supervisor / Store Staff" value="Shift Supervisor">
                            </div>

                            <div class="col-md-6">
                                <label class="form-label fw-semibold">Assign to Store Branch <span class="text-danger">*</span></label>
                                <select name="storeId" class="form-select rounded-3" required>
                                    <option value="">Select Branch Store...</option>
                                    <?php foreach ($stores as $sId => $s): ?>
                                        <option value="<?php echo htmlspecialchars($sId); ?>">
                                            <?php echo htmlspecialchars(isset($s['name']) ? $s['name'] : $sId); ?> (<?php echo htmlspecialchars(isset($s['city']) ? $s['city'] : 'Islamabad'); ?>)
                                        </option>
                                    <?php endforeach; ?>
                                </select>
                            </div>

                            <div class="col-md-6">
                                <label class="form-label fw-semibold">Phone Number</label>
                                <input type="text" name="phone" class="form-control rounded-3" placeholder="e.g. +923001234567" value="+923001234567">
                            </div>

                            <div class="col-md-3">
                                <label class="form-label fw-semibold">Check-In PIN Code</label>
                                <input type="password" name="pinCode" class="form-control rounded-3 text-center font-monospace fs-5" maxlength="6" value="1234" placeholder="1234" required>
                            </div>

                            <div class="col-md-3">
                                <label class="form-label fw-semibold">Shift Timing</label>
                                <select name="shift" class="form-select rounded-3">
                                    <option value="Morning">Morning</option>
                                    <option value="Evening">Evening</option>
                                    <option value="Night">Night</option>
                                </select>
                            </div>

                            <div class="col-12">
                                <label class="form-label fw-semibold">Profile Image URL</label>
                                <input type="url" name="imageUrl" class="form-control rounded-3" placeholder="https://..." value="https://upload.wikimedia.org/wikipedia/commons/9/9e/Placeholder_Person.jpg">
                            </div>

                            <div class="col-12 mt-4">
                                <div class="form-check form-switch fs-5">
                                    <input class="form-check-input" type="checkbox" name="isActive" id="isActiveStaff" value="1" checked>
                                    <label class="form-check-label fs-6 fw-semibold ms-2" for="isActiveStaff">Active Status</label>
                                </div>
                            </div>

                            <div class="col-12 mt-4 pt-3 border-top d-flex justify-content-end gap-2">
                                <a href="<?php echo base_url('admin/staff'); ?>" class="btn btn-light px-4">Cancel</a>
                                <button type="submit" class="btn btn-primary px-5 fw-semibold">
                                    <i class="fa-solid fa-check me-1"></i> Register Staff
                                </button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
