"use strict";

function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;

var _tslib = require("tslib");

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

var _consoleComponents = require("@alicloud/console-components");

var _silderNav = _interopRequireDefault(require("../silder-nav"));

var _classnames = _interopRequireDefault(require("classnames"));

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

function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (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; }

var Popup = _consoleComponents.Overlay.Popup;

var renderInput = function renderInput(_a) {
  var render = _a.render,
      popupConext = _a.popupConext,
      _b = _a.popOffset,
      popOffset = _b === void 0 ? [14, 0] : _b,
      input = (0, _tslib.__rest)(_a, ["render", "popupConext", "popOffset"]);
  return render ? render : popupConext ? /*#__PURE__*/_react["default"].createElement(Popup, {
    offset: popOffset,
    trigger: /*#__PURE__*/_react["default"].createElement(_consoleComponents.Search, (0, _tslib.__assign)({
      placeholder: "search ...",
      className: "lp-search-input",
      shape: "simple"
    }, input))
  }, /*#__PURE__*/_react["default"].createElement("span", {
    className: "lp-overlay-search"
  }, popupConext)) : /*#__PURE__*/_react["default"].createElement(_consoleComponents.Search, (0, _tslib.__assign)({
    placeholder: "search ...",
    className: "lp-search-input",
    shape: "simple"
  }, input));
};

var TopNav = function TopNav(_a) {
  var _b = _a.home,
      home = _b === void 0 ? {
    img: "https://img.alicdn.com/tfs/TB1Cti8pGNj0u4jSZFyXXXgMVXa-210-100.png",
    homeUrl: "//home.console.aliyun.com"
  } : _b,
      style = _a.style,
      _c = _a.offset,
      offset = _c === void 0 ? [0, 0] : _c,
      icons = _a.icons,
      input = _a.input,
      nav = _a.nav,
      user = _a.user,
      _d = _a.fixedTop,
      fixedTop = _d === void 0 ? true : _d,
      sliderContext = _a.sliderContext,
      sliderOfferWidth = _a.sliderOfferWidth,
      sliderOfferHeight = _a.sliderOfferHeight,
      _e = _a.sliderWidth,
      sliderWidth = _e === void 0 ? 300 : _e;
  var left = offset[0],
      top = offset[1];

  var _f = (0, _react.useState)(true),
      collapsed = _f[0],
      setCollapsed = _f[1];

  return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement("div", {
    className: (0, _classnames["default"])("lp-top-nav", {
      "absolute": !fixedTop
    }),
    style: fixedTop ? (0, _tslib.__assign)({
      left: left,
      top: top,
      width: "calc(100% - " + left + "px)"
    }, style) : style
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: "top-left"
  }, sliderContext ? /*#__PURE__*/_react["default"].createElement("div", {
    className: "left-more-button",
    onClick: function onClick() {
      setCollapsed(!collapsed);
    }
  }, /*#__PURE__*/_react["default"].createElement(_consoleComponents.Icon, {
    type: "menu"
  })) : null, /*#__PURE__*/_react["default"].createElement("a", {
    className: "product-icon",
    href: home.homeUrl,
    target: "_self"
  }, /*#__PURE__*/_react["default"].createElement("img", {
    src: home.img
  }))), /*#__PURE__*/_react["default"].createElement("div", {
    className: "top-right"
  }, input && renderInput(input), nav && nav.map(function (_a, index) {
    var render = _a.render,
        text = _a.text,
        onClick = _a.onClick,
        onItemClick = _a.onItemClick,
        key = _a.key,
        _b = _a.menus,
        menus = _b === void 0 ? [] : _b;
    return render ? /*#__PURE__*/_react["default"].createElement("span", {
      key: key ? key : index,
      className: "right-menu",
      onClick: onClick
    }, render) : /*#__PURE__*/_react["default"].createElement(_consoleComponents.Dropdown, {
      key: key ? key : index,
      trigger: /*#__PURE__*/_react["default"].createElement("span", {
        className: "right-menu",
        onClick: onClick
      }, text),
      cache: true
    }, /*#__PURE__*/_react["default"].createElement(_consoleComponents.Menu, {
      onItemClick: onItemClick
    }, menus.map(function (_a) {
      var label = _a.label,
          _b = _a.type,
          type = _b === void 0 ? "item" : _b,
          rest = (0, _tslib.__rest)(_a, ["label", "type"]);
      return type === "divider" ? /*#__PURE__*/_react["default"].createElement(_consoleComponents.Menu.Divider, (0, _tslib.__assign)({}, rest)) : /*#__PURE__*/_react["default"].createElement(_consoleComponents.Menu.Item, (0, _tslib.__assign)({}, rest), label);
    })));
  }), icons && icons.map(function (_a, index) {
    var render = _a.render,
        type = _a.type,
        popupConext = _a.popupConext,
        key = _a.key,
        onClick = _a.onClick,
        popOffset = _a.popOffset;
    return render ? /*#__PURE__*/_react["default"].createElement("span", {
      key: key ? key : index,
      className: "right-menu",
      onClick: onClick
    }, render) : popupConext ? /*#__PURE__*/_react["default"].createElement(Popup, {
      offset: popOffset,
      key: key ? key : index,
      trigger: /*#__PURE__*/_react["default"].createElement(_consoleComponents.Icon, {
        onClick: onClick,
        className: "right-menu",
        type: type
      })
    }, /*#__PURE__*/_react["default"].createElement("div", {
      className: "lp-pop-context"
    }, popupConext)) : /*#__PURE__*/_react["default"].createElement(_consoleComponents.Icon, {
      key: key ? key : index,
      onClick: onClick,
      className: "right-menu",
      type: type
    });
  }), user && user.render ? user.render : user.popupConext ? /*#__PURE__*/_react["default"].createElement(Popup, {
    offset: user.popOffset,
    trigger: /*#__PURE__*/_react["default"].createElement("img", {
      className: "userIcon",
      onClick: user.onClick,
      src: user.icon ? user.icon : "//oss.aliyuncs.com/aliyun_id_photo_bucket/default_handsome.jpg",
      alt: ""
    })
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: "lp-pop-context"
  }, user.popupConext)) : /*#__PURE__*/_react["default"].createElement("img", {
    className: "userIcon",
    src: user.icon ? user.icon : "//oss.aliyuncs.com/aliyun_id_photo_bucket/default_handsome.jpg",
    alt: "",
    onClick: user.onClick
  }))), sliderContext ? /*#__PURE__*/_react["default"].createElement(_silderNav["default"], {
    offset: [0, 50],
    offsetWidth: sliderOfferWidth,
    offsetHeight: sliderOfferHeight,
    type: "dialog",
    hasMask: true,
    width: sliderWidth,
    onMaskClick: function onMaskClick() {
      setCollapsed(!collapsed);
    },
    collapsible: false,
    collapsed: collapsed
  }, sliderContext) : null);
};

var _default = TopNav;
exports["default"] = _default;