import React from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { i18n } from 'vj/utils';
import FileSelectAutoComplete from '../autocomplete/components/FileSelectAutoComplete';
import LanguageSelectAutoComplete from '../autocomplete/components/LanguageSelectAutoComplete';
import type { RootState } from './reducer/index';
export function FormItem({
columns, label, children, helpText = '', disableLabel = false, ...props
}) {
return (
);
}
type KeyType = {
[Q in keyof K]: K[Q] extends T ? Q : never;
}[keyof K];
type FileSelectKey = 'checker' | 'interactor' | 'manager';
export function ManagedInput({ placeholder, formKey }: { placeholder?: string, formKey: KeyType }) {
const value = useSelector((state: RootState) => state.config[formKey]);
const dispatch = useDispatch();
return (
{
dispatch({ type: 'CONFIG_FORM_UPDATE', key: formKey, value: ev.currentTarget.value });
}}
className="textbox"
/>
);
}
export function ManagedSelect({ options, formKey }: { options: string[], formKey: KeyType }) {
const value = useSelector((state: RootState) => state.config[formKey]);
const dispatch = useDispatch();
return (
);
}
export function SingleFileSelect({ formKey, withLang = false, label = 'Checker' }: { formKey: FileSelectKey, withLang?: boolean, label?: string }) {
const value = useSelector((state: RootState) => state.config[formKey]);
const Files = useSelector((state: RootState) => state.testdata);
const dispatch = useDispatch();
const selectedFile = typeof value === 'string' ? value : value?.file || '';
const selectedLang = typeof value === 'string' ? 'auto' : value?.lang || 'auto';
const update = (file: string, lang: string) => {
if (file === selectedFile && lang === selectedLang) return;
if (withLang) dispatch({ type: 'CONFIG_FORM_UPDATE', key: formKey, value: file ? { file, lang } : null });
else dispatch({ type: 'CONFIG_FORM_UPDATE', key: formKey, value: file });
};
return withLang ? (<>
update(val, selectedLang)}
/>
update(selectedFile, val)}
withAuto
/>
>) : ( update(val, selectedLang)}
/>);
}