"use strict";

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

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

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

var _Button = _interopRequireDefault(require("../../../common/Button"));

var _CompCard = _interopRequireDefault(require("./CompCard"));

var _index = _interopRequireDefault(require("./index.less"));

function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }

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

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

function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

function CompListPanel(_ref) {
  var visible = _ref.visible,
      onClose = _ref.onClose,
      compSource = _ref.compSource,
      onAdd = _ref.onAdd;
  (0, _react.useEffect)(function () {
    if (visible) {
      document.getElementsByClassName('component-list')[0].scrollTop = 0;
    }
  }, [visible]);
  return /*#__PURE__*/_react["default"].createElement("div", {
    className: (0, _classnames["default"])(_index["default"].compListPanel, _defineProperty({}, _index["default"].visible, visible))
  }, /*#__PURE__*/_react["default"].createElement("header", {
    className: "header"
  }, /*#__PURE__*/_react["default"].createElement(_Button["default"], {
    type: "icon",
    icon: "icon-close",
    onClick: onClose
  })), /*#__PURE__*/_react["default"].createElement("h2", {
    className: "title"
  }, "Add Component"), /*#__PURE__*/_react["default"].createElement("div", {
    className: "component-list"
  }, Object.keys(compSource).map(function (compCat) {
    return /*#__PURE__*/_react["default"].createElement("div", {
      key: compCat,
      className: "cat-list"
    }, /*#__PURE__*/_react["default"].createElement("h5", {
      className: "cat-name"
    }, compCat, "(", "".concat(compSource[compCat].length), ")"), compSource[compCat].map(function (comp) {
      return /*#__PURE__*/_react["default"].createElement(_CompCard["default"], _extends({}, comp, {
        onAdd: onAdd,
        key: comp.moduleId
      }));
    }));
  })));
}