import React, { ReactNode, useState } from 'react';
import { WidgetsFormContextProvider } from '@wix/bex-core/react';
import { PageWrapperBase } from '../PageWrapper';
import { WidgetsFormState } from '@wix/bex-core';

export function WidgetsFormProvider({
  children,
  state,
}: {
  children: ReactNode;
  state?: WidgetsFormState;
}) {
  const [widgetsFormState] = useState(() => state ?? new WidgetsFormState());

  return (
    <WidgetsFormContextProvider value={widgetsFormState}>
      <PageWrapperBase>{children}</PageWrapperBase>
    </WidgetsFormContextProvider>
  );
}
