<?php
$task = $task ?? [];
$employees = $employees ?? [];
?>
<div class="enterprise-settings-fields">
    <div class="enterprise-field enterprise-field--full">
        <label class="enterprise-field-label">Title <span class="text-danger">*</span></label>
        <input type="text" name="title" class="form-control" maxlength="200" required
               value="<?= esc(old('title', $task['title'] ?? '')) ?>" placeholder="e.g. Inspect safety equipment">
    </div>
    <div class="enterprise-field enterprise-field--full">
        <label class="enterprise-field-label">Description</label>
        <textarea name="description" class="form-control" rows="3"><?= esc(old('description', $task['description'] ?? '')) ?></textarea>
    </div>
    <div class="enterprise-field">
        <label class="enterprise-field-label">Priority</label>
        <select name="priority" class="form-select">
            <?php foreach (['low', 'normal', 'high', 'urgent'] as $p): ?>
                <option value="<?= $p ?>" <?= old('priority', $task['priority'] ?? 'normal') === $p ? 'selected' : '' ?>>
                    <?= esc(ucfirst($p)) ?>
                </option>
            <?php endforeach; ?>
        </select>
    </div>
    <div class="enterprise-field">
        <label class="enterprise-field-label">Status</label>
        <select name="status" class="form-select">
            <?php foreach (['open', 'in_progress'] as $s): ?>
                <option value="<?= $s ?>" <?= old('status', $task['status'] ?? 'open') === $s ? 'selected' : '' ?>>
                    <?= esc(ucwords(str_replace('_', ' ', $s))) ?>
                </option>
            <?php endforeach; ?>
        </select>
    </div>
    <div class="enterprise-field">
        <label class="enterprise-field-label">Due Date</label>
        <input type="date" name="due_date" class="form-control"
               value="<?= esc(old('due_date', $task['due_date'] ?? '')) ?>">
    </div>
    <div class="enterprise-field">
        <label class="enterprise-field-label">Assignee</label>
        <select name="assignee_employee_id" class="form-select">
            <option value="">Unassigned</option>
            <?php foreach ($employees as $e): ?>
                <option value="<?= (int) $e['id'] ?>"
                    <?= (string) old('assignee_employee_id', $task['assignee_employee_id'] ?? '') === (string) $e['id'] ? 'selected' : '' ?>>
                    <?= esc($e['full_name']) ?> (<?= esc($e['employee_number']) ?>)
                </option>
            <?php endforeach; ?>
        </select>
    </div>
</div>
