import React, { useState } from 'react';

// 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 { fg } from '@atlaskit/platform-feature-flags';
import { context } from './utils/analytics/analytics';
import { isFlexibleUiCard } from './utils/flexible';
import CardErrorBoundary from './view/CardWithUrl/card-error-boundary';
import { CardWithUrl } from './view/CardWithUrl/component';
// 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 const CardSSR = props => {
  // eslint-disable-next-line @atlaskit/platform/prefer-crypto-random-uuid -- Use crypto.randomUUID instead
  const [id] = useState(() => {
    var _props$id;
    return (_props$id = props.id) !== null && _props$id !== void 0 ? _props$id : uuid();
  });
  // FlexibleCards always need full ORS data regardless of appearance prop,
  // because they render custom blocks (TitleBlock etc.) requiring a complete response.
  // Override appearance to 'block' for FlexibleCards when FG is enabled.
  const effectiveAppearance = isFlexibleUiCard(props.children, props.ui) && fg('platform_smartlink_inline_resolve_optimization') ? 'block' : props.appearance;
  const propsWithId = {
    ...props,
    id,
    appearance: effectiveAppearance
  };
  return /*#__PURE__*/React.createElement(AnalyticsContext, {
    data: context
  }, /*#__PURE__*/React.createElement(CardErrorBoundary, propsWithId, /*#__PURE__*/React.createElement(CardWithUrl, propsWithId)));
};