2025-01-28 23:23:03 +03:00
|
|
|
import { CProps } from '@/components/props';
|
2024-06-07 20:17:03 +03:00
|
|
|
import SelectMulti, { SelectMultiProps } from '@/components/ui/SelectMulti';
|
|
|
|
import { Grammeme } from '@/models/language';
|
|
|
|
import { getCompatibleGrams } from '@/models/languageAPI';
|
|
|
|
import { compareGrammemeOptions, IGrammemeOption, SelectorGrammemes } from '@/utils/selectors';
|
|
|
|
|
|
|
|
interface SelectMultiGrammemeProps
|
|
|
|
extends Omit<SelectMultiProps<IGrammemeOption>, 'value' | 'onChange'>,
|
|
|
|
CProps.Styling {
|
|
|
|
value: IGrammemeOption[];
|
2025-02-04 20:35:18 +03:00
|
|
|
onChange: (newValue: IGrammemeOption[]) => void;
|
2024-06-07 20:17:03 +03:00
|
|
|
placeholder?: string;
|
|
|
|
}
|
|
|
|
|
2025-02-04 20:35:18 +03:00
|
|
|
function SelectMultiGrammeme({ value, onChange, ...restProps }: SelectMultiGrammemeProps) {
|
2025-02-05 21:55:26 +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));
|
2024-06-07 20:17:03 +03:00
|
|
|
|
|
|
|
return (
|
|
|
|
<SelectMulti
|
|
|
|
options={options}
|
|
|
|
value={value}
|
2025-02-04 20:35:18 +03:00
|
|
|
onChange={newValue => onChange([...newValue].sort(compareGrammemeOptions))}
|
2024-06-07 20:17:03 +03:00
|
|
|
{...restProps}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export default SelectMultiGrammeme;
|