<?php
$row     = $row ?? [];
$lookups = $lookups ?? [];
$assets = $lookups['assets'] ?? [];
$workOrders = $lookups['workOrders'] ?? [];
$serviceVisits = $lookups['serviceVisits'] ?? [];
?>
<div class="enterprise-settings-fields">
    <div class="enterprise-field enterprise-field--full">
        <label class="enterprise-field-label">Inventory Asset <span class="text-danger">*</span></label>
        <select name="inventory_asset_id" class="form-select" required>
            <option value="">Select asset</option>
            <?php foreach ($assets as $a): ?>
                <option value="<?= (int) $a['id'] ?>"
                    <?= (string) old('inventory_asset_id', $row['inventory_asset_id'] ?? '') === (string) $a['id'] ? 'selected' : '' ?>>
                    <?= esc($a['name']) ?> (<?= esc($a['asset_tag']) ?>)
                </option>
            <?php endforeach; ?>
        </select>
    </div>
    <div class="enterprise-field">
        <label class="enterprise-field-label">Work Order</label>
        <select name="work_order_id" class="form-select">
            <option value="">None</option>
            <?php foreach ($workOrders as $wo): ?>
                <option value="<?= (int) $wo['id'] ?>"
                    <?= (string) old('work_order_id', $row['work_order_id'] ?? '') === (string) $wo['id'] ? 'selected' : '' ?>>
                    <?= esc($wo['number']) ?> — <?= esc($wo['title']) ?>
                </option>
            <?php endforeach; ?>
        </select>
    </div>
    <div class="enterprise-field">
        <label class="enterprise-field-label">Service Visit</label>
        <select name="service_visit_id" class="form-select">
            <option value="">None</option>
            <?php foreach ($serviceVisits as $sv): ?>
                <option value="<?= (int) $sv['id'] ?>"
                    <?= (string) old('service_visit_id', $row['service_visit_id'] ?? '') === (string) $sv['id'] ? 'selected' : '' ?>>
                    <?= esc($sv['number']) ?><?= ! empty($sv['title']) ? ' — ' . esc($sv['title']) : '' ?>
                </option>
            <?php endforeach; ?>
        </select>
    </div>
    <div class="enterprise-field enterprise-field--full">
        <label class="enterprise-field-label">Notes</label>
        <textarea name="notes" class="form-control" rows="3" maxlength="500"><?= esc(old('notes', $row['notes'] ?? '')) ?></textarea>
    </div>
</div>
