import _extends from "@babel/runtime/helpers/extends";
import React from 'react';
import UFOHoldLoad from '@atlaskit/react-ufo/load-hold';
import { useControlDataExportConfig } from '../../state/hooks/use-control-data-export-config';
import { getIsDataExportEnabled } from '../../utils/should-data-export';
import { handleClickCommon } from '../common/utils';
import { CardLinkView } from '../LinkView';
import ErroredView from './views/ErroredView';
import ForbiddenView from './views/ForbiddenView';
import NotFoundView from './views/NotFoundView';
import ResolvedView from './views/ResolvedView';
import UnauthorisedView from './views/UnauthorisedView';
const UFOLoadHoldWrapper = ({
  children
}) => /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(UFOHoldLoad, {
  name: "smart-card-block-card"
}), children);
export const BlockCard = ({
  id,
  url,
  cardState,
  authFlow,
  handleAuthorize,
  handleFrameClick,
  renderers,
  isSelected,
  onResolve,
  onError,
  testId,
  actionOptions,
  CompetitorPrompt,
  hideIconLoadingSkeleton
}) => {
  const {
    status
  } = cardState;
  const blockCardProps = {
    id,
    cardState,
    url,
    testId,
    onClick: event => handleClickCommon(event, handleFrameClick),
    onError,
    onResolve,
    renderers,
    actionOptions,
    CompetitorPrompt,
    hideIconLoadingSkeleton
  };
  const {
    shouldControlDataExport = false
  } = useControlDataExportConfig();
  switch (status) {
    case 'pending':
    case 'resolving':
      return /*#__PURE__*/React.createElement(UFOLoadHoldWrapper, null, /*#__PURE__*/React.createElement(ResolvedView, _extends({}, blockCardProps, {
        testId: "smart-block-resolving-view"
      })));
    case 'resolved':
      if (getIsDataExportEnabled(shouldControlDataExport, cardState.details)) {
        return /*#__PURE__*/React.createElement(UnauthorisedView, _extends({}, blockCardProps, {
          onAuthorize: handleAuthorize
        }));
      }
      return /*#__PURE__*/React.createElement(ResolvedView, blockCardProps);
    case 'unauthorized':
      return /*#__PURE__*/React.createElement(UnauthorisedView, _extends({}, blockCardProps, {
        onAuthorize: handleAuthorize
      }));
    case 'forbidden':
      return /*#__PURE__*/React.createElement(ForbiddenView, _extends({}, blockCardProps, {
        onAuthorize: handleAuthorize
      }));
    case 'not_found':
      return /*#__PURE__*/React.createElement(NotFoundView, _extends({}, blockCardProps, {
        onAuthorize: handleAuthorize
      }));
    case 'fallback':
    case 'errored':
    default:
      if (onError) {
        onError({
          url,
          status
        });
      }
      if (authFlow && authFlow === 'disabled') {
        return /*#__PURE__*/React.createElement(CardLinkView, {
          link: url,
          isSelected: isSelected,
          onClick: handleFrameClick,
          testId: `${testId}-${status}`
        });
      }
      return /*#__PURE__*/React.createElement(ErroredView, _extends({}, blockCardProps, {
        onAuthorize: handleAuthorize
      }));
  }
};