import type { FC } from '../../lib/teact/teact'; import { memo, useMemo, useState, } from '../../lib/teact/teact'; import { getActions } from '../../global'; import type { ApiCountry } from '../../api/types'; import buildClassName from '../../util/buildClassName'; import useLastCallback from '../../hooks/useLastCallback'; import useOldLang from '../../hooks/useOldLang'; import usePreviousDeprecated from '../../hooks/usePreviousDeprecated'; import Button from '../ui/Button'; import Modal from '../ui/Modal'; import Icon from './icons/Icon'; import ItemPicker from './pickers/ItemPicker'; import styles from './CountryPickerModal.module.scss'; export type OwnProps = { isOpen: boolean; onClose: () => void; onSubmit: (value: string[]) => void; countryList: ApiCountry[]; selectionLimit?: number | undefined; }; const CountryPickerModal: FC = ({ isOpen, onClose, onSubmit, countryList, selectionLimit, }) => { const { showNotification } = getActions(); const lang = useOldLang(); const [selectedCountryIds, setSelectedCountryIds] = useState([]); const prevSelectedCountryIds = usePreviousDeprecated(selectedCountryIds); const noPickerScrollRestore = prevSelectedCountryIds === selectedCountryIds; const displayedIds = useMemo(() => { if (!countryList) { return []; } return countryList.filter((country) => !country.isHidden && country.iso2 !== 'FT') .map(({ iso2, defaultName, }) => ({ value: iso2, label: defaultName, })); }, [countryList]); const handleSelectedIdsChange = useLastCallback((newSelectedIds: string[]) => { if (selectionLimit && newSelectedIds.length > selectionLimit) { showNotification({ message: lang('BoostingSelectUpToWarningCountries', selectionLimit), }); return; } setSelectedCountryIds(newSelectedIds); }); const handleSubmit = useLastCallback(() => { onSubmit(selectedCountryIds); onClose(); }); return (

{lang('BoostingSelectCountry')}

); }; export default memo(CountryPickerModal);