"use strict";

exports.__esModule = true;
exports.default = exports.TabText = exports.TabLink = exports.PageTab = exports.ModuleTab = exports.ModuleIcon = exports.CloseIcon = 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(e) { return e && e.__esModule ? e : { default: e }; }
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
(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(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _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(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var s = Object.getOwnPropertySymbols(e); for (r = 0; r < s.length; r++) o = s[r], t.includes(o) || {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.includes(n)) continue; t[n] = r[n]; } return t; }
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 = exports.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

var ModuleTab = exports.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;}"]);
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 = exports.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;"])));
var ModuleIcon = exports.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;"]);
var TabText = exports.TabText = _styledComponents.default.span.withConfig({
  displayName: "Tab__TabText",
  componentId: "sc-1ivjzw-4"
})(["min-width:50px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;"]);
var CloseIcon = exports.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"));
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 = exports.default = _default2;
;
(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);
})();