import React, { useEffect, useState } from 'react';
import { useScrollPosition } from '@n8tb1t/use-scroll-position';
import { LinkTo } from '../LinkTo';

var QuickNav = function QuickNav(_ref) {
  var entity = _ref.entity,
      appLinks = _ref.appLinks,
      ecosystemLinks = _ref.ecosystemLinks;

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

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

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

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

    setClasses('quick-nav');
  }, [stuck]);
  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.createElement("li", {
          key: subLink.name
        }, /*#__PURE__*/React.createElement(LinkTo, {
          type: subLink.type,
          url: subLink.url,
          blank: subLink.blank
        }, subLink.name === 'Overview' ? 'Platform' : subLink.name));
      }) : /*#__PURE__*/React.createElement("li", {
        key: link.name
      }, /*#__PURE__*/React.createElement(LinkTo, {
        type: link.type,
        url: link.url,
        blank: link.blank
      }, link.name));
    });
  };

  return /*#__PURE__*/React.createElement("nav", {
    role: "presentation",
    className: classes,
    onClick: function onClick() {
      return setOpen(!open);
    }
  }, /*#__PURE__*/React.createElement("div", {
    className: "handle red"
  }, /*#__PURE__*/React.createElement("div", {
    className: "controls"
  }, /*#__PURE__*/React.createElement("div", null)), /*#__PURE__*/React.createElement("div", {
    className: "open-label"
  }, "Dragonchain"), /*#__PURE__*/React.createElement("div", {
    className: "close-label"
  }, "Close Menu")), /*#__PURE__*/React.createElement("div", {
    className: "menu"
  }, /*#__PURE__*/React.createElement("div", {
    className: "inner"
  }, /*#__PURE__*/React.createElement("div", {
    className: "jojo"
  }, /*#__PURE__*/React.createElement("div", {
    className: "inner"
  })), /*#__PURE__*/React.createElement("div", {
    className: "links"
  }, /*#__PURE__*/React.createElement("div", {
    className: "link-list"
  }, /*#__PURE__*/React.createElement("ul", null, /*#__PURE__*/React.createElement("li", null, entity), renderDragonchainLinks(appLinks))), /*#__PURE__*/React.createElement("div", {
    className: "link-list"
  }, /*#__PURE__*/React.createElement("ul", null, /*#__PURE__*/React.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;
export { QuickNavWrapper as QuickNav };