import { memo } from 'react'; import FieldWrapper from './FieldWrapper'; import { __ } from '@wordpress/i18n'; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from './DropdownInput'; import Icon from '../../utils/Icon'; import useOnboardingStore from '../../store/useOnboardingStore'; // Import the store to access onboarding data /** * Interface for a single dropdown option. */ interface DropdownOption { value: string; label: string; icon?: string; is_premium?: boolean; // Property to indicate if the option is premium. } /** * Props for the DropdownInput component. */ interface DropdownFieldProps { field: { id: string; label?: string; options: DropdownOption[]; is_lock?: boolean; tooltip?: any; [key: string]: any; }; value: string; onChange: (value: string) => void; } /** * DropdownInput component for selecting a single option from a list. * Supports displaying premium labels and disabling options for non-pro users. */ const DropdownInput = ({ field, value, onChange } :DropdownFieldProps) => { // Access onboarding data from the store to check if the user is a Pro user. const { onboardingData } = useOnboardingStore(); const isProUser = onboardingData.is_pro; // Compute selected option once and normalize icon to a string so Icon always receives a string. const selectedOption = field.options.find(opt => opt.value === value); const selectedIcon = selectedOption?.icon ?? ''; const selectedLabel = selectedOption?.label ?? ''; return ( ); }; export default memo(DropdownInput);