"use strict";

exports.__esModule = true;
exports["default"] = void 0;

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

var _propTypes = _interopRequireDefault(require("prop-types"));

var _instance = _interopRequireDefault(require("./instance.js"));

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

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

function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }

function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

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

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["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;
  };

  _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["default"].createElement("canvas", _extends({
      ref: function ref(el) {
        _this.$el = el;
      }
    }, others, {
      width: width,
      height: height
    }), "Canvas\u62BD\u5956\u8F6E\u76D8");
  };

  return LotteryWheel;
}(_react.Component);

exports["default"] = LotteryWheel;

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

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