import { useState } from 'react'
import { IconChevronDown } from '@tabler/icons-react'
import DrugResultRow from './DrugResultRow'
import type { DrugSearchResult } from '../../../types/drug_reference'
import { PRODUCT_TYPES } from '../../../types/drug_reference'
export interface IngredientGrouping {
key: string
/** Display name (title-cased ingredient list). */
label: string
/** True when this group is a single active ingredient (ranked above combos). */
single: boolean
products: DrugSearchResult[]
}
/**
* A collapsible "active ingredient → its products" group for the drug-name search.
* A single-product group renders as a plain (ingredient-first) row; multi-product
* groups collapse behind the ingredient name so the list stays scannable.
*/
export default function IngredientGroup({
group,
defaultOpen = false,
}: {
group: IngredientGrouping
/** Expand this group on first render (used for the top/first result group). */
defaultOpen?: boolean
}) {
const [open, setOpen] = useState(defaultOpen)
if (group.products.length === 1) {
return