'use strict';

exports.__esModule = true;
exports.default = undefined;

var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };

var _class, _temp;

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _propTypes = require('prop-types');

var _propTypes2 = _interopRequireDefault(_propTypes);

var _instance = require('./instance.js');

var _instance2 = _interopRequireDefault(_instance);

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

function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }

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 LotteryWheel = (_temp = _class = function (_Component) {
  _inherits(LotteryWheel, _Component);

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

    return _possibleConstructorReturn(this, _Component.call(this, props));
  }

  LotteryWheel.prototype.componentDidUpdate = function componentDidUpdate(prevProps) {
    if (JSON.stringify(prevProps.data) !== JSON.stringify(this.props.data)) {
      this.instance.params.data = this.props.data;
      this.instance.init();
    }
  };

  LotteryWheel.prototype.componentDidMount = function componentDidMount() {
    if (this.instance) return;
    var instance = new _instance2.default(this.$el, {
      // 间隔
      spacing: this.props.spacing,
      // 数据
      data: this.props.data,
      // 数据默认值
      font: this.props.font,
      fontTop: this.props.fontTop,
      fontFillStyle: this.props.fontFillStyle,

      bgFillStyle: this.props.bgFillStyle,
      bgStrokeStyle: this.props.bgStrokeStyle,
      bgLineWidth: this.props.bgLineWidth,

      iconWidth: this.props.iconWidth,
      iconHeight: this.props.iconHeight,
      iconTop: this.props.iconTop,

      around: this.props.around,
      // 保存
      suffix: this.props.suffix,
      quality: this.props.quality
    });
    this.instance = instance;
  };

  LotteryWheel.prototype.render = function render() {
    var _this2 = this;

    var _props = this.props,
        data = _props.data,
        fontFamily = _props.fontFamily,
        fontSize = _props.fontSize,
        fontTop = _props.fontTop,
        fontFillStyle = _props.fontFillStyle,
        bgFillStyle = _props.bgFillStyle,
        bgStrokeStyle = _props.bgStrokeStyle,
        bgLineWidth = _props.bgLineWidth,
        iconWidth = _props.iconWidth,
        iconHeight = _props.iconHeight,
        iconTop = _props.iconTop,
        around = _props.around,
        width = _props.width,
        height = _props.height,
        spacing = _props.spacing,
        suffix = _props.suffix,
        quality = _props.quality,
        others = _objectWithoutProperties(_props, ['data', 'fontFamily', 'fontSize', 'fontTop', 'fontFillStyle', 'bgFillStyle', 'bgStrokeStyle', 'bgLineWidth', 'iconWidth', 'iconHeight', 'iconTop', 'around', 'width', 'height', 'spacing', 'suffix', 'quality']);

    return _react2.default.createElement(
      'canvas',
      _extends({ ref: function ref(el) {
          _this2.$el = el;
        } }, others, { width: width, height: height }),
      'Canvas\u62BD\u5956\u8F6E\u76D8'
    );
  };

  return LotteryWheel;
}(_react.Component), _class.defaultProps = {}, _temp);
exports.default = LotteryWheel;
LotteryWheel.propTypes = process.env.NODE_ENV !== "production" ? {
  // 数据源
  data: _propTypes2.default.array, // [{text: '', icon: '', font: '', fontTop...同数据默认值}]
  // 数据默认值
  fontFamily: _propTypes2.default.string,
  fontSize: _propTypes2.default.number,
  fontTop: _propTypes2.default.number,
  fontFillStyle: _propTypes2.default.string,

  bgFillStyle: _propTypes2.default.string,
  bgStrokeStyle: _propTypes2.default.string,
  bgLineWidth: _propTypes2.default.number,

  iconWidth: _propTypes2.default.number,
  iconHeight: _propTypes2.default.number,
  iconTop: _propTypes2.default.number,

  around: _propTypes2.default.number, // 转动圈数, 默认转6圈
  // 不能使用style制定宽高,canvas用style的width|height会导致绘图位置不正确
  width: _propTypes2.default.number, // 宽度
  height: _propTypes2.default.number, // 高度
  // 间隔
  spacing: _propTypes2.default.number,
  // 保存
  suffix: _propTypes2.default.string,
  quality: _propTypes2.default.number
} : {};
module.exports = exports['default'];