"use strict";

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

var _fdx = require("@whalecloud/fdx");

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

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

var _index2 = _interopRequireDefault(require("../components/BottomButton/index"));

var _index3 = _interopRequireDefault(require("../components/CommonStyle/index"));

var _MPropertiesBaseComponent = _interopRequireDefault(require("../MPropertiesBaseComponent"));

require("./index.module.less");

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

function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }

function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }

function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }

function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }

function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }

function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }

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

var MFlashSalesProperties = /*#__PURE__*/function (_MPropertiesBaseCompo) {
  _inherits(MFlashSalesProperties, _MPropertiesBaseCompo);

  var _super = _createSuper(MFlashSalesProperties);

  function MFlashSalesProperties(_props) {
    var _this;

    _classCallCheck(this, MFlashSalesProperties);

    _this = _super.call(this, _props);

    _defineProperty(_assertThisInitialized(_this), "resetProps", function (props) {
      _this.setState(_objectSpread({}, props, {
        progressImg: props.progressImg ? props.progressImg : [],
        noticeImg: props.noticeImg ? props.noticeImg : [],
        pageModuleName: props.pageModuleName || ''
      }));
    });

    _defineProperty(_assertThisInitialized(_this), "onSave", function () {
      var evt = new Event('property-update', {
        bubbles: false
      });
      evt.data = _objectSpread({}, _this.props, _this.state);
      console.log('evt: ', evt);

      if ((evt.data.noticeImg.length === 0 || evt.data.progressImg.length === 0) && _this.props.renderer !== 'mobile') {
        _fdx.message.warning('Please Add Image first');

        return;
      }

      window.document.dispatchEvent(evt);
    });

    _defineProperty(_assertThisInitialized(_this), "uploadImgUrl", function (type, index, url) {
      var _this$state = _this.state,
          progressImg = _this$state.progressImg,
          noticeImg = _this$state.noticeImg;

      if (type === 'pro') {
        var arr = JSON.parse(JSON.stringify(progressImg));
        arr[index].imgUrl = url;

        _this.setState({
          progressImg: arr
        });
      } else {
        var _arr = JSON.parse(JSON.stringify(noticeImg));

        _arr[index].imgUrl = url;

        _this.setState({
          noticeImg: _arr
        });
      }
    });

    _defineProperty(_assertThisInitialized(_this), "setImgLink", function (type, index, value) {
      var _this$state2 = _this.state,
          progressImg = _this$state2.progressImg,
          noticeImg = _this$state2.noticeImg;

      if (type === 'pro') {
        var arr = JSON.parse(JSON.stringify(progressImg));
        arr[index].link = value;

        _this.setState({
          progressImg: arr
        });
      } else {
        var _arr2 = JSON.parse(JSON.stringify(noticeImg));

        _arr2[index].link = value;

        _this.setState({
          noticeImg: _arr2
        });
      }
    });

    _defineProperty(_assertThisInitialized(_this), "addNewItem", function (type) {
      var _this$state3 = _this.state,
          progressImg = _this$state3.progressImg,
          noticeImg = _this$state3.noticeImg;

      if (type === 'pro') {
        _this.setState({
          progressImg: [].concat(_toConsumableArray(progressImg), [{}])
        });
      } else {
        _this.setState({
          noticeImg: [].concat(_toConsumableArray(noticeImg), [{}])
        });
      }
    });

    _defineProperty(_assertThisInitialized(_this), "previewImg", function (url) {
      window.open(url);
    });

    _defineProperty(_assertThisInitialized(_this), "delImg", function (type, index) {
      var _this$state4 = _this.state,
          progressImg = _this$state4.progressImg,
          noticeImg = _this$state4.noticeImg;

      if (type === 'pro') {
        var arr = JSON.parse(JSON.stringify(progressImg));
        arr[index].imgUrl = '';

        _this.setState({
          progressImg: arr
        });
      } else {
        var _arr3 = JSON.parse(JSON.stringify(noticeImg));

        _arr3[index].imgUrl = '';

        _this.setState({
          noticeImg: _arr3
        });
      }
    });

    _defineProperty(_assertThisInitialized(_this), "itemUp", function (type, index) {
      var _this$state5 = _this.state,
          progressImg = _this$state5.progressImg,
          noticeImg = _this$state5.noticeImg;

      if (type === 'pro') {
        var arr = JSON.parse(JSON.stringify(progressImg));
        var _ref = [arr[index - 1], arr[index]];
        arr[index] = _ref[0];
        arr[index - 1] = _ref[1];

        _this.setState({
          progressImg: arr
        });
      } else {
        var _arr4 = JSON.parse(JSON.stringify(noticeImg));

        var _ref2 = [_arr4[index - 1], _arr4[index]];
        _arr4[index] = _ref2[0];
        _arr4[index - 1] = _ref2[1];

        _this.setState({
          noticeImg: _arr4
        });
      }
    });

    _defineProperty(_assertThisInitialized(_this), "itemDown", function (type, index) {
      var _this$state6 = _this.state,
          progressImg = _this$state6.progressImg,
          noticeImg = _this$state6.noticeImg;

      if (type === 'pro') {
        var arr = JSON.parse(JSON.stringify(progressImg));
        var _ref3 = [arr[index], arr[index + 1]];
        arr[index + 1] = _ref3[0];
        arr[index] = _ref3[1];

        _this.setState({
          progressImg: arr
        });
      } else {
        var _arr5 = JSON.parse(JSON.stringify(noticeImg));

        var _ref4 = [_arr5[index], _arr5[index + 1]];
        _arr5[index + 1] = _ref4[0];
        _arr5[index] = _ref4[1];

        _this.setState({
          noticeImg: _arr5
        });
      }
    });

    _defineProperty(_assertThisInitialized(_this), "delItem", function (type, index) {
      var _this$state7 = _this.state,
          progressImg = _this$state7.progressImg,
          noticeImg = _this$state7.noticeImg;

      if (type === 'pro') {
        var arr = JSON.parse(JSON.stringify(progressImg));
        arr.splice(index, 1);

        _this.setState({
          progressImg: arr
        });
      } else {
        var _arr6 = JSON.parse(JSON.stringify(noticeImg));

        _arr6.splice(index, 1);

        _this.setState({
          noticeImg: _arr6
        });
      }
    });

    var _this$props = _this.props,
        imageLocation = _this$props.imageLocation,
        slidingMode = _this$props.slidingMode,
        pageModuleName = _this$props.pageModuleName;
    _this.state = _objectSpread({
      progressImg: [],
      noticeImg: [],
      imageLocation: imageLocation || 'Left',
      slidingMode: slidingMode || 'Auto',
      pageModuleName: pageModuleName || '',
      orderBy: 'Price',
      sourceUrl: ''
    }, _props);
    return _this;
  }

  _createClass(MFlashSalesProperties, [{
    key: "render",
    value: function render() {
      var _this2 = this;

      var isMoblie = this.props.renderer === 'mobile';
      var _this$state8 = this.state,
          progressImg = _this$state8.progressImg,
          noticeImg = _this$state8.noticeImg,
          imageLocation = _this$state8.imageLocation,
          slidingMode = _this$state8.slidingMode,
          orderBy = _this$state8.orderBy,
          sourceUrl = _this$state8.sourceUrl,
          pageModuleName = _this$state8.pageModuleName;
      var Option = _fdx.Select.Option;
      return /*#__PURE__*/_react["default"].createElement("div", {
        className: "mScorllWrap"
      }, /*#__PURE__*/_react["default"].createElement(_index3["default"], {
        data: this.state.commonConfig,
        onChange: function onChange(data) {
          _this2.state.commonConfig = data;
        }
      }), !isMoblie && /*#__PURE__*/_react["default"].createElement("div", {
        className: "addBut"
      }, /*#__PURE__*/_react["default"].createElement(_index["default"], {
        title: "In progress",
        hasTip: false,
        maxCount: 1,
        setImgLink: function setImgLink(index, url) {
          return _this2.setImgLink('pro', index, url);
        },
        imgList: progressImg,
        uploadImgUrl: function uploadImgUrl(index, url) {
          return _this2.uploadImgUrl('pro', index, url);
        },
        addNewItem: function addNewItem() {
          return _this2.addNewItem('pro');
        },
        previewImg: this.previewImg,
        delImg: function delImg(index) {
          return _this2.delImg('pro', index);
        },
        itemUp: function itemUp(index) {
          return _this2.itemUp('pro', index);
        },
        itemDown: function itemDown(index) {
          return _this2.itemDown('pro', index);
        },
        delItem: function delItem(index) {
          return _this2.delItem('pro', index);
        },
        renderer: this.props.renderer
      }), /*#__PURE__*/_react["default"].createElement(_index["default"], {
        title: "Notice",
        hasTip: false,
        maxCount: 1,
        setImgLink: function setImgLink(index, url) {
          return _this2.setImgLink('not', index, url);
        },
        imgList: noticeImg,
        uploadImgUrl: function uploadImgUrl(index, url) {
          return _this2.uploadImgUrl('not', index, url);
        },
        addNewItem: function addNewItem() {
          return _this2.addNewItem('not');
        },
        previewImg: this.previewImg,
        delImg: function delImg(index) {
          return _this2.delImg('not', index);
        },
        itemUp: function itemUp(index) {
          return _this2.itemUp('not', index);
        },
        itemDown: function itemDown(index) {
          return _this2.itemDown('not', index);
        },
        delItem: function delItem(index) {
          return _this2.delItem('not', index);
        },
        renderer: this.props.renderer
      })), /*#__PURE__*/_react["default"].createElement(_fdx.Form, {
        layout: "vertical"
      }, !isMoblie && /*#__PURE__*/_react["default"].createElement(_fdx.Form.Item, {
        label: "Image Location"
      }, /*#__PURE__*/_react["default"].createElement(_fdx.Radio.Group, {
        defaultValue: imageLocation,
        onChange: function onChange(e) {
          _this2.setState({
            imageLocation: e.target.value
          });
        }
      }, /*#__PURE__*/_react["default"].createElement(_fdx.Radio, {
        value: "Left"
      }, "Left"), /*#__PURE__*/_react["default"].createElement(_fdx.Radio, {
        value: "Right"
      }, "Right"))), !isMoblie && /*#__PURE__*/_react["default"].createElement(_fdx.Form.Item, {
        label: "Sliding Mode"
      }, /*#__PURE__*/_react["default"].createElement(_fdx.Radio.Group, {
        defaultValue: slidingMode,
        onChange: function onChange(e) {
          _this2.setState({
            slidingMode: e.target.value
          });
        }
      }, /*#__PURE__*/_react["default"].createElement(_fdx.Radio, {
        value: "Auto"
      }, "Auto"), /*#__PURE__*/_react["default"].createElement(_fdx.Radio, {
        value: "Manual"
      }, "Manual"))), /*#__PURE__*/_react["default"].createElement(_fdx.Form.Item, {
        name: "pageModuleName",
        label: "Title"
      }, /*#__PURE__*/_react["default"].createElement(_fdx.Input, {
        defaultValue: pageModuleName,
        onChange: function onChange(value) {
          _this2.setState({
            pageModuleName: value.target.value
          });
        }
      })), /*#__PURE__*/_react["default"].createElement(_fdx.Form.Item, {
        label: "Product Sort By"
      }, /*#__PURE__*/_react["default"].createElement(_fdx.Select, {
        defaultValue: orderBy,
        style: {
          width: '100%'
        },
        onChange: function onChange(value) {
          _this2.setState({
            orderBy: value
          });
        }
      }, /*#__PURE__*/_react["default"].createElement(Option, {
        value: "Price"
      }, "Price"))), /*#__PURE__*/_react["default"].createElement(_fdx.Form.Item, {
        label: "Source of Product"
      }, /*#__PURE__*/_react["default"].createElement(_fdx.Select, {
        defaultValue: sourceUrl,
        style: {
          width: '100%'
        },
        onChange: function onChange(value) {
          _this2.setState({
            sourceUrl: value
          });
        }
      }, /*#__PURE__*/_react["default"].createElement(Option, {
        value: "flsale/next;flsale/offer"
      }, "Deal of The Day")))), /*#__PURE__*/_react["default"].createElement(_index2["default"], {
        onSaveClick: this.onSave
      }));
    }
  }]);

  return MFlashSalesProperties;
}(_MPropertiesBaseComponent["default"]);

exports["default"] = MFlashSalesProperties;