<?php
$contract = $contract ?? [];
$isEdit   = ! empty($contract['id']);
?>
<div class="enterprise-settings-fields">
    <div class="enterprise-field" style="grid-column: 1 / -1;">
        <label class="enterprise-field-label">Title <span class="text-danger">*</span></label>
        <input type="text" name="title" class="form-control" maxlength="200"
               value="<?= esc(old('title', $contract['title'] ?? '')) ?>" required>
    </div>
    <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', $contract['supplier_id'] ?? '') === (string) $s['id'] ? 'selected' : '' ?>>
                    <?= esc($s['name']) ?>
                </option>
            <?php endforeach; ?>
        </select>
    </div>
    <?php if (! $isEdit): ?>
        <div class="enterprise-field">
            <label class="enterprise-field-label">Status</label>
            <select name="status" class="form-select">
                <?php foreach (['draft', 'active'] as $s): ?>
                    <option value="<?= $s ?>" <?= old('status', 'draft') === $s ? 'selected' : '' ?>><?= ucfirst($s) ?></option>
                <?php endforeach; ?>
            </select>
        </div>
    <?php endif; ?>
    <div class="enterprise-field">
        <label class="enterprise-field-label">Start Date</label>
        <input type="date" name="start_date" class="form-control"
               value="<?= esc(old('start_date', $contract['start_date'] ?? '')) ?>">
    </div>
    <div class="enterprise-field">
        <label class="enterprise-field-label">End Date</label>
        <input type="date" name="end_date" class="form-control"
               value="<?= esc(old('end_date', $contract['end_date'] ?? '')) ?>">
    </div>
    <div class="enterprise-field">
        <label class="enterprise-field-label">Value</label>
        <input type="number" name="value" class="form-control" step="0.01" min="0"
               value="<?= esc(old('value', $contract['value'] ?? '0')) ?>">
    </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', $contract['notes'] ?? '')) ?></textarea>
    </div>
</div>
