var _excluded = ["data", "fontFamily", "fontSize", "fontTop", "fontFillStyle", "bgFillStyle", "bgStrokeStyle", "bgLineWidth", "iconWidth", "iconHeight", "iconTop", "around", "width", "height", "spacing", "suffix", "quality"];

function _extends() { _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; }; return _extends.apply(this, arguments); }

function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }

function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }

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

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 React, { Component } from 'react';
import PropTypes from 'prop-types';
import Instance from './instance.js';

var LotteryWheel = /*#__PURE__*/function (_Component) {
  _inheritsLoose(LotteryWheel, _Component);

  function LotteryWheel(props) {
    return _Component.call(this, props) || this;
  }

  var _proto = LotteryWheel.prototype;

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

  _proto.componentDidMount = function componentDidMount() {
    if (this.instance) return;
    var instance = new Instance(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;
  };

  _proto.render = function render() {
    var _this = this;

    var _this$props = this.props,
        data = _this$props.data,
        fontFamily = _this$props.fontFamily,
        fontSize = _this$props.fontSize,
        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,
        width = _this$props.width,
        height = _this$props.height,
        spacing = _this$props.spacing,
        suffix = _this$props.suffix,
        quality = _this$props.quality,
        others = _objectWithoutPropertiesLoose(_this$props, _excluded);

    return /*#__PURE__*/React.createElement("canvas", _extends({
      ref: function ref(el) {
        _this.$el = el;
      }
    }, others, {
      width: width,
      height: height
    }), "Canvas\u62BD\u5956\u8F6E\u76D8");
  };

  return LotteryWheel;
}(Component);

_defineProperty(LotteryWheel, "defaultProps", {});

export { LotteryWheel as default };
LotteryWheel.propTypes = process.env.NODE_ENV !== "production" ? {
  // 数据源
  data: PropTypes.array,
  // [{text: '', icon: '', font: '', fontTop...同数据默认值}]
  // 数据默认值
  fontFamily: PropTypes.string,
  fontSize: PropTypes.number,
  fontTop: PropTypes.number,
  fontFillStyle: PropTypes.string,
  bgFillStyle: PropTypes.string,
  bgStrokeStyle: PropTypes.string,
  bgLineWidth: PropTypes.number,
  iconWidth: PropTypes.number,
  iconHeight: PropTypes.number,
  iconTop: PropTypes.number,
  around: PropTypes.number,
  // 转动圈数, 默认转6圈
  // 不能使用style制定宽高,canvas用style的width|height会导致绘图位置不正确
  width: PropTypes.number,
  // 宽度
  height: PropTypes.number,
  // 高度
  // 间隔
  spacing: PropTypes.number,
  // 保存
  suffix: PropTypes.string,
  quality: PropTypes.number
} : {};