"use strict";

exports.__esModule = true;
exports.QuickNav = void 0;

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

var _useScrollPosition = require("@n8tb1t/use-scroll-position");

var _LinkTo = require("../LinkTo");

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 QuickNav = function QuickNav(_ref) {
  var entity = _ref.entity,
      appLinks = _ref.appLinks,
      ecosystemLinks = _ref.ecosystemLinks;

  var _useState = (0, _react.useState)(false),
      open = _useState[0],
      setOpen = _useState[1];

  var _useState2 = (0, _react.useState)('quick-nav'),
      classes = _useState2[0],
      setClasses = _useState2[1];

  var _useState3 = (0, _react.useState)(false),
      stuck = _useState3[0],
      setStuck = _useState3[1];

  (0, _useScrollPosition.useScrollPosition)(function (_ref2) {
    var currPos = _ref2.currPos;
    if (currPos.y <= -300) setStuck(true);
    if (stuck && currPos.y > -300) setStuck(false);
  });
  (0, _react.useEffect)(function () {
    if (stuck) {
      setClasses('quick-nav is-stuck');
      return;
    }

    setClasses('quick-nav');
  }, [stuck]);
  (0, _react.useEffect)(function () {
    if (!open) {
      setClasses('quick-nav');
      if (stuck) setClasses('quick-nav is-stuck');
      setOpen(false);
      return;
    }

    setClasses('quick-nav is-open');
  }, [open]);

  var renderDragonchainLinks = function renderDragonchainLinks(links) {
    return links.map(function (link) {
      return link.subNav ? link.subNav.navItems.map(function (subLink) {
        return /*#__PURE__*/_react.default.createElement("li", {
          key: subLink.name
        }, /*#__PURE__*/_react.default.createElement(_LinkTo.LinkTo, {
          type: subLink.type,
          url: subLink.url,
          blank: subLink.blank
        }, subLink.name === 'Overview' ? 'Platform' : subLink.name));
      }) : /*#__PURE__*/_react.default.createElement("li", {
        key: link.name
      }, /*#__PURE__*/_react.default.createElement(_LinkTo.LinkTo, {
        type: link.type,
        url: link.url,
        blank: link.blank
      }, link.name));
    });
  };

  return /*#__PURE__*/_react.default.createElement("nav", {
    role: "presentation",
    className: classes,
    onClick: function onClick() {
      return setOpen(!open);
    }
  }, /*#__PURE__*/_react.default.createElement("div", {
    className: "handle red"
  }, /*#__PURE__*/_react.default.createElement("div", {
    className: "controls"
  }, /*#__PURE__*/_react.default.createElement("div", null)), /*#__PURE__*/_react.default.createElement("div", {
    className: "open-label"
  }, "Dragonchain"), /*#__PURE__*/_react.default.createElement("div", {
    className: "close-label"
  }, "Close Menu")), /*#__PURE__*/_react.default.createElement("div", {
    className: "menu"
  }, /*#__PURE__*/_react.default.createElement("div", {
    className: "inner"
  }, /*#__PURE__*/_react.default.createElement("div", {
    className: "jojo"
  }, /*#__PURE__*/_react.default.createElement("div", {
    className: "inner"
  })), /*#__PURE__*/_react.default.createElement("div", {
    className: "links"
  }, /*#__PURE__*/_react.default.createElement("div", {
    className: "link-list"
  }, /*#__PURE__*/_react.default.createElement("ul", null, /*#__PURE__*/_react.default.createElement("li", null, entity), renderDragonchainLinks(appLinks))), /*#__PURE__*/_react.default.createElement("div", {
    className: "link-list"
  }, /*#__PURE__*/_react.default.createElement("ul", null, /*#__PURE__*/_react.default.createElement("li", null, "Ecosystem"), renderDragonchainLinks(ecosystemLinks.filter(function (link) {
    return link.quickNav;
  }))))))));
};

QuickNav.displayName = 'Quick Nav';
var QuickNavDoc;

if (process.env.NODE_ENV !== 'production') {
  // eslint-disable-next-line global-require
  QuickNavDoc = require('./doc').doc(QuickNav);
}

var QuickNavWrapper = QuickNavDoc || QuickNav;
exports.QuickNav = QuickNavWrapper;