<?php
$order = $order ?? [];
?>
<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', $order['title'] ?? '')) ?>" placeholder="e.g. Site maintenance — Building A">
    </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', $order['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', $order['priority'] ?? 'normal') === $p ? 'selected' : '' ?>>
                    <?= esc(ucfirst($p)) ?>
                </option>
            <?php endforeach; ?>
        </select>
    </div>
    <?php if (empty($order)): ?>
        <div class="enterprise-field">
            <label class="enterprise-field-label">Initial Status</label>
            <select name="status" class="form-select">
                <option value="open" <?= old('status', 'open') === 'open' ? 'selected' : '' ?>>Open</option>
                <option value="draft" <?= old('status') === 'draft' ? 'selected' : '' ?>>Draft</option>
            </select>
        </div>
    <?php endif; ?>
    <div class="enterprise-field">
        <label class="enterprise-field-label">Scheduled Date</label>
        <input type="date" name="scheduled_date" class="form-control"
               value="<?= esc(old('scheduled_date', $order['scheduled_date'] ?? '')) ?>">
    </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', $order['due_date'] ?? '')) ?>">
    </div>
    <div class="enterprise-field enterprise-field--full">
        <label class="enterprise-field-label">Location</label>
        <input type="text" name="location" class="form-control" maxlength="200"
               value="<?= esc(old('location', $order['location'] ?? '')) ?>" placeholder="Site, building, or area">
    </div>
    <div class="enterprise-field enterprise-field--full">
        <label class="enterprise-field-label">Notes</label>
        <textarea name="notes" class="form-control" rows="2"><?= esc(old('notes', $order['notes'] ?? '')) ?></textarea>
    </div>
</div>
