import { jsx as _jsx } from "react/jsx-runtime";
import { Flex } from '@citric/core';
import { LoadingCircular } from '@citric/ui';
import { JinjaRawContext } from '../context/JinjaContext.js';
import { useAscendInputsEffect, useComputedInputsEffect, useJinjaFormsInit } from './hooks.js';
export const JinjaForm = ({ model, children, onSubmit, onReset, ...props }) => {
    const status = useJinjaFormsInit();
    useComputedInputsEffect(Object.values(model.context.computedVariables), model.context);
    useAscendInputsEffect(model.context);
    if (status === 'pending') {
        return (_jsx(Flex, { alignItems: "center", justifyContent: "center", style: { padding: '20px' }, children: _jsx(LoadingCircular, {}) }));
    }
    if (status === 'error') {
        throw new Error('There was an error while loading Python environment.');
    }
    return (_jsx(JinjaRawContext, { value: model.context, children: _jsx("form", { onSubmit: (e) => {
                e.preventDefault();
                onSubmit?.(e);
                model.submit();
            }, onReset: (e) => {
                e.preventDefault();
                onReset?.(e);
                model.reset();
            }, ...props, children: children }) }));
};
//# sourceMappingURL=JinjaForm.js.map