import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
import { useEffect, useMemo, } from 'react';
import { useTranslation } from 'react-i18next';
import { DEFAULT_FIXED_UPDATE_RATE } from 'dacha';
import { LabelledNumberInput } from '../../../components';
import { Field } from '../../../components/field';
import { useConfig, useCommander } from '../../../../../hooks';
import { addValue } from '../../../../../commands';
import { CollapsePanel } from '../../../components/collapse-panel';
import { PATH } from './consts';
export const PerformanceWidget = () => {
    const { t } = useTranslation();
    const { dispatch } = useCommander();
    const performanceOptions = useConfig(PATH);
    const maxFPSPath = useMemo(() => PATH.concat('maxFPS'), []);
    const fixedUpdateRatePath = useMemo(() => PATH.concat('fixedUpdateRate'), []);
    useEffect(() => {
        if (performanceOptions) {
            return;
        }
        dispatch(addValue(['globalOptions'], {
            name: 'performance',
            options: {
                maxFPS: 0,
                fixedUpdateRate: DEFAULT_FIXED_UPDATE_RATE,
            },
        }));
    }, [performanceOptions]);
    return (_jsxs(CollapsePanel, { title: t('globalOptions.performance.title'), deletable: false, children: [_jsx(Field, { path: maxFPSPath, component: LabelledNumberInput, label: t('globalOptions.performance.maxFPS.title') }), _jsx(Field, { path: fixedUpdateRatePath, component: LabelledNumberInput, label: t('globalOptions.performance.fixedUpdateRate.title') })] }));
};
