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 = ownKeys.concat(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); 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 } }); 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; } 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; }

import { Form, Input } from '@whalecloud/fdx';
import React from 'react';
import AddImgLink from '../components/AddImgLink/index';
import BottomButton from '../components/BottomButton/index';
import CommonStyle from '../components/CommonStyle/index';
import MPropertiesBaseComponent from '../MPropertiesBaseComponent';
import './index.less';

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

  var _super = _createSuper(GalaryTemplate4Properties);

  function GalaryTemplate4Properties(_props) {
    var _this;

    _classCallCheck(this, GalaryTemplate4Properties);

    _this = _super.call(this, _props);

    _defineProperty(_assertThisInitialized(_this), "resetProps", function (props) {
      _this.setState(_objectSpread({}, props, {
        imgList: props.imgList ? props.imgList : [],
        titleCot: props.titleCot ? props.titleCot : []
      }));
    });

    _defineProperty(_assertThisInitialized(_this), "uploadImgUrl", function (index, url) {
      var arr = JSON.parse(JSON.stringify(_this.state.imgList));
      arr[index].imgUrl = url;

      _this.setState({
        imgList: arr
      });
    });

    _defineProperty(_assertThisInitialized(_this), "setImgLink", function (index, value) {
      var arr = JSON.parse(JSON.stringify(_this.state.imgList));
      arr[index].link = value;

      _this.setState({
        imgList: arr
      });
    });

    _defineProperty(_assertThisInitialized(_this), "addNewItem", function () {
      _this.setState({
        imgList: [].concat(_toConsumableArray(_this.state.imgList), [{}])
      });
    });

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

    _defineProperty(_assertThisInitialized(_this), "delImg", function (index) {
      var arr = JSON.parse(JSON.stringify(_this.state.imgList));
      arr[index].imgUrl = '';

      _this.setState({
        imgList: arr
      });
    });

    _defineProperty(_assertThisInitialized(_this), "itemUp", function (index) {
      var arr = JSON.parse(JSON.stringify(_this.state.imgList));
      var _ref = [arr[index - 1], arr[index]];
      arr[index] = _ref[0];
      arr[index - 1] = _ref[1];

      _this.setState({
        imgList: arr
      });
    });

    _defineProperty(_assertThisInitialized(_this), "itemDown", function (index) {
      var arr = JSON.parse(JSON.stringify(_this.state.imgList));
      var _ref2 = [arr[index], arr[index + 1]];
      arr[index + 1] = _ref2[0];
      arr[index] = _ref2[1];

      _this.setState({
        imgList: arr
      });
    });

    _defineProperty(_assertThisInitialized(_this), "delItem", function (index) {
      console.log('object', index);
      var arr = JSON.parse(JSON.stringify(_this.state.imgList));
      arr.splice(index, 1);

      _this.setState({
        imgList: arr
      });
    });

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

    _this.state = _objectSpread({
      imgList: [],
      titleCot: ''
    }, _props);
    return _this;
  }

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

      console.log('props-4-img', this.props);
      return /*#__PURE__*/React.createElement("div", {
        className: "form-container"
      }, /*#__PURE__*/React.createElement(CommonStyle, {
        data: this.state.style,
        onChange: function onChange(data) {
          _this2.state.style = data;
        }
      }), /*#__PURE__*/React.createElement(Form, {
        layout: "vertical"
      }, /*#__PURE__*/React.createElement(Form.Item, {
        label: "Title"
      }, /*#__PURE__*/React.createElement(Input, {
        value: this.state.titleCot,
        onChange: function onChange(event) {
          event.persist();

          _this2.setState({
            titleCot: event.target.value
          });
        },
        placeholder: "please input"
      }))), /*#__PURE__*/React.createElement(AddImgLink, {
        hasPresaleTip: true,
        maxCount: 5,
        setImgLink: this.setImgLink,
        imgList: this.state.imgList,
        uploadImgUrl: this.uploadImgUrl,
        addNewItem: this.addNewItem,
        previewImg: this.previewImg,
        delImg: this.delImg,
        itemUp: this.itemUp,
        itemDown: this.itemDown,
        delItem: this.delItem,
        renderer: this.props.renderer
      }), /*#__PURE__*/React.createElement(BottomButton, {
        onSaveClick: this.onSave
      }));
    }
  }]);

  return GalaryTemplate4Properties;
}(MPropertiesBaseComponent);

export default GalaryTemplate4Properties;