/* ResolvedView.tsx generated by @compiled/babel-plugin v0.38.1 */
import _extends from "@babel/runtime/helpers/extends";
import "./ResolvedView.compiled.css";
import * as React from 'react';
import { ax, ix } from "@compiled/react/runtime";
import { useEffect, useMemo, useState } from 'react';
import { browser } from '@atlaskit/linking-common/user-agent';
import { ActionName, ElementName, SmartLinkPosition } from '../../../constants';
import FlexibleCard from '../../FlexibleCard';
import { FooterBlock, MetadataBlock, PreviewBlock, SnippetBlock, TitleBlock } from '../../FlexibleCard/components/blocks';
import { FlexibleCardUiOptions, getSimulatedBetterMetadata, PreviewBlockOptions, titleBlockOptions } from './utils';
import { withFlexibleUIBlockCardStyle } from './utils/withFlexibleUIBlockCardStyle';
const titleBlockCss = null;
const footerBlockCss = null;
const footerBlockSafariStyles = null;

/**
 * This view represents a Block card that has an 'Resolved' status.
 * @see SmartLinkStatus
 * @see FlexibleCardProps
 */
const ResolvedView = ({
  cardState,
  onClick,
  onError,
  onResolve,
  actionOptions,
  testId = 'smart-block-resolved-view',
  url,
  CompetitorPrompt,
  hideIconLoadingSkeleton
}) => {
  const [isPreviewBlockErrored, setIsPreviewBlockErrored] = useState(false);

  // eslint-disable-next-line react-hooks/rules-of-hooks
  const {
    safari = false
  } = useMemo(() => browser(), []);
  useEffect(() => {
    setIsPreviewBlockErrored(false);
  }, [url, cardState]);
  const {
    titleMetadata,
    topMetadata,
    bottomMetadata
  } = getSimulatedBetterMetadata(cardState.details);
  const footerActions = useMemo(() => [{
    name: ActionName.FollowAction,
    hideIcon: true
  }, {
    name: ActionName.PreviewAction,
    hideIcon: true
  }, {
    name: ActionName.DownloadAction,
    hideIcon: true
  }], []);
  const uiOptions = FlexibleCardUiOptions;
  uiOptions.enableSnippetRenderer = true;
  uiOptions.hideLoadingSkeleton = hideIconLoadingSkeleton;
  return /*#__PURE__*/React.createElement(FlexibleCard, {
    appearance: "block",
    cardState: cardState,
    onClick: onClick,
    onError: onError,
    onResolve: onResolve,
    origin: "smartLinkCard",
    actionOptions: actionOptions,
    testId: testId,
    ui: uiOptions,
    url: url
  }, /*#__PURE__*/React.createElement(TitleBlock, _extends({}, titleBlockOptions, {
    metadata: titleMetadata,
    subtitle: [{
      name: ElementName.Location
    }],
    metadataPosition: SmartLinkPosition.Top,
    CompetitorPrompt: CompetitorPrompt,
    url: url,
    hideIconLoadingSkeleton: hideIconLoadingSkeleton,
    className: ax(["_zulpu2gc _13mh1pd9 _2yhz13af"])
  })), /*#__PURE__*/React.createElement(MetadataBlock, {
    primary: topMetadata,
    maxLines: 1
  }), /*#__PURE__*/React.createElement(SnippetBlock, null), /*#__PURE__*/React.createElement(MetadataBlock, {
    primary: bottomMetadata,
    maxLines: 1
  }), !isPreviewBlockErrored ? /*#__PURE__*/React.createElement(PreviewBlock, _extends({}, PreviewBlockOptions, {
    onError: () => {
      setIsPreviewBlockErrored(true);
    }
  })) : null, /*#__PURE__*/React.createElement(FooterBlock, {
    actions: footerActions,
    className: ax(["_4t3i1k8s _1e0c1txw _1bah1yb4 _4cvresu3 _1wpz1fhb", safari && "_4t3i1osq"])
  }));
};
export default withFlexibleUIBlockCardStyle(ResolvedView);