<?php
$score     = $score ?? [];
$employees = $employees ?? [];
?>
<div class="enterprise-settings-fields">
    <div class="enterprise-field">
        <label class="enterprise-field-label">Subject Type <span class="text-danger">*</span></label>
        <select name="subject_type" class="form-select" required>
            <?php foreach (['employee', 'work_order', 'service_visit', 'inspection'] as $t): ?>
                <option value="<?= $t ?>" <?= old('subject_type', $score['subject_type'] ?? 'employee') === $t ? 'selected' : '' ?>>
                    <?= esc(ucwords(str_replace('_', ' ', $t))) ?>
                </option>
            <?php endforeach; ?>
        </select>
    </div>
    <div class="enterprise-field">
        <label class="enterprise-field-label">Subject ID <span class="text-danger">*</span></label>
        <input type="number" name="subject_id" class="form-control" min="1" required
               value="<?= esc(old('subject_id', $score['subject_id'] ?? '')) ?>">
    </div>
    <div class="enterprise-field enterprise-field--full">
        <label class="enterprise-field-label">Subject Label</label>
        <input type="text" name="subject_label" class="form-control" maxlength="200"
               value="<?= esc(old('subject_label', $score['subject_label'] ?? '')) ?>"
               placeholder="Optional display name">
    </div>
    <div class="enterprise-field">
        <label class="enterprise-field-label">Metric Code <span class="text-danger">*</span></label>
        <input type="text" name="metric_code" class="form-control" maxlength="80" required
               value="<?= esc(old('metric_code', $score['metric_code'] ?? '')) ?>" placeholder="e.g. QC_PASS_RATE">
    </div>
    <div class="enterprise-field">
        <label class="enterprise-field-label">Metric Name <span class="text-danger">*</span></label>
        <input type="text" name="metric_name" class="form-control" maxlength="150" required
               value="<?= esc(old('metric_name', $score['metric_name'] ?? '')) ?>" placeholder="e.g. Pass rate">
    </div>
    <div class="enterprise-field">
        <label class="enterprise-field-label">Score</label>
        <input type="number" name="score" class="form-control" step="0.01"
               value="<?= esc(old('score', $score['score'] ?? '0')) ?>">
    </div>
    <div class="enterprise-field">
        <label class="enterprise-field-label">Max Score</label>
        <input type="number" name="max_score" class="form-control" step="0.01"
               value="<?= esc(old('max_score', $score['max_score'] ?? '100')) ?>">
    </div>
    <div class="enterprise-field">
        <label class="enterprise-field-label">Period Start</label>
        <input type="date" name="period_start" class="form-control"
               value="<?= esc(old('period_start', $score['period_start'] ?? '')) ?>">
    </div>
    <div class="enterprise-field">
        <label class="enterprise-field-label">Period End</label>
        <input type="date" name="period_end" class="form-control"
               value="<?= esc(old('period_end', $score['period_end'] ?? '')) ?>">
    </div>
    <div class="enterprise-field">
        <label class="enterprise-field-label">Scored By</label>
        <select name="scored_by" class="form-select">
            <option value="">None</option>
            <?php foreach ($employees as $e): ?>
                <option value="<?= (int) $e['id'] ?>"
                    <?= (string) old('scored_by', $score['scored_by'] ?? '') === (string) $e['id'] ? 'selected' : '' ?>>
                    <?= esc($e['full_name']) ?> (<?= esc($e['employee_number']) ?>)
                </option>
            <?php endforeach; ?>
        </select>
    </div>
    <div class="enterprise-field enterprise-field--full">
        <label class="enterprise-field-label">Notes</label>
        <textarea name="notes" class="form-control" rows="3"><?= esc(old('notes', $score['notes'] ?? '')) ?></textarea>
    </div>
</div>
