"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.Sidebar = void 0;
var _react = _interopRequireWildcard(require("react"));
var _classnames = _interopRequireDefault(require("classnames"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
const classPrefix = `adm-index-bar`;
const Sidebar = props => {
  const [interacting, setInteracting] = (0, _react.useState)(false);
  return _react.default.createElement("div", {
    className: (0, _classnames.default)(`${classPrefix}-sidebar`, {
      [`${classPrefix}-sidebar-interacting`]: interacting
    }),
    onMouseDown: () => {
      setInteracting(true);
    },
    onMouseUp: () => {
      setInteracting(false);
    },
    onTouchStart: () => {
      setInteracting(true);
    },
    onTouchEnd: () => {
      setInteracting(false);
    },
    onTouchMove: e => {
      if (!interacting) return;
      const {
        clientX,
        clientY
      } = e.touches[0];
      const target = document.elementFromPoint(clientX, clientY);
      if (!target) return;
      const index = target.dataset['index'];
      if (index) {
        props.onActive(index);
      }
    }
  }, props.indexItems.map(({
    index,
    brief
  }) => {
    const active = index === props.activeIndex;
    return _react.default.createElement("div", {
      className: `${classPrefix}-sidebar-row`,
      onMouseDown: () => {
        props.onActive(index);
      },
      onTouchStart: () => {
        props.onActive(index);
      },
      onMouseEnter: () => {
        if (interacting) {
          props.onActive(index);
        }
      },
      "data-index": index,
      key: index
    }, interacting && active && _react.default.createElement("div", {
      className: `${classPrefix}-sidebar-bubble`
    }, brief), _react.default.createElement("div", {
      className: (0, _classnames.default)(`${classPrefix}-sidebar-item`, {
        [`${classPrefix}-sidebar-item-active`]: active
      }),
      "data-index": index
    }, _react.default.createElement("div", null, brief)));
  }));
};
exports.Sidebar = Sidebar;