@foreach($drugs as $d)
@php
$rowData = [
'id' => $d->id,
'name' => $d->name,
'generic_name' => $d->generic_name,
'category' => $d->category,
'unit' => $d->unit,
'reorder_level' => $d->reorder_level ?? 0,
'cost_price' => $d->cost_price,
'selling_price' => $d->selling_price,
'is_active' => (bool) $d->is_active,
];
@endphp
@php
// If the drug's current category isn't on the canonical list,
// render the dropdown with NO selection so the row visibly
// reads "unresolved". The legacy value is shown as a badge
// below the dropdown (so the admin can see what it was) but
// is NOT an option in the list — forcing a pick from the 20.
//
// `data-original` then reflects the UI truth: original category
// is empty. This prevents the row from being falsely flagged
// "dirty" on load just because we rendered the select differently
// than the DB value. It also means selecting ANY canonical
// category (even one that happens to match the legacy label
// textually) is a deliberate change — which is what we want.
$isCanonical = $d->category && $categories->contains($d->category);
$rowCategoryForDirty = $isCanonical ? $d->category : null;
$rowData['category'] = $rowCategoryForDirty;
@endphp