/* index.tsx generated by @compiled/babel-plugin v0.39.1 */
"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
require("./index.compiled.css");
var _runtime = require("@compiled/react/runtime");
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
var _react = _interopRequireDefault(require("react"));
var _reactIntl = require("react-intl");
var _compiled = require("@atlaskit/primitives/compiled");
var _constants = require("../../../../../constants");
var _flexibleUiContext = require("../../../../../state/flexible-ui-context");
var _excluded = ["testId", "onlyShowIfAction", "Container"];
var styles = {
  button: "_1e0c1bgi",
  message: "_1rjcze3t _18zrze3t"
};
var validErrorStatuses = [_constants.SmartLinkStatus.Forbidden, _constants.SmartLinkStatus.Unauthorized];
var validateErrorStatus = function validateErrorStatus(status) {
  return status !== undefined && validErrorStatuses.includes(status);
};
var getMessageDescriptor = function getMessageDescriptor(status, accessType, props) {
  var _props$status;
  if (!validateErrorStatus(status)) {
    return undefined;
  }
  var message = props === null || props === void 0 || (_props$status = props[status]) === null || _props$status === void 0 ? void 0 : _props$status[accessType !== null && accessType !== void 0 ? accessType : 'FALLBACK'];
  return message;
};
var CustomUnresolvedAction = function CustomUnresolvedAction(_ref) {
  var _context$data, _context$data2, _getMessageDescriptor;
  var _ref$testId = _ref.testId,
    testId = _ref$testId === void 0 ? 'custom-unresolved-action' : _ref$testId,
    _ref$onlyShowIfAction = _ref.onlyShowIfAction,
    onlyShowIfAction = _ref$onlyShowIfAction === void 0 ? false : _ref$onlyShowIfAction,
    Container = _ref.Container,
    props = (0, _objectWithoutProperties2.default)(_ref, _excluded);
  var context = (0, _flexibleUiContext.useFlexibleCardContext)();
  var data = context === null || context === void 0 || (_context$data = context.data) === null || _context$data === void 0 || (_context$data = _context$data.actions) === null || _context$data === void 0 ? void 0 : _context$data[_constants.InternalActionName.UnresolvedAction];
  if (!data) {
    return null;
  }
  var descriptor = data.descriptor,
    onClick = data.onClick,
    values = data.values;
  var status = context.status;
  var accessType = context === null || context === void 0 || (_context$data2 = context.data) === null || _context$data2 === void 0 || (_context$data2 = _context$data2.meta) === null || _context$data2 === void 0 ? void 0 : _context$data2.accessType;
  var hasAction = onClick !== undefined;
  if (onlyShowIfAction && !hasAction) {
    return null;
  }
  var messageDescriptor = (_getMessageDescriptor = getMessageDescriptor(status, accessType, props)) !== null && _getMessageDescriptor !== void 0 ? _getMessageDescriptor : descriptor;
  if (!messageDescriptor) {
    return null;
  }
  var message = /*#__PURE__*/_react.default.createElement(_compiled.Box, {
    testId: "".concat(testId, "-errored-view-message"),
    tabIndex: hasAction ? 0 : undefined,
    xcss: styles.message
  }, /*#__PURE__*/_react.default.createElement(_reactIntl.FormattedMessage, (0, _extends2.default)({}, messageDescriptor, {
    values: values
  })));
  var component = hasAction ? /*#__PURE__*/_react.default.createElement(_compiled.Pressable, {
    onClick: data.onClick,
    style: {
      color: "inherit",
      font: "inherit",
      textAlign: "inherit"
    },
    xcss: styles.button
  }, message) : message;
  return Container ? /*#__PURE__*/_react.default.createElement(Container, null, component) : component;
};
var _default = exports.default = CustomUnresolvedAction;