import { useController } from '@graphcommerce/ecommerce-ui' import { Money } from '@graphcommerce/magento-store' import { filterNonNullableKeys, SectionHeader, sxx } from '@graphcommerce/next-ui' import { t } from '@lingui/core/macro' import { Box, MenuItem, TextField } from '@mui/material' import { useFormAddProductsToCart } from '../AddProductsToCart' import type { OptionTypeRenderer } from './CustomizableAreaOption' export type CustomizableDropDownOptionProps = React.ComponentProps< OptionTypeRenderer['CustomizableDropDownOption'] > export function CustomizableDropDownOption(props: CustomizableDropDownOptionProps) { const { uid, required, index, title, dropdownValue, productPrice, currency } = props const { control } = useFormAddProductsToCart() const label = title ?? '' const { field: { onChange, value, ref, ...field }, fieldState: { invalid, error }, } = useController({ name: `cartItems.${index}.selected_options_record.${uid}`, rules: { required: required ? t`Please select a value for ‘${label}’` : false, }, control, defaultValue: '', }) return ( {title} {required && ' *'} } sx={{ mt: 0 }} /> onChange(event.target.value)} select error={invalid} helperText={error?.message} > {filterNonNullableKeys(dropdownValue, ['title']).map((option) => ( {option.title} {option.price ? ( ) : null} ))} ) }