"use strict";

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

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

var _mobxReact = require("mobx-react");

var _defaultImg = _interopRequireDefault(require("../imgs/defaultImg.png"));

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

var _GroupList = _interopRequireDefault(require("../../../../../common/GroupList"));

var _defaultJSON = require("../../../components/Recommend/defaultJSON");

var _coreUtil = require("../../../../../utils/coreUtil");

require("./index.less");

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

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

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 (b.hasOwnProperty(p)) d[p] = b[p];
      }
    };

    return _extendStatics(d, b);
  };

  return function (d, b) {
    _extendStatics(d, b);

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

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

var __decorate = void 0 && (void 0).__decorate || function (decorators, target, key, desc) {
  var c = arguments.length,
      r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc,
      d;
  if ((typeof Reflect === "undefined" ? "undefined" : _typeof(Reflect)) === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);else for (var i = decorators.length - 1; i >= 0; i--) {
    if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  }
  return c > 3 && r && Object.defineProperty(target, key, r), r;
};

var notice = '';

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

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

    _this.state = {};

    _this.onClickItem = function (node) {
      _this.props.store.setState({
        clickedGroup: node.id
      });
    };

    _this.onAddClick = function () {
      var json = (0, _defaultJSON.recommendGroupSourceJSON)('', 'Tab');

      _this.props.source.push(json);

      _this.setState({});

      (0, _coreUtil.renderPreview)();
    };

    _this.reRender = function () {
      _this.setState({});
    };

    return _this;
  }

  AComponent.prototype.render = function () {
    var source = this.props.source;

    var _renderCard = function renderCard(src) {
      return /*#__PURE__*/_react["default"].createElement("div", {
        className: "card_wrap"
      }, /*#__PURE__*/_react["default"].createElement("img", {
        alt: "",
        src: ((0, _coreUtil.isPc)() ? src.image.content.pcImgSrc : src.image.content.h5ImgSrc) || _defaultImg["default"]
      }), /*#__PURE__*/_react["default"].createElement("div", {
        className: "name"
      }, src.groupName.text));
    };

    return /*#__PURE__*/_react["default"].createElement("div", {
      className: "group_wrap"
    }, /*#__PURE__*/_react["default"].createElement("div", {
      className: "node_list"
    }, source.length === 0 ? /*#__PURE__*/_react["default"].createElement("span", {
      className: "notice"
    }, notice) : /*#__PURE__*/_react["default"].createElement(_GroupList["default"], {
      onClickItem: this.onClickItem,
      renderCard: function renderCard(v) {
        return _renderCard(v);
      },
      reRender: this.reRender,
      source: source
    })), /*#__PURE__*/_react["default"].createElement("div", {
      className: "btn_wrap"
    }, /*#__PURE__*/_react["default"].createElement(_Button["default"], {
      icon: "icon-add",
      onClick: this.onAddClick,
      type: "primary"
    }, "Add Group")));
  };

  AComponent.defaultProps = {
    source: []
  };
  AComponent = __decorate([(0, _mobxReact.inject)('store'), _mobxReact.observer], AComponent);
  return AComponent;
}(_react["default"].Component);

var _default = AComponent;
exports["default"] = _default;