<?php
$bill      = $bill ?? [];
$suppliers = $suppliers ?? [];
$lines     = $lines ?? [];
$isEdit    = ! empty($bill['id']);
$taxAmount = $taxAmount ?? ($bill['tax_amount'] ?? 0);
?>
<div class="enterprise-settings-fields">
    <div class="enterprise-field">
        <label class="enterprise-field-label">Supplier <span class="text-danger">*</span></label>
        <select name="supplier_id" class="form-select" required>
            <option value="">— Select supplier —</option>
            <?php foreach ($suppliers as $s): ?>
                <option value="<?= $s['id'] ?>" <?= (string) old('supplier_id', $bill['supplier_id'] ?? '') === (string) $s['id'] ? 'selected' : '' ?>>
                    <?= esc($s['name']) ?>
                </option>
            <?php endforeach; ?>
        </select>
    </div>
    <div class="enterprise-field">
        <label class="enterprise-field-label">Bill Date <span class="text-danger">*</span></label>
        <input type="date" name="bill_date" class="form-control" required
               value="<?= esc(old('bill_date', $bill['bill_date'] ?? date('Y-m-d'))) ?>">
    </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', $bill['due_date'] ?? '')) ?>">
    </div>
    <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', $bill['notes'] ?? '')) ?></textarea>
    </div>
    <?= $this->include('Modules\Sale\Views\partials\document_lines', ['lines' => $lines, 'mode' => 'priced', 'taxAmount' => $taxAmount]) ?>
</div>
