'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = undefined;

var _createClass = 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); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _reactDom = require('react-dom');

var _imageLink = require('../constant/imageLink');

var _imageLink2 = _interopRequireDefault(_imageLink);

var _mxa = require('../../components/mxa');

var _home = require('../styles/views/home.less');

var _home2 = _interopRequireDefault(_home);

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

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

function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }

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

var ShortcutMenu = function (_React$Component) {
  _inherits(ShortcutMenu, _React$Component);

  function ShortcutMenu(props) {
    _classCallCheck(this, ShortcutMenu);

    var _this = _possibleConstructorReturn(this, (ShortcutMenu.__proto__ || Object.getPrototypeOf(ShortcutMenu)).call(this, props));

    _this.editMenu = function () {
      var menu = (0, _reactDom.findDOMNode)(_this);
      console.log(menu);
      _this.setState({ menuType: 'edit' });
    };

    _this.saveShortMenuList = function () {
      _this.setState({ menuType: 'readOnly' });
    };

    _this.deleteShortMenuItem = function (key) {
      console.log(key);

      var newData = _this.state.dataSource.filter(function (item) {
        return item.key !== key;
      });
      _this.setState({
        dataSource: newData
      });
    };

    _this.renderEditButton = function () {
      if (_this.state.menuType === 'readOnly') {
        return _react2.default.createElement(
          'a',
          { onClick: function onClick() {
              return _this.editMenu();
            }, className: _home2.default.editButton },
          _react2.default.createElement('img', { src: _imageLink2.default.home_shortmenu_edit, alt: '\u7F16\u8F91' })
        );
      }
      return _react2.default.createElement(
        _mxa.Button,
        { type: 'primary', size: 'small', onClick: function onClick() {
            return _this.saveShortMenuList();
          }, className: _home2.default.editButton },
        '\u4FDD\u5B58'
      );
    };

    _this.renderMenuItem = function () {
      var dataSource = _this.state.dataSource;
      if (_this.state.menuType === 'readOnly' && dataSource) {
        return dataSource.map(function (item) {
          return _react2.default.createElement(
            _mxa.Button,
            { key: item.key, type: 'ghost', className: _home2.default.menuButton },
            item.menuText
          );
        });
      }
      return dataSource.map(function (item) {
        return _react2.default.createElement(
          _mxa.Button,
          { key: item.key, type: 'dashed', className: _home2.default.menuButton, onClick: function onClick() {
              return _this.deleteShortMenuItem(item.key);
            } },
          item.menuText + '    ',
          _react2.default.createElement(
            'div',
            { className: _home2.default.iconRight },
            _react2.default.createElement(_mxa.Icon, { type: 'close-circle' })
          )
        );
      });
    };

    _this.renderAddButton = function () {
      if (_this.state.dataSource.length < 8) {
        return _react2.default.createElement(
          _mxa.Button,
          { type: 'ghost', className: _home2.default.menuButton },
          _react2.default.createElement('img', { src: _imageLink2.default.home_shortmenu_add, alt: '\u65B0\u589E' })
        );
      }
      return null;
    };

    _this.state = {
      menuType: 'readOnly',
      dataSource: [{
        key: 1,
        menuText: '客户管理',
        link: '/leaseeManage'
      }, {
        key: 2,
        menuText: '合同管理',
        link: '/leaseeManage'
      }, {
        key: 3,
        menuText: '风险管理',
        link: '/leaseeManage'
      }, {
        key: 4,
        menuText: '客户管理',
        link: '/leaseeManage'
      }, {
        key: 5,
        menuText: '合同管理',
        link: '/leaseeManage'
      }, {
        key: 6,
        menuText: '风险管理',
        link: '/leaseeManage'
      }, {
        key: 7,
        menuText: '合同管理',
        link: '/leaseeManage'
      }]
    };
    return _this;
  }

  _createClass(ShortcutMenu, [{
    key: 'render',
    value: function render() {
      return _react2.default.createElement(
        'div',
        { className: _home2.default.shortcutMenu },
        _react2.default.createElement(
          _mxa.Row,
          { type: 'flex', align: 'middle', justify: 'start', className: _home2.default.commonTitle },
          _react2.default.createElement(
            _mxa.Col,
            { span: 12 },
            _react2.default.createElement(
              _mxa.Row,
              { type: 'flex', align: 'middle', justify: 'start' },
              _react2.default.createElement('span', { className: _home2.default.highLight }),
              _react2.default.createElement(
                'p',
                null,
                '\u5FEB\u6377\u83DC\u5355'
              )
            )
          ),
          _react2.default.createElement(
            _mxa.Col,
            { span: 12 },
            _react2.default.createElement(
              _mxa.Row,
              { type: 'flex', align: 'middle', justify: 'end' },
              this.renderEditButton()
            )
          )
        ),
        _react2.default.createElement(
          _mxa.Row,
          { type: 'flex', align: 'center', justify: 'center' },
          this.renderMenuItem(),
          this.renderAddButton()
        )
      );
    }
  }]);

  return ShortcutMenu;
}(_react2.default.Component);

exports.default = ShortcutMenu;
//# sourceMappingURL=ShortcutMenu.js.map