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

<?= view('partials/workspace_hero', [
    'workspaceCrumbPill'  => 'HRM',
    'workspaceCrumbCurrent' => 'Payroll Settings',
    'workspaceTitle'      => 'Bahrain Payroll Configuration',
    'workspaceDesc'       => 'SIO contribution rates, EOSB settings, overtime multipliers, and WPS employer ID.',
]) ?>

<article class="enterprise-settings-card" style="max-width:760px;">
    <div class="enterprise-settings-card__head">
        <i class="fa-solid fa-sliders"></i>
        <h2 class="enterprise-settings-card__title">Statutory & Calculation Settings</h2>
    </div>

    <?php if (session()->getFlashdata('errors')): ?>
        <div class="alert alert-danger py-2 small">
            <ul class="mb-0 ps-3">
                <?php foreach ((array) session()->getFlashdata('errors') as $err): ?>
                    <li><?= esc(is_array($err) ? implode(', ', $err) : $err) ?></li>
                <?php endforeach; ?>
            </ul>
        </div>
    <?php endif; ?>

    <form action="<?= base_url('payroll/settings') ?>" method="post" novalidate>
        <?= csrf_field() ?>
        <div class="enterprise-settings-fields">
            <div class="enterprise-field">
                <label class="enterprise-field-label">SIO Salary Cap (BHD)</label>
                <input type="number" name="sio_cap_amount" class="form-control" step="0.001" min="0"
                       value="<?= esc(old('sio_cap_amount', $settings['sio_cap_amount'])) ?>">
            </div>
            <div class="enterprise-field">
                <label class="enterprise-field-label">Bahraini Employer SIO %</label>
                <input type="number" name="sio_bahraini_employer_rate" class="form-control" step="0.01" min="0"
                       value="<?= esc(old('sio_bahraini_employer_rate', $settings['sio_bahraini_employer_rate'])) ?>">
            </div>
            <div class="enterprise-field">
                <label class="enterprise-field-label">Bahraini Employee SIO %</label>
                <input type="number" name="sio_bahraini_employee_rate" class="form-control" step="0.01" min="0"
                       value="<?= esc(old('sio_bahraini_employee_rate', $settings['sio_bahraini_employee_rate'])) ?>">
            </div>
            <div class="enterprise-field">
                <label class="enterprise-field-label">Expat Employer SIO %</label>
                <input type="number" name="sio_expat_employer_rate" class="form-control" step="0.01" min="0"
                       value="<?= esc(old('sio_expat_employer_rate', $settings['sio_expat_employer_rate'])) ?>">
            </div>
            <div class="enterprise-field">
                <label class="enterprise-field-label">Expat Employee SIO %</label>
                <input type="number" name="sio_expat_employee_rate" class="form-control" step="0.01" min="0"
                       value="<?= esc(old('sio_expat_employee_rate', $settings['sio_expat_employee_rate'])) ?>">
            </div>
            <div class="enterprise-field">
                <label class="enterprise-field-label">EOSB Rate — First 3 Years %</label>
                <input type="number" name="eosb_rate_first_3_years" class="form-control" step="0.01" min="0"
                       value="<?= esc(old('eosb_rate_first_3_years', $settings['eosb_rate_first_3_years'])) ?>">
            </div>
            <div class="enterprise-field">
                <label class="enterprise-field-label">EOSB Rate — After 3 Years %</label>
                <input type="number" name="eosb_rate_after_3_years" class="form-control" step="0.01" min="0"
                       value="<?= esc(old('eosb_rate_after_3_years', $settings['eosb_rate_after_3_years'])) ?>">
            </div>
            <div class="enterprise-field">
                <label class="enterprise-field-label">EOSB Effective Date</label>
                <input type="date" name="eosb_effective_date" class="form-control"
                       value="<?= esc(old('eosb_effective_date', $settings['eosb_effective_date'])) ?>">
            </div>
            <div class="enterprise-field">
                <label class="enterprise-field-label">Working Days / Month</label>
                <input type="number" name="working_days_per_month" class="form-control" min="1" max="31"
                       value="<?= esc(old('working_days_per_month', $settings['working_days_per_month'])) ?>">
            </div>
            <div class="enterprise-field">
                <label class="enterprise-field-label">Daily Work Hours</label>
                <input type="number" name="daily_work_hours" class="form-control" step="0.5" min="1"
                       value="<?= esc(old('daily_work_hours', $settings['daily_work_hours'])) ?>">
            </div>
            <div class="enterprise-field">
                <label class="enterprise-field-label">Overtime Day Multiplier</label>
                <input type="number" name="overtime_day_multiplier" class="form-control" step="0.01" min="1"
                       value="<?= esc(old('overtime_day_multiplier', $settings['overtime_day_multiplier'])) ?>">
            </div>
            <div class="enterprise-field">
                <label class="enterprise-field-label">Overtime Night/Holiday Multiplier</label>
                <input type="number" name="overtime_night_multiplier" class="form-control" step="0.01" min="1"
                       value="<?= esc(old('overtime_night_multiplier', $settings['overtime_night_multiplier'])) ?>">
            </div>
            <div class="enterprise-field">
                <label class="enterprise-field-label">Payment Day of Month</label>
                <input type="number" name="payment_day" class="form-control" min="1" max="31"
                       value="<?= esc(old('payment_day', $settings['payment_day'])) ?>">
            </div>
            <div class="enterprise-field enterprise-settings-fields--single" style="grid-column:1/-1;">
                <label class="enterprise-field-label">WPS Employer ID</label>
                <input type="text" name="wps_employer_id" class="form-control"
                       value="<?= esc(old('wps_employer_id', $settings['wps_employer_id'] ?? '')) ?>"
                       placeholder="For bank WPS file export">
            </div>
        </div>
        <div class="enterprise-settings-card__footer">
            <button type="submit" class="btn btn-primary">Save Settings</button>
        </div>
    </form>
</article>

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