"use strict";

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

var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));

var _rest = require("@fishx/rest");

var _ecommerce = require("@whalecloud/ecommerce");

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

var _MagicBox = _interopRequireDefault(require("../../../core/MagicBox"));

var _MBaseComponent2 = _interopRequireDefault(require("../../MBaseComponent"));

require("./index.less");

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

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? Object(arguments[i]) : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys.push.apply(ownKeys, Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }

function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }

function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }

function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }

function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }

function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }

function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }

function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }

function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }

function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }

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

/**
 * @class MCatalogMenu 目录组件
 * @author wang.chenye@iwhalecloud.com
 */
var MCatalogMenu = /*#__PURE__*/function (_MBaseComponent) {
  _inherits(MCatalogMenu, _MBaseComponent);

  var _super = _createSuper(MCatalogMenu);

  /**
   * @required
   * React 会根据 type 动态创建组件的实例。
   */
  function MCatalogMenu(props) {
    var _this;

    _classCallCheck(this, MCatalogMenu);

    _this = _super.call(this, props);
    _this.state = {
      isShow: true,
      catalogueTree: []
    };
    return _this;
  }

  _createClass(MCatalogMenu, [{
    key: "queryGoods",
    value: function () {
      var _queryGoods = _asyncToGenerator( /*#__PURE__*/_regenerator["default"].mark(function _callee(params) {
        var data;
        return _regenerator["default"].wrap(function _callee$(_context) {
          while (1) {
            switch (_context.prev = _context.next) {
              case 0:
                _context.next = 2;
                return (0, _rest.fetch)("".concat(window.MParams.MBaseUrl, "/buyer/v1/pages/buyer/displaycatgs"), {
                  method: 'GET',
                  params: params
                });

              case 2:
                data = _context.sent;

                if (data && data instanceof Array) {
                  this.setState({
                    catalogueTree: data
                  });
                }

              case 4:
              case "end":
                return _context.stop();
            }
          }
        }, _callee, this);
      }));

      function queryGoods(_x) {
        return _queryGoods.apply(this, arguments);
      }

      return queryGoods;
    }()
  }, {
    key: "componentDidMount",
    value: function componentDidMount() {
      this.queryGoods({
        bdPageId: window.MParams.bdPageId
      });
    }
  }, {
    key: "render",
    value: function render() {
      var _this2 = this;

      var tempProps = _objectSpread({}, this.props, {
        isLeaf: true,
        onComponentClick: this.onComponentClick,
        style: {
          background: '#fff',
          display: 'flex',
          justifyContent: 'center'
        }
      });

      var catalogueTree = [{
        model: {
          catgId: '01',
          catgName: 'Electronic Devices',
          catgPath: ' '
        },
        children: [{
          model: {
            catgId: '11',
            catgName: 'Mobiles',
            catgPath: ' '
          },
          children: [{
            model: {
              catgId: '111',
              catgName: 'Mobiles',
              catgPath: ' '
            },
            children: null
          }, {
            model: {
              catgId: '112',
              catgName: '5G',
              catgPath: ' '
            },
            children: null
          }, {
            model: {
              catgId: '113',
              catgName: 'Apple Mobiles',
              catgPath: ' '
            },
            children: null
          }, {
            model: {
              catgId: '114',
              catgName: 'Xiaomi Mobiles',
              catgPath: ' '
            },
            children: null
          }, {
            model: {
              catgId: '115',
              catgName: 'Huawei Mobiles',
              catgPath: ' '
            },
            children: null
          }]
        }, {
          model: {
            catgId: '12',
            catgName: 'Tables',
            catgPath: ' '
          },
          children: [{
            model: {
              catgId: '121',
              catgName: 'Tables',
              catgPath: ' '
            },
            children: null
          }]
        }, {
          model: {
            catgId: '13',
            catgName: 'Laptops',
            catgPath: ' '
          },
          children: [{
            model: {
              catgId: '131',
              catgName: 'Laptops',
              catgPath: ' '
            },
            children: null
          }, {
            model: {
              catgId: '132',
              catgName: 'Gaming Laptops',
              catgPath: ' '
            },
            children: null
          }, {
            model: {
              catgId: '133',
              catgName: 'Laptops & Notebooks',
              catgPath: ' '
            },
            children: null
          }]
        }, {
          model: {
            catgId: '14',
            catgName: 'Desktop Computers',
            catgPath: ' '
          },
          children: [{
            model: {
              catgId: '141',
              catgName: 'All in one',
              catgPath: ' '
            },
            children: null
          }, {
            model: {
              catgId: '142',
              catgName: 'DIY',
              catgPath: ' '
            },
            children: null
          }, {
            model: {
              catgId: '143',
              catgName: 'Gaming Desktops',
              catgPath: ' '
            },
            children: null
          }]
        }, {
          model: {
            catgId: '15',
            catgName: 'Gaming Consoles',
            catgPath: ' '
          },
          children: [{
            model: {
              catgId: '151',
              catgName: 'PlayStation Consoles',
              catgPath: ' '
            },
            children: null
          }, {
            model: {
              catgId: '152',
              catgName: 'PlayStation Games',
              catgPath: ' '
            },
            children: null
          }, {
            model: {
              catgId: '153',
              catgName: 'PlayStation Controllers',
              catgPath: ' '
            },
            children: null
          }, {
            model: {
              catgId: '154',
              catgName: 'Nintendo Consoles',
              catgPath: ' '
            },
            children: null
          }, {
            model: {
              catgId: '155',
              catgName: 'Nintendo Games',
              catgPath: ' '
            },
            children: null
          }]
        }, {
          model: {
            catgId: '16',
            catgName: 'Action/Video Cameras',
            catgPath: ' '
          },
          children: [{
            model: {
              catgId: '161',
              catgName: '360 Cameras',
              catgPath: ' '
            },
            children: null
          }, {
            model: {
              catgId: '162',
              catgName: 'Sport & Action Cameras',
              catgPath: ' '
            },
            children: null
          }, {
            model: {
              catgId: '163',
              catgName: 'Video Cameras',
              catgPath: ' '
            },
            children: null
          }, {
            model: {
              catgId: '164',
              catgName: 'Professional Video Cameras',
              catgPath: ' '
            },
            children: null
          }]
        }, {
          model: {
            catgId: '17',
            catgName: 'Security Cameras',
            catgPath: ' '
          },
          children: [{
            model: {
              catgId: '171',
              catgName: 'CCTV Security Cameras',
              catgPath: ' '
            },
            children: null
          }, {
            model: {
              catgId: '172',
              catgName: 'IP Security Cameras',
              catgPath: ' '
            },
            children: null
          }, {
            model: {
              catgId: '173',
              catgName: 'CCTV Security System',
              catgPath: ' '
            },
            children: null
          }, {
            model: {
              catgId: '174',
              catgName: 'IP Security System',
              catgPath: ' '
            },
            children: null
          }, {
            model: {
              catgId: '175',
              catgName: 'Dummy Cameras',
              catgPath: ' '
            },
            children: null
          }]
        }, {
          model: {
            catgId: '18',
            catgName: 'Digital Cameras',
            catgPath: ' '
          },
          children: [{
            model: {
              catgId: '181',
              catgName: 'DSLR',
              catgPath: ' '
            },
            children: null
          }, {
            model: {
              catgId: '182',
              catgName: 'Mirroless',
              catgPath: ' '
            },
            children: null
          }, {
            model: {
              catgId: '183',
              catgName: 'Point & Shoot',
              catgPath: ' '
            },
            children: null
          }, {
            model: {
              catgId: '184',
              catgName: 'Instant Cameras',
              catgPath: ' '
            },
            children: null
          }]
        }, {
          model: {
            catgId: '19',
            catgName: 'Gadgets & Drones',
            catgPath: ' '
          },
          children: [{
            model: {
              catgId: '191',
              catgName: 'Drones',
              catgPath: ' '
            },
            children: null
          }, {
            model: {
              catgId: '192',
              catgName: 'Media Players',
              catgPath: ' '
            },
            children: null
          }, {
            model: {
              catgId: '193',
              catgName: 'Walkie-Talkies',
              catgPath: ' '
            },
            children: null
          }]
        }]
      }, {
        model: {
          catgId: '02',
          catgName: 'Electronic Accessories',
          catgPath: ' '
        },
        children: null
      }, {
        model: {
          catgId: '03',
          catgName: 'TV & Home Appliances',
          catgPath: ' '
        },
        children: null
      }, {
        model: {
          catgId: '04',
          catgName: 'Health & Beauty',
          catgPath: ' '
        },
        children: null
      }, {
        model: {
          catgId: '05',
          catgName: 'Babies & Toys',
          catgPath: ' '
        },
        children: null
      }, {
        model: {
          catgId: '06',
          catgName: 'Groceries & Pets',
          catgPath: ' '
        },
        children: null
      }, {
        model: {
          catgId: '07',
          catgName: 'Home & LifeStyle',
          catgPath: ' '
        },
        children: null
      }, {
        model: {
          catgId: '08',
          catgName: "Women's Fashion",
          catgPath: ' '
        },
        children: null
      }, {
        model: {
          catgId: '09',
          catgName: "Men's Fashion",
          catgPath: ' '
        },
        children: null
      }, {
        model: {
          catgId: '10',
          catgName: 'Watches & Bags',
          catgPath: ' '
        },
        children: null
      }];
      var navList = tempProps.catalogList ? tempProps.catalogList : [];
      return /*#__PURE__*/_react["default"].createElement(_MagicBox["default"], tempProps, /*#__PURE__*/_react["default"].createElement(_ecommerce.CategoryNavi, {
        data: this.state.catalogueTree,
        firstCatalogNmae: tempProps.firstCatalogNmae,
        navList: navList,
        naviClick: function naviClick(item) {
          return _this2.clickItem(item.link);
        }
      }));
    }
  }]);

  return MCatalogMenu;
}(_MBaseComponent2["default"]);

exports["default"] = MCatalogMenu;

_defineProperty(MCatalogMenu, "type", 'MCatalogMenu');