2025-01-28 23:23:42 +03:00
|
|
|
import { CProps } from '@/components/props';
|
2024-01-04 19:38:12 +03:00
|
|
|
import SelectMulti, { SelectMultiProps } from '@/components/ui/SelectMulti';
|
2023-12-13 14:32:57 +03:00
|
|
|
import { Grammeme } from '@/models/language';
|
|
|
|
import { getCompatibleGrams } from '@/models/languageAPI';
|
2023-12-28 14:04:44 +03:00
|
|
|
import { compareGrammemeOptions, IGrammemeOption, SelectorGrammemes } from '@/utils/selectors';
|
2023-12-08 19:24:08 +03:00
|
|
|
|
2024-05-27 20:42:34 +03:00
|
|
|
interface SelectMultiGrammemeProps
|
|
|
|
extends Omit<SelectMultiProps<IGrammemeOption>, 'value' | 'onChange'>,
|
|
|
|
CProps.Styling {
|
2023-12-28 14:04:44 +03:00
|
|
|
value: IGrammemeOption[];
|
2025-02-04 20:35:55 +03:00
|
|
|
onChange: (newValue: IGrammemeOption[]) => void;
|
2023-12-28 14:04:44 +03:00
|
|
|
placeholder?: string;
|
2023-12-08 19:24:08 +03:00
|
|
|
}
|
|
|
|
|
2025-02-04 20:35:55 +03:00
|
|
|
function SelectMultiGrammeme({ value, onChange, ...restProps }: SelectMultiGrammemeProps) {
|
2025-02-05 21:55:39 +03:00
|
|
|
const compatible = getCompatibleGrams(
|
|
|
|
value.filter(data => Object.values(Grammeme).includes(data.value as Grammeme)).map(data => data.value as Grammeme)
|
|
|
|
);
|
|
|
|
const options = SelectorGrammemes.filter(({ value }) => compatible.includes(value as Grammeme));
|
2023-12-08 19:24:08 +03:00
|
|
|
|
|
|
|
return (
|
2023-12-28 14:04:44 +03:00
|
|
|
<SelectMulti
|
|
|
|
options={options}
|
|
|
|
value={value}
|
2025-02-04 20:35:55 +03:00
|
|
|
onChange={newValue => onChange([...newValue].sort(compareGrammemeOptions))}
|
2023-12-28 14:04:44 +03:00
|
|
|
{...restProps}
|
|
|
|
/>
|
|
|
|
);
|
2023-12-08 19:24:08 +03:00
|
|
|
}
|
|
|
|
|
2024-05-27 20:42:34 +03:00
|
|
|
export default SelectMultiGrammeme;
|