"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
var _typeof = require("@babel/runtime/helpers/typeof");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.CardSSR = void 0;
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
var _react = _interopRequireWildcard(require("react"));
var _reactErrorBoundary = require("react-error-boundary");
var _uuid = _interopRequireDefault(require("uuid"));
var _analyticsNext = require("@atlaskit/analytics-next");
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
var _analytics = require("./utils/analytics/analytics");
var _component = require("./view/CardWithUrl/component");
var _LoadingCardLink = require("./view/CardWithUrl/component-lazy/LoadingCardLink");
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); }
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } // eslint-disable-next-line @atlaskit/platform/prefer-crypto-random-uuid -- Use crypto.randomUUID instead
// SSR friendly version of smart-card
// simplifies the logic around rendering and loading placeholders and
// only contains whats necessary to render the card on SSR mode
var CardSSR = exports.CardSSR = function CardSSR(props) {
  // eslint-disable-next-line @atlaskit/platform/prefer-crypto-random-uuid -- Use crypto.randomUUID instead
  var _useState = (0, _react.useState)(function () {
      var _props$id;
      return (_props$id = props.id) !== null && _props$id !== void 0 ? _props$id : (0, _uuid.default)();
    }),
    _useState2 = (0, _slicedToArray2.default)(_useState, 1),
    id = _useState2[0];
  var cardProps = _objectSpread(_objectSpread({}, props), {}, {
    id: id
  });
  var ErrorFallbackComponent = cardProps.fallbackComponent;
  var errorBoundaryFallbackComponent = function errorBoundaryFallbackComponent() {
    if (ErrorFallbackComponent) {
      return /*#__PURE__*/_react.default.createElement(ErrorFallbackComponent, null);
    }
    return /*#__PURE__*/_react.default.createElement(_LoadingCardLink.LoadingCardLink, cardProps);
  };
  if ((0, _platformFeatureFlags.fg)('platform_editor_inline_card_selected_state_fix')) {
    var Component = cardProps.appearance === 'inline' ? 'span' : 'div';
    return /*#__PURE__*/_react.default.createElement(_analyticsNext.AnalyticsContext, {
      data: _analytics.context
    }, /*#__PURE__*/_react.default.createElement(_reactErrorBoundary.ErrorBoundary, {
      FallbackComponent: errorBoundaryFallbackComponent
    }, /*#__PURE__*/_react.default.createElement(Component, {
      className: "loader-wrapper"
    }, /*#__PURE__*/_react.default.createElement(_component.CardWithUrlContent, cardProps))));
  }
  return /*#__PURE__*/_react.default.createElement(_analyticsNext.AnalyticsContext, {
    data: _analytics.context
  }, /*#__PURE__*/_react.default.createElement(_reactErrorBoundary.ErrorBoundary, {
    FallbackComponent: errorBoundaryFallbackComponent
  }, /*#__PURE__*/_react.default.createElement(_component.CardWithUrlContent, cardProps)));
};