"use strict";

exports.__esModule = true;
exports.default = exports.CloseIcon = exports.TabText = exports.ModuleIcon = exports.TabLink = exports.ModuleTab = exports.PageTab = void 0;

var _react = _interopRequireWildcard(require("react"));

var _styledComponents = _interopRequireWildcard(require("styled-components"));

var _utils = require("../../utils");

var _reactRouterDom = require("react-router-dom");

var _Icon = _interopRequireDefault(require("../Icon"));

var _useLabelMessage3 = _interopRequireDefault(require("../../hooks/useLabelMessage"));

var _Text = require("../Text");

var _reactIntl = require("react-intl");

var _excluded = ["outsideScope", "mustTruncate"];

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }

function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

(function () {
  var enterModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.enterModule : undefined;
  enterModule && enterModule(module);
})();

(function () {
  var enterModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.enterModule : undefined;
  enterModule && enterModule(module);
})();

function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }

function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }

function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }

function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }

function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }

function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }

function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }

function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }

var __signature__ = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default.signature : function (a) {
  return a;
};

var __signature__ = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default.signature : function (a) {
  return a;
};

var PageTab = _styledComponents.default.div.withConfig({
  displayName: "Tab__PageTab",
  componentId: "sc-1ivjzw-0"
})(["flex:0 0 auto;overflow:hidden;height:38px;border:1px solid ", ";border-top-left-radius:5px;border-top-right-radius:5px;margin-left:-1px;background-color:white;", ";", " ", ""], (0, _utils.getThemeProp)(["colors", "borderLight"], "#cccccc"), (0, _utils.ifFlag)("active", (0, _styledComponents.css)(["border-bottom-color:white;color:", ";"], (0, _utils.getThemeProp)(["colors", "application", "base"], "#ccc")), (0, _styledComponents.css)(["color:", ";"], (0, _utils.getThemeProp)(["colors", "textMedium"], "#999999"))), (0, _utils.ifFlag)("outsideScope", (0, _styledComponents.css)(["background-color:#eeeeee;"])), (0, _utils.ifFlag)("hide", (0, _styledComponents.css)(["visibility:hidden;"]))); // XXX: The below contains an IE10/IE11 targeting CSS hack


exports.PageTab = PageTab;
var ModuleTab = (0, _styledComponents.default)(PageTab).withConfig({
  displayName: "Tab__ModuleTab",
  componentId: "sc-1ivjzw-1"
})(["flex-grow:0;flex-shrink:0;margin-left:0px;z-index:1;@media all and (-ms-high-contrast:none),(-ms-high-contrast:active){flex-grow:1;}"]);
exports.ModuleTab = ModuleTab;

var FilteredLink = function FilteredLink(_ref) {
  var outsideScope = _ref.outsideScope,
      mustTruncate = _ref.mustTruncate,
      props = _objectWithoutProperties(_ref, _excluded);

  return /*#__PURE__*/_react.default.createElement(_reactRouterDom.Link, props);
};

var TabLink = (0, _styledComponents.default)(FilteredLink).withConfig({
  displayName: "Tab__TabLink",
  componentId: "sc-1ivjzw-2"
})(["min-width:100px;overflow:hidden;color:inherit;text-decoration:none;display:flex;justify-content:center;padding:11px 15px;", ";", ";"], (0, _utils.ifFlag)("outsideScope", (0, _styledComponents.css)(["cursor:not-allowed;"])), (0, _utils.ifFlag)("mustTruncate", (0, _styledComponents.css)(["max-width:220px;"])));
exports.TabLink = TabLink;
var ModuleIcon = (0, _styledComponents.default)(_Icon.default).withConfig({
  displayName: "Tab__ModuleIcon",
  componentId: "sc-1ivjzw-3"
})(["vertical-align:middle;font-size:20px;margin-right:10px;margin-top:-3px;"]);
exports.ModuleIcon = ModuleIcon;

var TabText = _styledComponents.default.span.withConfig({
  displayName: "Tab__TabText",
  componentId: "sc-1ivjzw-4"
})(["min-width:50px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;"]);

exports.TabText = TabText;
var CloseIcon = (0, _styledComponents.default)(_Icon.default).attrs(function (props) {
  return {
    id: (0, _utils.getThemeProp)(["icons", "close"], "close")(props)
  };
}).withConfig({
  displayName: "Tab__CloseIcon",
  componentId: "sc-1ivjzw-5"
})(["flex:0 0 auto;margin-left:10px;margin-right:-5px;font-size:14px;color:", ";&:hover{color:", ";}"], (0, _utils.getThemeProp)(["colors", "textMedium"], "#999999"), (0, _utils.getThemeProp)(["colors", "application", "base"], "#ccc"));
exports.CloseIcon = CloseIcon;

var Tab = function Tab(_ref2, ref) {
  var href = _ref2.href,
      label = _ref2.label,
      mustTruncate = _ref2.mustTruncate,
      icon = _ref2.icon,
      module = _ref2.module,
      active = _ref2.active,
      _ref2$close = _ref2.close,
      close = _ref2$close === void 0 ? function () {} : _ref2$close,
      outsideScope = _ref2.outsideScope,
      scopeNotSupported = _ref2.scopeNotSupported,
      hide = _ref2.hide;
  var ThisTab = module ? ModuleTab : PageTab;

  var _useIntl = (0, _reactIntl.useIntl)(),
      formatMessage = _useIntl.formatMessage;

  var tabTextRef = (0, _react.useRef)(null);

  var _useState = (0, _react.useState)(null),
      _useState2 = _slicedToArray(_useState, 2),
      aTitle = _useState2[0],
      setTitle = _useState2[1];

  var buildMessage = function buildMessage(message) {
    return formatMessage(message, message.values);
  };

  var _useLabelMessage = (0, _useLabelMessage3.default)(label, buildMessage),
      _useLabelMessage2 = _slicedToArray(_useLabelMessage, 1),
      labelMessage = _useLabelMessage2[0];

  (0, _react.useEffect)(function () {
    if (scopeNotSupported) {
      close();
    } else if (mustTruncate && tabTextRef.current && tabTextRef.current.offsetWidth < tabTextRef.current.scrollWidth) {
      setTitle(labelMessage);
    }
  }, [scopeNotSupported, tabTextRef, setTitle, labelMessage, mustTruncate, close]);
  return /*#__PURE__*/_react.default.createElement(ThisTab, {
    ref: ref,
    active: active,
    outsideScope: outsideScope,
    hide: hide || scopeNotSupported,
    "data-href": href
  }, /*#__PURE__*/_react.default.createElement(TabLink, {
    to: href,
    mustTruncate: mustTruncate,
    outsideScope: outsideScope,
    onClick: outsideScope ? function (event) {
      event.preventDefault();
      event.stopPropagation();
    } : function () {}
  }, module ? /*#__PURE__*/_react.default.createElement(ModuleIcon, {
    id: icon
  }) : null, /*#__PURE__*/_react.default.createElement(TabText, {
    ref: tabTextRef,
    title: aTitle
  }, labelMessage ? labelMessage : /*#__PURE__*/_react.default.createElement(_Text.Placeholder, null)), module ? null : /*#__PURE__*/_react.default.createElement(CloseIcon, {
    onClick: close
  })));
};

__signature__(Tab, "useIntl{{ formatMessage }}\nuseRef{tabTextRef}\nuseState{[aTitle, setTitle](null)}\nuseLabelMessage{[labelMessage]}\nuseEffect{}", function () {
  return [_reactIntl.useIntl, _useLabelMessage3.default];
});

__signature__(Tab, "useIntl{{ formatMessage }}\nuseRef{tabTextRef}\nuseState{[aTitle, setTitle](null)}\nuseLabelMessage{[labelMessage]}\nuseEffect{}", function () {
  return [_reactIntl.useIntl, _useLabelMessage3.default];
});

var _default = _react.default.forwardRef(Tab);

var _default2 = _default;
var _default3 = _default2;
exports.default = _default3;
;

(function () {
  var reactHotLoader = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default : undefined;

  if (!reactHotLoader) {
    return;
  }

  reactHotLoader.register(PageTab, "PageTab", "/home/vsts/work/1/s/src/components/Navigation/Tab.js");
  reactHotLoader.register(ModuleTab, "ModuleTab", "/home/vsts/work/1/s/src/components/Navigation/Tab.js");
  reactHotLoader.register(FilteredLink, "FilteredLink", "/home/vsts/work/1/s/src/components/Navigation/Tab.js");
  reactHotLoader.register(TabLink, "TabLink", "/home/vsts/work/1/s/src/components/Navigation/Tab.js");
  reactHotLoader.register(ModuleIcon, "ModuleIcon", "/home/vsts/work/1/s/src/components/Navigation/Tab.js");
  reactHotLoader.register(TabText, "TabText", "/home/vsts/work/1/s/src/components/Navigation/Tab.js");
  reactHotLoader.register(CloseIcon, "CloseIcon", "/home/vsts/work/1/s/src/components/Navigation/Tab.js");
  reactHotLoader.register(Tab, "Tab", "/home/vsts/work/1/s/src/components/Navigation/Tab.js");
  reactHotLoader.register(_default, "default", "/home/vsts/work/1/s/src/components/Navigation/Tab.js");
})();

;

(function () {
  var leaveModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.leaveModule : undefined;
  leaveModule && leaveModule(module);
})();

;

(function () {
  var reactHotLoader = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default : undefined;

  if (!reactHotLoader) {
    return;
  }

  reactHotLoader.register(PageTab, "PageTab", "/home/vsts/work/1/s/src/components/Navigation/Tab.js");
  reactHotLoader.register(ModuleTab, "ModuleTab", "/home/vsts/work/1/s/src/components/Navigation/Tab.js");
  reactHotLoader.register(FilteredLink, "FilteredLink", "/home/vsts/work/1/s/src/components/Navigation/Tab.js");
  reactHotLoader.register(TabLink, "TabLink", "/home/vsts/work/1/s/src/components/Navigation/Tab.js");
  reactHotLoader.register(ModuleIcon, "ModuleIcon", "/home/vsts/work/1/s/src/components/Navigation/Tab.js");
  reactHotLoader.register(TabText, "TabText", "/home/vsts/work/1/s/src/components/Navigation/Tab.js");
  reactHotLoader.register(CloseIcon, "CloseIcon", "/home/vsts/work/1/s/src/components/Navigation/Tab.js");
  reactHotLoader.register(Tab, "Tab", "/home/vsts/work/1/s/src/components/Navigation/Tab.js");
  reactHotLoader.register(_default2, "default", "/home/vsts/work/1/s/src/components/Navigation/Tab.js");
})();

;

(function () {
  var leaveModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.leaveModule : undefined;
  leaveModule && leaveModule(module);
})();