/* index.tsx generated by @compiled/babel-plugin v0.39.1 */
import _extends from "@babel/runtime/helpers/extends";
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
var _excluded = ["testId", "onlyShowIfAction", "Container"];
import "./index.compiled.css";
import { ax, ix } from "@compiled/react/runtime";
import React from 'react';
import { FormattedMessage } from 'react-intl';
import { Box, Pressable } from '@atlaskit/primitives/compiled';
import { InternalActionName, SmartLinkStatus } from '../../../../../constants';
import { useFlexibleCardContext } from '../../../../../state/flexible-ui-context';
var styles = {
  button: "_1e0c1bgi",
  message: "_1rjcze3t _18zrze3t"
};
var validErrorStatuses = [SmartLinkStatus.Forbidden, 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;
};

/**
 * Public API — exported externally. Do not add props without external support intent.
 */
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 = _objectWithoutProperties(_ref, _excluded);
  var context = 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[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.createElement(Box, {
    testId: "".concat(testId, "-errored-view-message"),
    tabIndex: hasAction ? 0 : undefined,
    xcss: styles.message
  }, /*#__PURE__*/React.createElement(FormattedMessage, _extends({}, messageDescriptor, {
    values: values
  })));
  var component = hasAction ? /*#__PURE__*/React.createElement(Pressable, {
    onClick: data.onClick,
    style: {
      color: "inherit",
      font: "inherit",
      textAlign: "inherit"
    },
    xcss: styles.button
  }, message) : message;
  return Container ? /*#__PURE__*/React.createElement(Container, null, component) : component;
};
export default CustomUnresolvedAction;