import { useContext, useMemo } from 'react';
import { CardContainerProps } from './CardContainer';
import { entityPageContext } from '../providers';

export function useWidgetPageStatus(
  widgetStatus: CardContainerProps['status'],
) {
  const pageState = useContext(entityPageContext);
  const pageStatus = pageState?.initTask.status.status;

  const status = useMemo(
    () => (!pageState || pageStatus === 'success' ? widgetStatus : pageStatus),
    [pageStatus, widgetStatus],
  );

  return { status };
}
