"use client"; import { cn } from "@app/lib/cn"; import { RadioGroup, RadioGroupItem } from "./ui/radio-group"; import { useState, ReactNode } from "react"; export interface StrategyOption { id: TValue; title: string; description: string | ReactNode; disabled?: boolean; icon?: ReactNode; } interface StrategySelectProps { options: ReadonlyArray>; value?: TValue | null; defaultValue?: TValue; onChange?: (value: TValue) => void; cols?: number; } export function StrategySelect({ options, value: controlledValue, defaultValue, onChange, cols = 1 }: StrategySelectProps) { const [uncontrolledSelected, setUncontrolledSelected] = useState< TValue | undefined >(defaultValue); const isControlled = controlledValue !== undefined; const selected = isControlled ? (controlledValue ?? undefined) : uncontrolledSelected; return ( { const typedValue = value as TValue; if (!isControlled) setUncontrolledSelected(typedValue); onChange?.(typedValue); }} style={{ // @ts-expect-error "--cols": `repeat(${cols}, 1fr)` }} className="grid md:grid-cols-(--cols) gap-4" > {options.map((option: StrategyOption) => ( ))} ); }