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; }

import classNames from 'classnames';
import React, { useEffect } from 'react';
import Button from '../../../common/Button';
import CompCard from './CompCard';
import styles from './index.less';
export default function CompListPanel(_ref) {
  var visible = _ref.visible,
      onClose = _ref.onClose,
      compSource = _ref.compSource,
      onAdd = _ref.onAdd;
  useEffect(function () {
    if (visible) {
      document.getElementsByClassName('component-list')[0].scrollTop = 0;
    }
  }, [visible]);
  return /*#__PURE__*/React.createElement("div", {
    className: classNames(styles.compListPanel, _defineProperty({}, styles.visible, visible))
  }, /*#__PURE__*/React.createElement("header", {
    className: "header"
  }, /*#__PURE__*/React.createElement(Button, {
    type: "icon",
    icon: "icon-close",
    onClick: onClose
  })), /*#__PURE__*/React.createElement("h2", {
    className: "title"
  }, "Add Component"), /*#__PURE__*/React.createElement("div", {
    className: "component-list"
  }, Object.keys(compSource).map(function (compCat) {
    return /*#__PURE__*/React.createElement("div", {
      key: compCat,
      className: "cat-list"
    }, /*#__PURE__*/React.createElement("h5", {
      className: "cat-name"
    }, compCat, "(", "".concat(compSource[compCat].length), ")"), compSource[compCat].map(function (comp) {
      return /*#__PURE__*/React.createElement(CompCard, _extends({}, comp, {
        onAdd: onAdd,
        key: comp.moduleId
      }));
    }));
  })));
}