/* index.tsx generated by @compiled/babel-plugin v0.40.0 */
"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("./index.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 _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
var _constants = require("../../../../../constants");
var _useLinkClicked = require("../../../../../state/analytics/useLinkClicked");
var _flexibleUiContext = require("../../../../../state/flexible-ui-context");
var _elements = require("../../elements");
var _actionGroup = _interopRequireDefault(require("../action-group"));
var _errored = _interopRequireDefault(require("./errored"));
var _resolved = _interopRequireDefault(require("./resolved"));
var _resolving = _interopRequireDefault(require("./resolving"));
var _excluded = ["actions", "anchorTarget", "hideTitleTooltip", "maxLines", "onActionMenuOpenChange", "showActionOnHover", "testId", "text", "icon", "hideRetry", "metadataPosition", "hideIcon", "className", "anchorRef", "CompetitorPrompt", "url", "hideIconLoadingSkeleton"];
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 actionStyles = null;
var getTitleBlockViewComponent = function getTitleBlockViewComponent(status) {
  switch (status) {
    case _constants.SmartLinkStatus.Pending:
    case _constants.SmartLinkStatus.Resolving:
      return _resolving.default;
    case _constants.SmartLinkStatus.Resolved:
      return _resolved.default;
    case _constants.SmartLinkStatus.Unauthorized:
    case _constants.SmartLinkStatus.Forbidden:
    case _constants.SmartLinkStatus.NotFound:
    case _constants.SmartLinkStatus.Errored:
    case _constants.SmartLinkStatus.Fallback:
    default:
      return _errored.default;
  }
};

/**
 * Represents a TitleBlock, which is the foundation of Flexible UI.
 * This contains an icon, the link, and any associated metadata and actions in one block.
 * The TitleBlock will also render differently given the state of the smart link.
 * This can be found in the corresponding Resolving, Resolved and Errored views.
 * @public
 * @param {TitleBlockProps} TitleBlockProps
 * @see Block
 * @see TitleBlockResolvingViewNew
 * @see TitleBlockResolvedViewNew
 * @see TitleBlockErroredViewNew
 */
var TitleBlock = function TitleBlock(_ref) {
  var _props$size;
  var _ref$actions = _ref.actions,
    actions = _ref$actions === void 0 ? [] : _ref$actions,
    anchorTarget = _ref.anchorTarget,
    hideTitleTooltip = _ref.hideTitleTooltip,
    maxLines = _ref.maxLines,
    onActionMenuOpenChange = _ref.onActionMenuOpenChange,
    showActionOnHover = _ref.showActionOnHover,
    _ref$testId = _ref.testId,
    testId = _ref$testId === void 0 ? 'smart-block-title' : _ref$testId,
    text = _ref.text,
    icon = _ref.icon,
    hideRetry = _ref.hideRetry,
    metadataPosition = _ref.metadataPosition,
    _ref$hideIcon = _ref.hideIcon,
    hideIcon = _ref$hideIcon === void 0 ? false : _ref$hideIcon,
    className = _ref.className,
    anchorRef = _ref.anchorRef,
    CompetitorPrompt = _ref.CompetitorPrompt,
    url = _ref.url,
    hideIconLoadingSkeleton = _ref.hideIconLoadingSkeleton,
    props = (0, _objectWithoutProperties2.default)(_ref, _excluded);
  var cardContext = (0, _flexibleUiContext.useFlexibleCardContext)();
  var _ref2 = cardContext || {},
    _ref2$status = _ref2.status,
    status = _ref2$status === void 0 ? _constants.SmartLinkStatus.Fallback : _ref2$status,
    ui = _ref2.ui;
  var _useState = (0, _react.useState)(false),
    _useState2 = (0, _slicedToArray2.default)(_useState, 2),
    actionDropdownOpen = _useState2[0],
    setActionDropdownOpen = _useState2[1];
  var onDropdownOpenChange = (0, _react.useCallback)(function (isOpen) {
    setActionDropdownOpen(isOpen);
    if (onActionMenuOpenChange) {
      onActionMenuOpenChange({
        isOpen: isOpen
      });
    }
  }, [onActionMenuOpenChange]);
  var actionGroup = actions.length > 0 && /*#__PURE__*/React.createElement(_actionGroup.default, {
    items: actions,
    visibleButtonsNum: showActionOnHover ? 1 : 2,
    onDropdownOpenChange: onDropdownOpenChange
  });
  var overrideText = !!text ? {
    text: text
  } : {};
  var onMouseDown = (0, _useLinkClicked.useMouseDownEvent)();
  var title = /*#__PURE__*/React.createElement(_elements.Title, (0, _extends2.default)({
    hideTooltip: hideTitleTooltip,
    maxLines: maxLines,
    onMouseDown: onMouseDown,
    target: anchorTarget,
    theme: ui === null || ui === void 0 ? void 0 : ui.theme,
    anchorRef: anchorRef
  }, overrideText));
  var Component = getTitleBlockViewComponent(status);
  return /*#__PURE__*/React.createElement(Component, (0, _extends2.default)({}, props, {
    actionGroup: actionGroup
    // eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop
    ,
    className: (0, _runtime.ax)([showActionOnHover && !actionDropdownOpen && "_1bfhidpf _wn5xkb7n _h157kb7n", className]),
    testId: testId,
    title: title,
    metadataPosition: metadataPosition,
    hideIcon: hideIcon,
    hideRetry: hideRetry,
    icon: icon,
    hideIconLoadingSkeleton: hideIconLoadingSkeleton,
    size: (_props$size = props.size) !== null && _props$size !== void 0 ? _props$size : ui === null || ui === void 0 ? void 0 : ui.size,
    CompetitorPrompt: CompetitorPrompt,
    url: url
  }));
};
var _default = exports.default = TitleBlock;