import { AdminContext, AdminContextProps } from './AdminContext';
import { AdminUI, AdminUIProps, localStorageStore } from 'react-admin';

type AdminProps = AdminContextProps & AdminUIProps;

function Admin(props: AdminProps): JSX.Element {
  const {
    authProvider,
    catchAll,
    children,
    dashboard,
    dataProvider,
    disableTelemetry,
    history,
    i18nProvider,
    layout,
    loading,
    loginPage,
    authCallbackPage,
    menu, // deprecated, use a custom layout instead
    notification,
    queryClient,
    requireAuth,
    store = localStorageStore(),
    ready,
    theme,
    title = 'React Admin'
  } = props;
  return (
    <AdminContext
      authProvider={authProvider}
      dataProvider={dataProvider}
      i18nProvider={i18nProvider}
      store={store}
      history={history}
      queryClient={queryClient}
      theme={theme}
    >
      <AdminUI
        layout={layout}
        dashboard={dashboard}
        disableTelemetry={disableTelemetry}
        menu={menu}
        catchAll={catchAll}
        title={title}
        loading={loading}
        loginPage={loginPage}
        authCallbackPage={authCallbackPage}
        notification={notification}
        requireAuth={requireAuth}
        ready={ready}
      >
        {children}
      </AdminUI>
    </AdminContext>
  );
}

export { Admin };
export type { AdminProps };
