"use strict";

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

var _effectStateHooks = _interopRequireDefault(require("parsec-hooks/lib/effectStateHooks"));

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

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

var _one = require("remax/one");

var _indexModule = _interopRequireDefault(require("./styles/index.module.less"));

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

function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _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(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }

function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }

function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }

function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }

var _default = function _default(_ref) {
  var _data$, _data$find;

  var className = _ref.className,
      leftCls = _ref.leftCls,
      rightCls = _ref.rightCls,
      data = _ref.data,
      leftItemCls = _ref.leftItemCls,
      rightItemCls = _ref.rightItemCls,
      _ref$current = _ref.current,
      current = _ref$current === void 0 ? data === null || data === void 0 ? void 0 : (_data$ = data[0]) === null || _data$ === void 0 ? void 0 : _data$.id : _ref$current,
      onSelect = _ref.onSelect,
      onChange = _ref.onChange,
      style = _ref.style;

  var _useEffectState = (0, _effectStateHooks.default)(current, {
    wait: 300
  }),
      _useEffectState2 = _slicedToArray(_useEffectState, 2),
      selected = _useEffectState2[0],
      setSelected = _useEffectState2[1];

  var right = ((_data$find = data.find(function (_ref2) {
    var id = _ref2.id;
    return id === selected;
  })) === null || _data$find === void 0 ? void 0 : _data$find.children) || [];
  return /*#__PURE__*/_react.default.createElement(_one.View, {
    className: (0, _classnames.default)(_indexModule.default.menu, className),
    style: style
  }, /*#__PURE__*/_react.default.createElement(_one.View, {
    className: (0, _classnames.default)(_indexModule.default.left, leftCls)
  }, data.map(function (_ref3) {
    var id = _ref3.id,
        name = _ref3.name,
        children = _ref3.children;
    return /*#__PURE__*/_react.default.createElement(_one.View, {
      key: id,
      className: (0, _classnames.default)(_indexModule.default.leftItem, leftItemCls, selected === id && _indexModule.default.leftActive),
      onTap: function onTap() {
        setSelected(id);
        onChange === null || onChange === void 0 ? void 0 : onChange(id, children || []);
      }
    }, name);
  })), /*#__PURE__*/_react.default.createElement(_one.View, {
    className: (0, _classnames.default)(_indexModule.default.right, rightCls)
  }, right.map(function (item, i) {
    return /*#__PURE__*/_react.default.createElement(_one.View, {
      key: item.id,
      style: {
        borderBottom: i === right.length - 1 ? 0 : undefined
      },
      className: (0, _classnames.default)(_indexModule.default.rightItem, rightItemCls),
      onTap: function onTap() {
        return onSelect === null || onSelect === void 0 ? void 0 : onSelect(item);
      }
    }, item.name);
  })));
};

exports.default = _default;