/* ForbiddenView.tsx generated by @compiled/babel-plugin v0.38.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("./ForbiddenView.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 _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
var _reactIntlNext = require("react-intl-next");
var _analyticsNext = require("@atlaskit/analytics-next");
var _lockLocked = _interopRequireDefault(require("@atlaskit/icon/core/lock-locked"));
var _linkExtractors = require("@atlaskit/link-extractors");
var _extractAccessContext = require("../../../extractors/common/context/extractAccessContext");
var _extractHostname = _interopRequireDefault(require("../../../extractors/common/hostname/extractHostname"));
var _messages = require("../../../messages");
var _intlUtils = require("../../../utils/intl-utils");
var _jsonld = require("../../../utils/jsonld");
var _baseTextElement = _interopRequireDefault(require("../../FlexibleCard/components/elements/common/base-text-element"));
var _ForbiddenAction = require("../actions/ForbiddenAction");
var _unresolvedView = _interopRequireDefault(require("./unresolved-view"));
var _withFlexibleUIBlockCardStyle = require("./utils/withFlexibleUIBlockCardStyle");
var _excluded = ["testId"];
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 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 = (0, _objectWithoutProperties2.default)(_ref, _excluded);
  var _useAnalyticsEvents = (0, _analyticsNext.useAnalyticsEvents)(),
    createAnalyticsEvent = _useAnalyticsEvents.createAnalyticsEvent;
  var intl = (0, _reactIntlNext.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 : (0, _jsonld.getForbiddenJsonLd)().meta;
  var provider = (0, _linkExtractors.extractSmartLinkProvider)(details);
  var providerName = (provider === null || provider === void 0 ? void 0 : provider.text) || '';
  var messageContext = (0, _react.useMemo)(function () {
    var hostname = /*#__PURE__*/React.createElement("b", null, (0, _extractHostname.default)(url));
    return {
      product: providerName,
      hostname: hostname
    };
  }, [providerName, url]);
  var requestAccessContext = (0, _react.useMemo)(function () {
    return (0, _extractAccessContext.extractRequestAccessContextImproved)({
      jsonLd: cardMetadata,
      url: url,
      product: providerName,
      createAnalyticsEvent: createAnalyticsEvent
    });
  }, [cardMetadata, providerName, url, createAnalyticsEvent]);
  var title = (0, _react.useMemo)(function () {
    var descriptor = (0, _intlUtils.toMessage)(_messages.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 = (0, _react.useMemo)(function () {
    var actionFromAccessContext = [];
    var tryAnotherAccountAction = onAuthorize ? [(0, _ForbiddenAction.ForbiddenAction)(onAuthorize, 'try_another_account')] : [];
    if (requestAccessContext) {
      var action = requestAccessContext.action,
        callToActionMessageKey = requestAccessContext.callToActionMessageKey;
      actionFromAccessContext = action && callToActionMessageKey ? [(0, _ForbiddenAction.ForbiddenAction)(action.promise, callToActionMessageKey, messageContext, requestAccessContext === null || requestAccessContext === void 0 ? void 0 : requestAccessContext.buttonDisabled)] : [];
    }
    return [].concat(tryAnotherAccountAction, (0, _toConsumableArray2.default)(actionFromAccessContext));
  }, [onAuthorize, requestAccessContext, messageContext]);
  return /*#__PURE__*/React.createElement(_unresolvedView.default, (0, _extends2.default)({}, props, {
    actions: actions,
    showPreview: true,
    testId: testId,
    title: title
  }), /*#__PURE__*/React.createElement(_lockLocked.default, {
    label: "forbidden-lock-icon",
    color: "var(--ds-icon-danger, #C9372C)",
    testId: "".concat(testId, "-lock-icon")
  }), /*#__PURE__*/React.createElement(_baseTextElement.default, {
    maxLines: 3,
    message: {
      descriptor: (0, _intlUtils.toMessage)(_messages.messages.invalid_permissions_description, requestAccessContext === null || requestAccessContext === void 0 ? void 0 : requestAccessContext.descriptiveMessageKey),
      values: messageContext
    },
    className: (0, _runtime.ax)(["_syazi7uo"])
  }));
};
var _default = exports.default = (0, _withFlexibleUIBlockCardStyle.withFlexibleUIBlockCardStyle)(ForbiddenView);