import * as React from 'react'; import { RegisteredLoadingIndicator, RegisteredErrorInfo, useGlobalStateContext } from 'piral-core'; import { useForm } from './useForm'; import { usePromise } from './usePromise'; import type { InputFormOptions, FormProps } from './types'; export function withFormHandler( Component: React.ComponentType>, options: InputFormOptions, ): React.FC { const FormView: React.FC = (props) => { const { navigation } = useGlobalStateContext(); const formProps = useForm(props.initialData, navigation, options); return ; }; const FormLoader: React.FC = (props) => { const { loadData, emptyData } = options; const { loading, data, error } = usePromise(() => typeof loadData !== 'function' ? Promise.resolve(emptyData) : loadData(props), ); if (loading) { return ; } else if (data) { return ; } else { return ; } }; FormLoader.displayName = `withFormHandler(${Component.displayName ?? 'Component'})`; return FormLoader; }