<?php
$request   = $request ?? [];
$isEdit    = ! empty($request['id']);
$taxAmount = $taxAmount ?? ($request['tax_amount'] ?? 0);
?>
<div class="enterprise-settings-fields">
    <div class="enterprise-field">
        <label class="enterprise-field-label">Request Date <span class="text-danger">*</span></label>
        <input type="date" name="request_date" class="form-control" required
               value="<?= esc(old('request_date', $request['request_date'] ?? date('Y-m-d'))) ?>">
    </div>
    <div class="enterprise-field">
        <label class="enterprise-field-label">Needed By</label>
        <input type="date" name="needed_by" class="form-control"
               value="<?= esc(old('needed_by', $request['needed_by'] ?? '')) ?>">
    </div>
    <div class="enterprise-field">
        <label class="enterprise-field-label">Department</label>
        <input type="text" name="department" class="form-control" maxlength="100"
               value="<?= esc(old('department', $request['department'] ?? '')) ?>"
               placeholder="e.g. Operations, IT">
    </div>
    <?php if (! $isEdit): ?>
        <div class="enterprise-field">
            <label class="enterprise-field-label">Status</label>
            <select name="status" class="form-select">
                <?php foreach (['draft' => 'Draft', 'pending_approval' => 'Pending Approval'] as $val => $label): ?>
                    <option value="<?= $val ?>" <?= old('status', 'draft') === $val ? 'selected' : '' ?>><?= $label ?></option>
                <?php endforeach; ?>
            </select>
        </div>
    <?php endif; ?>
    <div class="enterprise-field" style="grid-column: 1 / -1;">
        <label class="enterprise-field-label">Notes</label>
        <textarea name="notes" class="form-control" rows="3"><?= esc(old('notes', $request['notes'] ?? '')) ?></textarea>
    </div>
    <?= $this->include('Modules\Sale\Views\partials\document_lines', [
        'lines'     => $lines ?? [],
        'mode'      => 'priced',
        'taxAmount' => $taxAmount,
    ]) ?>
</div>
