import _defineProperty from "@babel/runtime/helpers/defineProperty";
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
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) { _defineProperty(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; }
import React, { useState } from 'react';
import { ErrorBoundary } from 'react-error-boundary';
// eslint-disable-next-line @atlaskit/platform/prefer-crypto-random-uuid -- Use crypto.randomUUID instead
import uuid from 'uuid';
import { AnalyticsContext } from '@atlaskit/analytics-next';
import { context } from './utils/analytics/analytics';
import { CardWithUrlContent } from './view/CardWithUrl/component';
import { LoadingCardLink } from './view/CardWithUrl/component-lazy/LoadingCardLink';
// 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
export var CardSSR = function CardSSR(props) {
  // eslint-disable-next-line @atlaskit/platform/prefer-crypto-random-uuid -- Use crypto.randomUUID instead
  var _useState = useState(function () {
      var _props$id;
      return (_props$id = props.id) !== null && _props$id !== void 0 ? _props$id : uuid();
    }),
    _useState2 = _slicedToArray(_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.createElement(ErrorFallbackComponent, null);
    }
    return /*#__PURE__*/React.createElement(LoadingCardLink, cardProps);
  };
  var Component = cardProps.appearance === 'inline' ? 'span' : 'div';
  return /*#__PURE__*/React.createElement(AnalyticsContext, {
    data: context
  }, /*#__PURE__*/React.createElement(ErrorBoundary, {
    FallbackComponent: errorBoundaryFallbackComponent
  }, /*#__PURE__*/React.createElement(Component, {
    className: "loader-wrapper"
  }, /*#__PURE__*/React.createElement(CardWithUrlContent, cardProps))));
};