/* ResolvedView.tsx generated by @compiled/babel-plugin v0.39.1 */
"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
var _typeof = require("@babel/runtime/helpers/typeof");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
require("./ResolvedView.compiled.css");
var _react = _interopRequireWildcard(require("react"));
var React = _react;
var _runtime = require("@compiled/react/runtime");
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
var _userAgent = require("@atlaskit/linking-common/user-agent");
var _constants = require("../../../constants");
var _FlexibleCard = _interopRequireDefault(require("../../FlexibleCard"));
var _blocks = require("../../FlexibleCard/components/blocks");
var _utils = require("./utils");
var _withFlexibleUIBlockCardStyle = require("./utils/withFlexibleUIBlockCardStyle");
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
var titleBlockCss = null;
var footerBlockCss = null;
var footerBlockSafariStyles = null;

/**
 * This view represents a Block card that has an 'Resolved' status.
 * @see SmartLinkStatus
 * @see FlexibleCardProps
 */
var ResolvedView = function ResolvedView(_ref) {
  var cardState = _ref.cardState,
    onClick = _ref.onClick,
    onError = _ref.onError,
    onResolve = _ref.onResolve,
    actionOptions = _ref.actionOptions,
    _ref$testId = _ref.testId,
    testId = _ref$testId === void 0 ? 'smart-block-resolved-view' : _ref$testId,
    url = _ref.url,
    CompetitorPrompt = _ref.CompetitorPrompt,
    hideIconLoadingSkeleton = _ref.hideIconLoadingSkeleton;
  var _useState = (0, _react.useState)(false),
    _useState2 = (0, _slicedToArray2.default)(_useState, 2),
    isPreviewBlockErrored = _useState2[0],
    setIsPreviewBlockErrored = _useState2[1];

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