2025-02-20 20:22:05 +03:00
|
|
|
import { SelectMulti, type SelectMultiProps } from '@/components/Input';
|
|
|
|
import { type Styling } from '@/components/props';
|
2025-02-10 01:32:16 +03:00
|
|
|
|
2025-02-20 20:22:05 +03:00
|
|
|
import { Grammeme, type IGrammemeOption } from '../models/language';
|
2025-02-10 01:32:16 +03:00
|
|
|
import { getCompatibleGrams, grammemeCompare, supportedGrammeOptions } from '../models/languageAPI';
|
2024-06-07 20:17:03 +03:00
|
|
|
|
2025-02-20 20:22:05 +03:00
|
|
|
interface SelectMultiGrammemeProps extends Omit<SelectMultiProps<IGrammemeOption>, 'value' | 'onChange'>, Styling {
|
2024-06-07 20:17:03 +03:00
|
|
|
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-15 16:42:33 +03:00
|
|
|
export 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)
|
|
|
|
);
|
2025-02-10 01:32:16 +03:00
|
|
|
const options = supportedGrammeOptions.filter(({ value }) => compatible.includes(value as Grammeme));
|
2024-06-07 20:17:03 +03:00
|
|
|
|
|
|
|
return (
|
|
|
|
<SelectMulti
|
|
|
|
options={options}
|
|
|
|
value={value}
|
2025-02-10 01:32:16 +03:00
|
|
|
onChange={newValue => onChange([...newValue].sort((left, right) => grammemeCompare(left.value, right.value)))}
|
2024-06-07 20:17:03 +03:00
|
|
|
{...restProps}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|