/* ForbiddenView.tsx generated by @compiled/babel-plugin v0.39.1 */
import _extends from "@babel/runtime/helpers/extends";
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
var _excluded = ["testId"];
import "./ForbiddenView.compiled.css";
import * as React from 'react';
import { ax, ix } from "@compiled/react/runtime";
import { useMemo } from 'react';
import { useIntl } from 'react-intl';
import { useAnalyticsEvents } from '@atlaskit/analytics-next';
import LockLockedIcon from '@atlaskit/icon/core/lock-locked';
import { extractSmartLinkProvider } from '@atlaskit/link-extractors';
import { extractRequestAccessContextImproved } from '../../../extractors/common/context/extractAccessContext';
import extractHostname from '../../../extractors/common/hostname/extractHostname';
import { messages } from '../../../messages';
import { toMessage } from '../../../utils/intl-utils';
import { getForbiddenJsonLd } from '../../../utils/jsonld';
import Text from '../../FlexibleCard/components/elements/common/base-text-element';
import { ForbiddenAction } from '../actions/ForbiddenAction';
import UnresolvedView from './unresolved-view';
import { withFlexibleUIBlockCardStyle } from './utils/withFlexibleUIBlockCardStyle';
var textStyles = null;

/**
 * This view represent a Block Card with the 'Forbidden' status.
 * It should have a "Try another account" button that will allow a user to connect another account and view the block card.
 *
 * @see SmartLinkStatus
 * @see FlexibleCardProps
 */
var ForbiddenView = function ForbiddenView(_ref) {
  var _details$meta;
  var _ref$testId = _ref.testId,
    testId = _ref$testId === void 0 ? 'smart-block-forbidden-view' : _ref$testId,
    props = _objectWithoutProperties(_ref, _excluded);
  var _useAnalyticsEvents = useAnalyticsEvents(),
    createAnalyticsEvent = _useAnalyticsEvents.createAnalyticsEvent;
  var intl = useIntl();
  var cardState = props.cardState,
    onAuthorize = props.onAuthorize,
    url = props.url;
  var details = cardState === null || cardState === void 0 ? void 0 : cardState.details;
  var cardMetadata = (_details$meta = details === null || details === void 0 ? void 0 : details.meta) !== null && _details$meta !== void 0 ? _details$meta : getForbiddenJsonLd().meta;
  var provider = extractSmartLinkProvider(details);
  var providerName = (provider === null || provider === void 0 ? void 0 : provider.text) || '';
  var messageContext = useMemo(function () {
    var hostname = /*#__PURE__*/React.createElement("b", null, extractHostname(url));
    return {
      product: providerName,
      hostname: hostname
    };
  }, [providerName, url]);
  var requestAccessContext = useMemo(function () {
    return extractRequestAccessContextImproved({
      jsonLd: cardMetadata,
      url: url,
      product: providerName,
      createAnalyticsEvent: createAnalyticsEvent
    });
  }, [cardMetadata, providerName, url, createAnalyticsEvent]);
  var title = useMemo(function () {
    var descriptor = toMessage(messages.invalid_permissions, requestAccessContext === null || requestAccessContext === void 0 ? void 0 : requestAccessContext.titleMessageKey);
    return intl.formatMessage(descriptor, {
      product: providerName
    });
  }, [intl, providerName, requestAccessContext === null || requestAccessContext === void 0 ? void 0 : requestAccessContext.titleMessageKey]);
  var actions = useMemo(function () {
    var actionFromAccessContext = [];
    var tryAnotherAccountAction = onAuthorize ? [ForbiddenAction(onAuthorize, 'try_another_account')] : [];
    if (requestAccessContext) {
      var action = requestAccessContext.action,
        callToActionMessageKey = requestAccessContext.callToActionMessageKey;
      actionFromAccessContext = action && callToActionMessageKey ? [ForbiddenAction(action.promise, callToActionMessageKey, messageContext, requestAccessContext === null || requestAccessContext === void 0 ? void 0 : requestAccessContext.buttonDisabled)] : [];
    }
    return [].concat(tryAnotherAccountAction, _toConsumableArray(actionFromAccessContext));
  }, [onAuthorize, requestAccessContext, messageContext]);
  return /*#__PURE__*/React.createElement(UnresolvedView, _extends({}, props, {
    actions: actions,
    showPreview: true,
    testId: testId,
    title: title
  }), /*#__PURE__*/React.createElement(LockLockedIcon, {
    label: "forbidden-lock-icon",
    color: "var(--ds-icon-danger, #C9372C)",
    testId: "".concat(testId, "-lock-icon")
  }), /*#__PURE__*/React.createElement(Text, {
    maxLines: 3,
    message: {
      descriptor: toMessage(messages.invalid_permissions_description, requestAccessContext === null || requestAccessContext === void 0 ? void 0 : requestAccessContext.descriptiveMessageKey),
      values: messageContext
    },
    className: ax(["_syazi7uo"])
  }));
};
var _default_1 = withFlexibleUIBlockCardStyle(ForbiddenView);
export default _default_1;