@php
    $variant = $variant ?? [];
    $label = $variant['label'] ?? '';
    $unit = $variant['unit'] ?? 'kg';
    $baseUnitPrice = $variant['base_unit_price'] ?? '';
    $finalPrice = $variant['final_price'] ?? '';
    $salePrice = $variant['sale_price'] ?? '';
@endphp
<tr class="variant-row">
    <td class="px-3 py-2">
        <input type="text" name="variants[{{ $index }}][label]" value="{{ old('variants.' . $index . '.label', $label) }}" required
               class="w-full border border-gray-300 rounded-md px-2 py-1 text-sm focus:outline-none focus:ring-2 focus:ring-blue-500"
               placeholder="e.g. 1100–1190 gm (Per Piece)">
    </td>
    <td class="px-3 py-2">
        <select name="variants[{{ $index }}][unit]"
                class="w-full border border-gray-300 rounded-md px-2 py-1 text-sm focus:outline-none focus:ring-2 focus:ring-blue-500">
            <option value="kg" {{ old('variants.' . $index . '.unit', $unit) == 'kg' ? 'selected' : '' }}>kg</option>
            <option value="gm" {{ old('variants.' . $index . '.unit', $unit) == 'gm' ? 'selected' : '' }}>gm</option>
            <option value="pcs" {{ old('variants.' . $index . '.unit', $unit) == 'pcs' ? 'selected' : '' }}>pcs</option>
        </select>
    </td>
    <td class="px-3 py-2">
        <input type="number" name="variants[{{ $index }}][base_unit_price]" value="{{ old('variants.' . $index . '.base_unit_price', $baseUnitPrice) }}" required step="0.01" min="0"
               class="w-full border border-gray-300 rounded-md px-2 py-1 text-sm focus:outline-none focus:ring-2 focus:ring-blue-500"
               placeholder="0.00">
    </td>
    <td class="px-3 py-2">
        <input type="number" name="variants[{{ $index }}][final_price]" value="{{ old('variants.' . $index . '.final_price', $finalPrice) }}" required step="0.01" min="0"
               class="w-full border border-gray-300 rounded-md px-2 py-1 text-sm focus:outline-none focus:ring-2 focus:ring-blue-500"
               placeholder="0.00">
    </td>
    <td class="px-3 py-2">
        <input type="number" name="variants[{{ $index }}][sale_price]" value="{{ old('variants.' . $index . '.sale_price', $salePrice) }}" step="0.01" min="0"
               class="w-full border border-gray-300 rounded-md px-2 py-1 text-sm focus:outline-none focus:ring-2 focus:ring-blue-500"
               placeholder="0.00">
    </td>
    <td class="px-3 py-2 text-right">
        <button type="button" onclick="removeVariantRow(this)"
                class="text-red-600 hover:text-red-800 font-medium text-sm">🗑️</button>
    </td>
</tr>
