import { FormApi, functionalUpdate } from '@tanstack/form-core';
import { createComputed, onMount } from 'solid-js';
import { useStore } from '@tanstack/solid-store';
import { Field } from './createField';
import { FormGroup } from './createFormGroup';
export function createForm(opts) {
    const options = opts?.();
    const api = new FormApi(options);
    const extendedApi = api;
    extendedApi.Field = (props) => <Field {...props} form={api}/>;
    extendedApi.FormGroup = (props) => <FormGroup {...props} form={api}/>;
    extendedApi.useStore = (selector) => useStore(api.store, selector);
    extendedApi.Subscribe = (props) => functionalUpdate(props.children, useStore(api.store, props.selector));
    onMount(api.mount);
    /**
     * formApi.update should not have any side effects. Think of it like a `useRef`
     * that we need to keep updated every render with the most up-to-date information.
     */
    createComputed(() => api.update(opts?.()));
    return extendedApi;
}
//# sourceMappingURL=createForm.jsx.map