"use strict";

function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }

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

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

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

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

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

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 ? Object.assign.bind() : 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); }

var __extends = void 0 && (void 0).__extends || function () {
  var _extendStatics = function extendStatics(d, b) {
    _extendStatics = Object.setPrototypeOf || {
      __proto__: []
    } instanceof Array && function (d, b) {
      d.__proto__ = b;
    } || function (d, b) {
      for (var p in b) {
        if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p];
      }
    };

    return _extendStatics(d, b);
  };

  return function (d, b) {
    if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");

    _extendStatics(d, b);

    function __() {
      this.constructor = d;
    }

    d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  };
}();

var CompListPanel =
/** @class */
function (_super) {
  __extends(CompListPanel, _super);

  function CompListPanel() {
    var _this = _super !== null && _super.apply(this, arguments) || this;

    _this.animation = function (type) {
      document.getElementsByClassName('list_panel')[0].setAttribute('style', "animation-name:".concat(type, ";animation-duration: 0.3s;animation-fill-mode:both"));
    };

    _this.onClose = function () {
      _this.animation('onListClose');
    };

    _this.onOpen = function () {
      _this.animation('onListOpen');
    };

    _this.onAddClick = function (data) {
      var onAdd = _this.props.onAdd;

      _this.onClose();

      onAdd(data);
    };

    return _this;
  }

  CompListPanel.prototype.render = function () {
    var _this = this;

    var compSource = this.props.compSource;
    return /*#__PURE__*/_react["default"].createElement("div", {
      className: (0, _classnames["default"])('list_panel')
    }, /*#__PURE__*/_react["default"].createElement("header", {
      className: "header"
    }, /*#__PURE__*/_react["default"].createElement(_Button["default"], {
      icon: "icon-close",
      onClick: this.onClose,
      type: "icon"
    })), /*#__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, {
          key: comp.moduleId,
          onAdd: _this.onAddClick
        }));
      }));
    })));
  };

  return CompListPanel;
}(_react.Component);

var _default = CompListPanel; // export default function CompListPanel({ visible, onClose, compSource, onAdd }) {
//   useEffect(() => {
//     if (visible) {
//       document.getElementsByClassName('component-list')[0].scrollTop = 0;
//     }
//   }, [visible]);
//   return (
//     <div className={classNames('compListPanel', { visible })}>
//       <header className="header">
//         <Button icon="icon-close" onClick={onClose} type="icon" />
//       </header>
//       <h2 className="title">Add Component</h2>
//       <div className="component-list">
//         {
//           Object.keys(compSource).map(compCat => (
//             <div key={compCat} className="cat-list">
//               <h5 className="cat-name">{compCat}({`${compSource[compCat].length}`})</h5>
//               {
//                 compSource[compCat].map(comp => (
//                   <CompCard {...comp} key={comp.moduleId} onAdd={onAdd} />
//                 ))
//               }
//             </div>
//           ))
//         }
//       </div>
//     </div>
//   );
// }

exports["default"] = _default;