"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports["default"] = void 0;
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _dialog = _interopRequireDefault(require("@alifd/next/lib/dialog"));
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
var React = _interopRequireWildcard(require("react"));
require("./index.scss");
var _LuckDrawSucc = _interopRequireDefault(require("../../../common/LuckDrawSucc"));
var _base = require("../../../../api/base");
var _utils = require("../../../../utils/utils");
var _shippingAddress = _interopRequireDefault(require("../../../common/shippingAddress"));
var _excluded = ["bgImgEgg", "bgImgSmart", "bgImgEggSize", "bgImgSmartSize", "bgOpacity", "bgSize", "bgPosition", "text", "font", "fontSize", "fontPosition", "fontColor", "fontOpacity", "btnOpacity", "btnSize", "btnFontFamily", "btnTextColor", "isclick"];
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; }
var activityId = _utils.$_GET.activityId,
  code = _utils.$_GET.code;
var GoldEgg = function GoldEgg(_ref) {
  var bgImgEgg = _ref.bgImgEgg,
    bgImgSmart = _ref.bgImgSmart,
    bgImgEggSize = _ref.bgImgEggSize,
    bgImgSmartSize = _ref.bgImgSmartSize,
    bgOpacity = _ref.bgOpacity,
    bgSize = _ref.bgSize,
    bgPosition = _ref.bgPosition,
    text = _ref.text,
    font = _ref.font,
    fontSize = _ref.fontSize,
    fontPosition = _ref.fontPosition,
    fontColor = _ref.fontColor,
    fontOpacity = _ref.fontOpacity,
    btnOpacity = _ref.btnOpacity,
    btnSize = _ref.btnSize,
    btnFontFamily = _ref.btnFontFamily,
    btnTextColor = _ref.btnTextColor,
    isclick = _ref.isclick,
    otherProps = (0, _objectWithoutPropertiesLoose2["default"])(_ref, _excluded);
  var _split = (fontPosition || 'cc').split(''),
    fontH = _split[0],
    fontV = _split[1];
  var fontTextCss = {
    opacity: fontOpacity / 100,
    color: fontColor,
    fontSize: fontSize + "px",
    fontFamily: font
  };
  switch (fontH) {
    case 'l':
      Object.assign(fontTextCss, {
        left: '2%'
      });
      break;
    case 'r':
      Object.assign(fontTextCss, {
        right: '2%'
      });
      break;
    case 'c':
      Object.assign(fontTextCss, {
        transform: 'translateX(-50%)'
      });
    // eslint-disable-next-line no-fallthrough

    default:
      Object.assign(fontTextCss, {
        left: '50%'
      });
  }
  switch (fontV) {
    case 't':
      Object.assign(fontTextCss, {
        top: '2%'
      });
      break;
    case 'b':
      Object.assign(fontTextCss, {
        bottom: '2%'
      });
      break;
    case 'c':
      Object.assign(fontTextCss, {
        transform: 'translateY(-50%)'
      });
    // eslint-disable-next-line no-fallthrough

    default:
      Object.assign(fontTextCss, {
        top: '50%'
      });
      break;
  }
  if (fontPosition === 'cc') Object.assign(fontTextCss, {
    transform: 'translate(-50%)'
  });

  // transform: rotate(45deg);

  var _split2 = (bgPosition || 'cc').split(''),
    bgH = _split2[0],
    bgV = _split2[1];
  var justifyContent = {
    l: 'flex-start',
    c: 'center',
    r: 'flex-end'
  };
  var alignItems = {
    t: 'flex-start',
    c: 'center',
    b: 'flex-end'
  };
  // console.log(bgH, bgV);
  var _useState = (0, React.useState)({
      isChecked: false,
      isOpenPrize: false,
      openAddress: false,
      activityId: activityId,
      singerID: '',
      drawMessage: '',
      countPrized: '3'
    }),
    state = _useState[0],
    setState = _useState[1];
  var btnState = function btnState() {
    setState({
      // countPrized: state.countPrized,
      isOpenPrize: !state.isOpenPrize
    });
  };

  // const start = async (): Promise<void> => {

  //   await trans()
  // }

  // const postData = async (): Promise<void> => {

  // }

  // const
  var loginWechat = function loginWechat() {
    window.location.href = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + _utils.getWxAppid + "&redirect_uri=" + encodeURIComponent(window.location.href) + "&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect";
  };
  var drawFun = /*#__PURE__*/function () {
    var _ref2 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee() {
      return _regenerator["default"].wrap(function _callee$(_context) {
        while (1) {
          switch (_context.prev = _context.next) {
            case 0:
            case "end":
              return _context.stop();
          }
        }
      }, _callee);
    }));
    return function drawFun() {
      return _ref2.apply(this, arguments);
    };
  }();
  var trans = /*#__PURE__*/function () {
    var _ref3 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2() {
      var _yield$lottery, data, f, ce;
      return _regenerator["default"].wrap(function _callee2$(_context2) {
        while (1) {
          switch (_context2.prev = _context2.next) {
            case 0:
              if (code) {
                _context2.next = 4;
                break;
              }
              loginWechat();
              _context2.next = 13;
              break;
            case 4:
              _context2.next = 6;
              return (0, _base.lottery)({
                b: activityId
              });
            case 6:
              _yield$lottery = _context2.sent;
              data = _yield$lottery.data;
              f = data.f, ce = data.ce;
              setState({
                drawMessage: data,
                singerID: data.a
              });
              _dialog["default"].confirm({
                v2: true,
                title: '提示',
                content: f ? "\u606D\u559C\u60A8\u4E2D\u5956\u5566-\u5956\u54C1: " + ce : '很遗憾: 谢谢您的参与',
                messageProps: {
                  type: f ? 'success' : 'warning'
                },
                onOk: function onOk() {
                  return f ? setState({
                    isChecked: false,
                    openAddress: true
                  }) : setState({
                    isChecked: false
                  });
                }
              });

              //
              // console.log("这是传递过来的东西isclick", isclick)
              //
              // if (Number(state.countPrized) < 1) {
              //     Message.error('你剩余的抽奖次数已用完。');
              //     return;
              // }
              setState({
                isChecked: true
                // isOpen: false,
              });

              setTimeout(function () {
                setState({
                  //         isOpen: true,
                  isChecked: false
                  //         countPrized: (Number(state.countPrized) - 1).toString(),
                });
              }, 1000);
              // setTimeout(() => {
              //   setState({
              //     ...state,
              //     isOpenPrize: !state.isOpenPrize
              //   });
              // }, 3000)
            case 13:
            case "end":
              return _context2.stop();
          }
        }
      }, _callee2);
    }));
    return function trans() {
      return _ref3.apply(this, arguments);
    };
  }();
  var container = {
    style: {
      opacity: bgOpacity / 100,
      width: "100%",
      overflow: "auto"
    }
  };
  var SmartStyle = {
    style: {
      backgroundRepeat: "no-repeat",
      backgroundImage: "url(" + bgImgSmart + "?imageMogr2/interlace/1)",
      backgroundSize: bgImgSmartSize + "%"
    }
  };
  var _otherProps = Object.assign({
    container: container
  }, otherProps) || {};
  // const btnStyle = {
  //   style: {
  //     opacity: btnOpacity / 100,
  //     fontSize: `${btnSize}px`,
  //     fontFamily: btnFontFamily,
  //     position: 'relative',
  //     color: btnTextColor,
  //   },
  // };
  var eggPOsition = {
    style: {
      display: 'flex',
      flexDirection: 'row',
      justifyContent: justifyContent[bgH],
      alignItems: alignItems[bgV]
    }
  };
  var prizeTextList = {
    icon: 'prize',
    msg: '恭喜您中奖啦!',
    // msg: '很遗憾空无一物',
    prizeLv: ['特等奖', '冬奥冰墩墩钥匙扣 × 1']
    // prizeLv: ['谢谢参于', '']
  };

  var isOpenPrize = state.isOpenPrize;
  var EggStyle = {
    style: {
      backgroundRepeat: "no-repeat",
      backgroundImage: "url(" + bgImgEgg + "?imageMogr2/interlace/1)",
      backgroundSize: bgImgEggSize + "%",
      cursor: "pointer"
    }
  };
  var EggOpenStyle = {
    style: {
      backgroundRepeat: "no-repeat",
      backgroundImage: "url(https://img.maimairen.com/low-code/components/golden-eggs/egg-open1.gif)"
    }
  };
  // 默认金蛋
  var defaultEgg = /*#__PURE__*/React.createElement("div", (0, _extends2["default"])({
    className: "egg-g"
  }, EggStyle, {
    onClick: trans
  }));
  // 砸开的金蛋
  var openEgg = /*#__PURE__*/React.createElement("div", (0, _extends2["default"])({
    className: "egg-gs"
  }, EggOpenStyle));
  return /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("div", (0, _extends2["default"])({
    className: "egg"
  }, _otherProps.container, _otherProps), /*#__PURE__*/React.createElement(_LuckDrawSucc["default"], {
    btnState: btnState,
    prizeTextList: prizeTextList,
    isOpenPrize: isOpenPrize
  }), /*#__PURE__*/React.createElement("div", (0, _extends2["default"])({
    style: {
      fontSize: '48px'
    }
  }, eggPOsition), /*#__PURE__*/React.createElement("div", {
    className: "eggPosition"
  }, /*#__PURE__*/React.createElement("div", {
    className: "eggBorder"
  }, state !== null && state !== void 0 && state.isOpen ? openEgg : defaultEgg, /*#__PURE__*/React.createElement("div", (0, _extends2["default"])({
    className: state !== null && state !== void 0 && state.isChecked ? 'egg-T egg-attacded' : 'egg-T'
  }, SmartStyle), state === null || state === void 0 ? void 0 : state.isChecked))))), /*#__PURE__*/React.createElement(_shippingAddress["default"], {
    touchState: state.openAddress,
    drawMessage: JSON.stringify(state.drawMessage),
    activityId: state.activityId,
    singerID: state.singerID
  }));
};
var _default = GoldEgg;
exports["default"] = _default;