"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.MySlotMachineChild = void 0;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _message = _interopRequireDefault(require("@alifd/next/lib/message"));
var _inheritsLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/inheritsLoose"));
var _indexModule = _interopRequireDefault(require("./index.module.scss"));
var React = _interopRequireWildcard(require("react"));
var _react2 = require("@lucky-canvas/react");
var _index = _interopRequireDefault(require("../../common/shippingAddress/index"));
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; }
// <koiSlotMachinProps>  换成any
var MySlotMachineChild = /*#__PURE__*/function (_Component) {
  (0, _inheritsLoose2["default"])(MySlotMachineChild, _Component);
  function MySlotMachineChild(props) {
    var _this;
    _this = _Component.call(this, props) || this;
    _this.onGetPrize = function () {
      _this.setState(function (prev) {
        return {
          writeMessage: !prev.writeMessage,
          isTicket: true,
          title: '',
          icon: '',
          message: ''
        };
      });
    };
    _this.onisClick = function () {
      var isClick = _this.state.isClick;
      _this.setState({
        isClick: !isClick
      });
    };
    _this.onisTicket = function (prize) {
      var isTicket = _this.state.isTicket;
      _this.setState({
        isTicket: !isTicket,
        title: prize.title,
        icon: prize.icon,
        message: prize.message
      });
    };
    _this.onStarts = function () {
      // 开始先全部清空
      if (_this.state.count > 0) {
        // const count = this.state.count
        _this.setState(function (prev) {
          return {
            isTicket: true,
            title: '',
            icon: '',
            message: '',
            count: prev.count - 1,
            writeMessage: false
          };
        });
        _this.onisClick();
        _this.myMachin.current.play();
        setTimeout(function () {
          var index = Math.random() * 6 >> 0;
          _this.myMachin.current.stop(index);
        }, 2500);
      } else {
        return _message["default"].error('你剩余的抽奖次数已用完。');
      }
    };
    _this.myMachin = /*#__PURE__*/React.createRef();
    _this.state = {
      // 抽奖次数
      count: 3,
      isClick: true,
      isTicket: true,
      title: '',
      icon: '',
      message: '',
      writeMessage: false
    };
    return _this;
  }
  var _proto = MySlotMachineChild.prototype;
  _proto.componentDidMount = function componentDidMount() {}
  // 修改老虎机点击isClick
  ;
  _proto.render = function render() {
    var _this2 = this;
    var data = this.props.data;
    var container = {
      width: "100%",
      overflow: "auto"
    };
    var imgopacity = {
      opacity: data.bgOpacity / 100
    };
    var SlotMachineStyle = {
      style: {
        display: "flex",
        flexDirection: "column",
        justifyContent: "center" /* 水平居中 */,
        alignItems: "center" /* 垂直居中 */,
        paddingTop: "3.7vh" /* 看着太大，除以2 */,
        paddingBottom: "8.65vh" /* 看着太大，除以2 */
      }
    };

    var blocks = [
      // {
      //     imgs: [
      //         {
      //             src: 'https://img.maimairen.com/low-code/components/SlotMachine/tiger.png',
      //             // 图片位置
      //             width: '100%',
      //             height: '100%',
      //         }
      //     ]
      // },
      // // 这里的padding 规则是上下左右，别改动，好不容易调好的
      // { padding: '5.8vw 18.3vw 5.8vw 5.8vw' }
    ];
    var prizes = [{
      // background: '#ffffff',
      // background: '#007acc',
      // background: 'linear-gradient(to bottom, #333, #333 5%, #eee 50%, #333 102%);',
      // fonts: [
      //     {
      //         text: '王冠',
      //         fontSize: data.MachinePrizeFontSize,
      //         fontStyle: data.MachinePrizeFontFamily,
      //         fontColor: '#F58B33',
      //         top: `${data.MachinePrizeFontTop}%`,
      //     },
      // ],
      message: '抽中了一等奖   iphone 13一台',
      imgs: [{
        src: '//img.maimairen.com/low-code/components/slot001/level.png',
        width: data.MachinePrizeImgWidth + "%",
        top: (data.MachinePrizeImgTop ? data.MachinePrizeImgTop : 27) + "%"
      }]
    }, {
      message: '抽中了二等奖   100积分',
      imgs: [{
        src: '//img.maimairen.com/low-code/components/slot001/housand.png',
        width: data.MachinePrizeImgWidth + "%",
        top: (data.MachinePrizeImgTop ? data.MachinePrizeImgTop : 27) + "%"
      }]
    }, {
      message: '抽中了二等奖   100金豆',
      imgs: [{
        src: '//img.maimairen.com/low-code/components/prize-list001/bean5.png',
        width: data.MachinePrizeImgWidth + "%",
        top: (data.MachinePrizeImgTop ? data.MachinePrizeImgTop : 27) + "%"
      }]
    }];
    var defaultConfig = {
      // 设置每个格子间隔
      // rowSpacing: '6.5em',
      rowSpacing: '-1px',
      colSpacing: '1em'
    };
    var slots = [{
      order: [0, 1, 2],
      speed: data.prizeSpeed
    }, {
      order: [0, 1, 2],
      speed: data.prizeSpeed
    }, {
      order: [0, 2, 1],
      speed: data.prizeSpeed
    }];
    // const slots = [{
    //     // 奖品排列顺序  默认所有奖品
    //     // order:
    //     speed: 30,
    //     // 1是正方向 -1是反方向
    //     direction: 1
    // }]
    var _allMachineStyle = {
      style: {
        wdith: data.SlotMachineWidth + "vw",
        height: data.SlotMachineWidth * 0.8 + "vw"
      }
    };
    var _onEnd = function onEnd(prize) {
      var TD = {
        title: '恭喜你',
        message: prize.message,
        icon: prize.imgs[0].src
      };
      _this2.onisTicket(TD);
      _this2.onisClick();
      // this.props.btnState(prize, "恭喜中奖了");
      // alert(`恭喜你抽到 ${prize.fonts[0].text} 号奖品`);
    };

    var thaks = function thaks() {
      var TD = {
        title: '很遗憾',
        message: '此次没有中奖',
        icon: '//img.maimairen.com/low-code/components/marquee/xiatu01.png'
      };
      _this2.onisTicket(TD);
      _this2.onisClick();
      // const prize = { imgs: [{ src: "//img.maimairen.com/low-code/components/marquee/xiatu01.png" }], fonts: [{ text: "谢谢参与" }] };
      // this.props.btnState(prize, "");
    };

    var clickBtn = function clickBtn(state) {
      var btnActive = state;
      var btn = '//img.maimairen.com/low-code/components/slot001/btn.png';
      var btnGif = '//img.maimairen.com/low-code/components/slot001/btn.gif';
      if (btnActive) {
        return /*#__PURE__*/React.createElement("div", {
          className: _indexModule["default"]['btn-box']
        }, /*#__PURE__*/React.createElement("img", {
          src: btn
        }));
      } else {
        return /*#__PURE__*/React.createElement("div", {
          className: _indexModule["default"]['btn-box']
        }, /*#__PURE__*/React.createElement("img", {
          src: btnGif
        }));
      }
    };
    return /*#__PURE__*/React.createElement("div", {
      className: _indexModule["default"]['block-container']
    }, /*#__PURE__*/React.createElement("div", {
      className: _indexModule["default"].bigWheel,
      style: (0, _extends2["default"])({}, container, imgopacity)
    }, this.props.children, /*#__PURE__*/React.createElement("div", {
      className: _indexModule["default"]['bigWheel-content']
    }, /*#__PURE__*/React.createElement("div", {
      style: (0, _extends2["default"])({}, SlotMachineStyle)
    }, /*#__PURE__*/React.createElement("div", {
      className: _indexModule["default"].allMachineStyle,
      style: (0, _extends2["default"])({}, _allMachineStyle)
    }, /*#__PURE__*/React.createElement("div", {
      className: _indexModule["default"].SlotMachineBG
    }, /*#__PURE__*/React.createElement("img", {
      src: data.chooseImg.src1,
      className: _indexModule["default"].img
    }), /*#__PURE__*/React.createElement("div", {
      className: _indexModule["default"].title
    }, /*#__PURE__*/React.createElement("div", {
      className: _indexModule["default"].count
    }, this.state.count), /*#__PURE__*/React.createElement("div", {
      className: _indexModule["default"]['count-message']
    }, "\u4ECA\u65E5\u5269\u4F59\u62BD\u5956\u6B21\u6570")), /*#__PURE__*/React.createElement("div", {
      className: _indexModule["default"].btn,
      onClick: this.onStarts
    }, this.state.isClick ? clickBtn(true) : clickBtn(false)), /*#__PURE__*/React.createElement("div", {
      className: _indexModule["default"].mask
    }, /*#__PURE__*/React.createElement(_react2.SlotMachine, {
      ref: this.myMachin
      // width={`55.8vw`}
      // height={`28vw`}
      ,
      blocks: blocks,
      prizes: prizes,
      slots: slots,
      defaultConfig: defaultConfig,
      onEnd: function onEnd(prize) {
        prize ? _onEnd(prize) : thaks();
      }
    })), /*#__PURE__*/React.createElement("div", {
      className: _indexModule["default"].windows
    }, /*#__PURE__*/React.createElement("img", {
      src: data.chooseImg.src2,
      className: _indexModule["default"]['windows-img']
    })), /*#__PURE__*/React.createElement("div", {
      className: _indexModule["default"][this.state.isTicket ? 'noTicket' : 'ticket']
    }, /*#__PURE__*/React.createElement("div", {
      className: _indexModule["default"].textDescription
    }, /*#__PURE__*/React.createElement("div", {
      className: _indexModule["default"].title
    }, this.state.title), /*#__PURE__*/React.createElement("div", {
      className: _indexModule["default"][this.state.icon ? 'icon' : 'noIcon']
    }, /*#__PURE__*/React.createElement("img", {
      src: this.state.icon
    })), /*#__PURE__*/React.createElement("div", {
      className: _indexModule["default"].message
    }, this.state.message), /*#__PURE__*/React.createElement("div", {
      className: _indexModule["default"][this.state.icon ? 'getBtn' : 'noIcon']
    }, /*#__PURE__*/React.createElement("div", {
      className: _indexModule["default"].outer
    }, this.state.title === '很遗憾' ? /*#__PURE__*/React.createElement("div", {
      className: _indexModule["default"].inner,
      onClick: this.onStarts
    }, "\u518D\u73A9\u4E00\u6B21") : /*#__PURE__*/React.createElement("div", {
      className: _indexModule["default"].inner,
      onClick: this.onGetPrize
    }, "\u9886\u53D6\u5956\u54C1")))))))), this.state.writeMessage ? /*#__PURE__*/React.createElement(_index["default"], {
      data: {
        touchState: true,
        mustName: false,
        mustPhone: true,
        mustEmail: true
      }
    }) : null)));
  };
  return MySlotMachineChild;
}(React.Component);
exports.MySlotMachineChild = MySlotMachineChild;
MySlotMachineChild.displayName = 'MySlotMachineChild';