System.register(["__unresolved_0", "cc", "__unresolved_1", "__unresolved_2"], function (_export, _context) {
  "use strict";

  var _reporterNs, _cclegacy, constants, utils, PlatformWX, _crd, WX_CONFIG, delayTime;

  function _reportPossibleCrUseOfconstants(extras) {
    _reporterNs.report("constants", "../data/constants", _context.meta, extras);
  }

  function _reportPossibleCrUseOfutils(extras) {
    _reporterNs.report("utils", "../data/utils", _context.meta, extras);
  }

  return {
    setters: [function (_unresolved_) {
      _reporterNs = _unresolved_;
    }, function (_cc) {
      _cclegacy = _cc.cclegacy;
    }, function (_unresolved_2) {
      constants = _unresolved_2.constants;
    }, function (_unresolved_3) {
      utils = _unresolved_3.utils;
    }],
    execute: function () {
      _crd = true;

      _cclegacy._RF.push({}, "ef013qcT+5IAYjrcLFqwA9m", "platformWX", undefined);

      WX_CONFIG = {
        AD_ID: {
          /** banner广告 */
          banner: 'adunit-fa7b08ac6d8cf200',

          /** 视频广告 */
          video: 'adunit-29b5f0955ee77f59',

          /** 插屏广告 */
          interstitial: 'adunit-a3615ebe31eba64a',

          /** 原生模板多个格子广告 */
          multiGridCustom: 'adunit-xxx',

          /** 原生模版单格格子广告 */
          sigleGridCustom: 'adunit-d4f43001efd879de'
        }
      };
      delayTime = 1900;
      PlatformWX = class PlatformWX {
        constructor() {
          this._onHideTime = Infinity;
          this._rewardVideo = void 0;
          this._bannerAd = void 0;
          this._interstitialAd = void 0;
          this._customAd = void 0;
          this._sigleCustomAd = void 0;
          this._shareSuccessHandler = null;
          this._videoSuccessHandler = null;
          this._customAdCloseHandler = null;
          this._showInterstitialAdTime = null;
          this._shareModalIsActive = false;
          this._shareStr = "东北F4来到美国西部拓荒时代，保卫城镇，完成自我救赎。";
        }

        initialize() {
          console.log("初始化微信框架");
          wx.showShareMenu({
            withShareTicket: true,
            menus: ['shareAppMessage', 'shareTimeline'],
            success: () => {},
            fail: () => {},
            complete: () => {}
          }); //发送给朋友

          wx.onShareAppMessage(function () {
            wx.shareAppMessage({
              imageUrl: "share.jpg",
              title: this._shareStr,
              query: 'shareMsg=' + 'a=1'
            });
          }.bind(this));
          wx.onShow(res => {
            if (this._shareSuccessHandler == null) return;
            if (this._shareModalIsActive) return;

            if (Date.now() - this._onHideTime >= delayTime) {
              if (this._shareSuccessHandler) this._shareSuccessHandler(true);
            } else {
              wx.showModal({
                title: '分享提示',
                content: '成功分享到群即可获得奖励',
                success: res => {
                  if (res.confirm) {
                    this.shareShowReward(this._shareSuccessHandler(false));
                  } else if (res.cancel) {
                    this._shareSuccessHandler = null;
                  }

                  this._shareModalIsActive = false;
                }
              });
              this._shareModalIsActive = true;
            }

            this._onHideTime = Infinity;
          }); //this.__createBannerAd();

          this.__createVideoAd(); //this.__createCustomAd();
          //this.__createSigleCustomAd();
          //this.__createInterstitialAd();
          //this.__customAdExist();
          //this.__customSigleAdExist();

        }

        showToast(param) {
          var finalParam = {
            title: '',
            icon: 'none',
            duration: 2000
          };
          Object.assign(finalParam, param);
          wx.showToast(finalParam);
        }

        shareAppMessage(param) {
          if (param === void 0) {
            param = {};
          }

          wx.shareAppMessage(param);
        }

        vibrateShort(param) {
          if (param === void 0) {
            param = {};
          }

          wx.vibrateShort(param);
        }

        vibrateLong(param) {
          if (param === void 0) {
            param = {};
          }

          wx.vibrateLong(param);
        }
        /**
         * 是否支持添加桌面
         * @returns 
         */


        isSupportDesk() {
          //@ts-ignore
          if (wx.canAddToFavorites) {
            return true;
          } else {
            return false;
          }
        } //添加到桌面


        addDesk() {
          //@ts-ignore
          if (wx.canAddToFavorites) {
            //@ts-ignore
            wx.canAddToFavorites({
              success(res) {
                if (res.canAdd) {
                  //可以添加到桌面
                  //@ts-ignore
                  wx.addToFavorites({
                    // 小程序的相关信息
                    title: (_crd && constants === void 0 ? (_reportPossibleCrUseOfconstants({
                      error: Error()
                    }), constants) : constants).gameName,
                    query: '',

                    // 可以携带参数
                    success() {
                      this.showToast({
                        title: '添加到桌面成功'
                      });
                    },

                    fail(err) {
                      this.showToast({
                        title: '添加到桌面失败',
                        err
                      });
                    }

                  });
                } else {
                  // 不支持添加到桌面
                  this.showToast({
                    title: '当前环境不支持添加到桌面'
                  });
                }
              },

              fail(err) {
                this.showToast({
                  title: '检查添加到桌面权限失败',
                  err
                });
              }

            });
          } else {
            this.showToast({
              title: "当前环境不支持添加到桌面"
            });
          }
        } //分享


        shareShowReward(handler) {
          if (handler === void 0) {
            handler = null;
          }

          if (handler) {
            this._shareSuccessHandler = handler;
          }

          this._onHideTime = Date.now();
          this.shareAppMessage({
            imageUrl: "share.jpg",
            title: this._shareStr,
            query: 'shareMsg=' + 'a=1'
          });
        }

        showRewardVideo(handler) {
          if (handler === void 0) {
            handler = null;
          }

          //console.log('当日视频次数： ', ArchiveSystem.localData.videoRewardTimesToday);

          /*if (ArchiveSystem.localData.videoRewardTimesToday % 2 === 1) {
              cc.log(ArchiveSystem.localData.videoRewardTimesToday, '转为分享');
              this.__turnVideoToShare(handler);
              return;
          }*/
          if (!this._rewardVideo) {
            this.__turnVideoToShare(handler);

            return;
          }

          this._videoSuccessHandler = handler;

          this._rewardVideo.show().then(() => {
            console.log("视频播放成功");
          }).catch(err => {
            this._rewardVideo.load().then(() => {
              this._rewardVideo.show().then(() => {
                console.log("视频重新加载，播放成功");
              });
            }).catch(err2 => {
              var _this$_videoSuccessHa;

              (_this$_videoSuccessHa = this._videoSuccessHandler) == null ? void 0 : _this$_videoSuccessHa.call(this, false);
              this.shareShowReward(handler);
              this._videoSuccessHandler = null;
            });
          });
        }

        showBannerAd() {
          if (!this._bannerAd) return;
          var {
            screenWidth,
            screenHeight
          } = wx.getSystemInfoSync();

          this._bannerAd.show().then(() => {
            this._bannerAd.style.left = (screenWidth - this._bannerAd.style.realWidth) / 2;
            this._bannerAd.style.top = screenHeight - this._bannerAd.style.realHeight;
          }).catch(e => {
            console.log('banner广告显示出错', e);
          });
        }

        hideBannerAd(recreate) {
          if (recreate === void 0) {
            recreate = false;
          }

          if (!this._bannerAd) return;

          this._bannerAd.hide();

          if (recreate) {
            this.refreshBannerAd();
          }
        }

        refreshBannerAd() {
          if (!this._bannerAd) return;

          this._bannerAd.destroy();

          this.__createBannerAd();
        }

        showInterstitialAd(force) {
          if (force === void 0) {
            force = false;
          }

          if (force) {
            if (!this._interstitialAd) return;

            this._interstitialAd.show();
          } else {
            if (!this._interstitialAd) return;
            var timeNow = Date.now();

            if (this._showInterstitialAdTime == null) {
              this._showInterstitialAdTime = timeNow;
              return;
            }

            if (timeNow - this._showInterstitialAdTime > 120 * 1000) {
              this._interstitialAd.show();

              this._showInterstitialAdTime = timeNow;
            }
          }
        }

        showCustomAd(close) {
          if (!this._customAd) return;
          this._customAdCloseHandler = close;

          this._customAd.show().catch(e => {
            console.log('原生广告显示出错', e);
          });
        }

        hideCustomAd() {
          if (!this._customAd) return;

          this._customAd.hide().catch(e => {
            console.log('原生广告隐藏出错', e);
          });
        }

        showSigleCustomAd() {
          if (!this._sigleCustomAd || false) return;

          this._sigleCustomAd.show().catch(e => {
            console.log('原生当个格子广告显示出错', e);
          });
        }

        hideSigleCustomAd() {
          if (!this._sigleCustomAd || false) return;

          this._sigleCustomAd.hide().catch(e => {
            console.log('隐藏单个格子广告出错', e);
          });
        }
        /**单个格子广告*/


        __customSigleAdExist() {
          if (!this._sigleCustomAd) {
            this.__createSigleCustomAd();
          }

          this._sigleCustomAd.show().then(() => {
            if (this._sigleCustomAd.isShow()) {
              this.hideSigleCustomAd();
            }
          }).catch(res => {
            if (this._sigleCustomAd.isShow()) {
              this.hideSigleCustomAd();
            }
          });
        }
        /**多个格子广告*/


        __customAdExist() {
          if (!this._customAd) {
            this.__createCustomAd();
          }

          this._customAd.show().then(() => {
            if (this._customAd.isShow()) {
              this.hideCustomAd();
            }
          }).catch(res => {
            if (this._customAd.isShow()) {
              this.hideCustomAd();
            }
          });
        }

        exitGame() {
          wx.exitMiniProgram({});
        }

        __createVideoAd() {
          if (!WX_CONFIG.AD_ID.video) return;
          this._rewardVideo = wx.createRewardedVideoAd({
            adUnitId: WX_CONFIG.AD_ID.video
          }); // 注册视频的onClose事件

          this._rewardVideo.onClose(res => {
            if (res && res.isEnded || res === undefined) {
              var _this$_videoSuccessHa2;

              (_this$_videoSuccessHa2 = this._videoSuccessHandler) == null ? void 0 : _this$_videoSuccessHa2.call(this, true);
            } else {
              var _this$_videoSuccessHa3;

              this.showToast({
                title: "完整观看视频才有奖励哦"
              });
              (_this$_videoSuccessHa3 = this._videoSuccessHandler) == null ? void 0 : _this$_videoSuccessHa3.call(this, false);
            }

            this._videoSuccessHandler = null;
          }); // 注册视频的onError事件


          this._rewardVideo.onError(res => {
            var _this$_videoSuccessHa4;

            (_this$_videoSuccessHa4 = this._videoSuccessHandler) == null ? void 0 : _this$_videoSuccessHa4.call(this, false);
            this.showToast({
              title: "暂时没有可观看的视频"
            });
            this.shareShowReward(this._videoSuccessHandler);
            this._videoSuccessHandler = null;
          });
        }

        __createBannerAd() {
          if (!WX_CONFIG.AD_ID.banner) return;
          var info = wx.getSystemInfoSync();
          var f = (_crd && utils === void 0 ? (_reportPossibleCrUseOfutils({
            error: Error()
          }), utils) : utils).isNormalScreen();
          var w = f ? info.screenWidth * 0.85 : info.screenWidth * 0.85;
          this._bannerAd = wx.createBannerAd({
            adUnitId: WX_CONFIG.AD_ID.banner,
            adIntervals: 48,
            style: {
              left: 0,
              top: info.screenHeight,
              width: w,
              height: 70 //w * (f ? 0.48 : 0.5) //原始0

            }
          });

          this._bannerAd.onError(err => {
            switch (err.errCode) {
              case 1001:
                {
                  break;
                }

              case 1004:
                {
                  break;
                }
            }
          });

          this._bannerAd.onResize(() => {});
        }

        __createInterstitialAd() {
          if (!WX_CONFIG.AD_ID.interstitial) return;
          this._interstitialAd = wx.createInterstitialAd({
            adUnitId: WX_CONFIG.AD_ID.interstitial
          });
        }

        __createCustomAd() {
          if (!WX_CONFIG.AD_ID.multiGridCustom) return;
          var info = wx.getSystemInfoSync();
          this._customAd = wx.createCustomAd({
            adUnitId: WX_CONFIG.AD_ID.multiGridCustom,
            adIntervals: 60,
            style: {
              left: 0,
              top: info.screenHeight * 0.16,
              with: info.screenWidth * 0.9
            }
          });

          if (this._customAd) {
            this._customAd.onHide(res => {
              if (this._customAdCloseHandler) {
                this._customAdCloseHandler();
              }

              ;
            });

            this._customAd.onError(err => {
              switch (err.errCode) {
                case 1001:
                  {
                    break;
                  }

                case 1004:
                  {
                    break;
                  }
              }
            });
          }
        }

        __createSigleCustomAd() {
          if (!WX_CONFIG.AD_ID.sigleGridCustom) return;
          var info = wx.getSystemInfoSync();
          var f = (_crd && utils === void 0 ? (_reportPossibleCrUseOfutils({
            error: Error()
          }), utils) : utils).isNormalScreen();
          this._sigleCustomAd = wx.createCustomAd({
            adUnitId: WX_CONFIG.AD_ID.sigleGridCustom,
            adIntervals: 60,
            style: {
              left: info.screenWidth * 0.49,
              top: info.screenHeight * 0.038 + (f ? 20 : 35)
            }
          });

          this._sigleCustomAd.onError(err => {
            console.log('展示格子广告失败1');
          });
        }

        __turnVideoToShare(handler) {
          this.shareShowReward(handler);
          this._videoSuccessHandler = null;
        }

      };

      _export("default", new PlatformWX());

      _cclegacy._RF.pop();

      _crd = false;
    }
  };
});
//# sourceMappingURL=ed7816beea2d4c6349462e4065b653a23963eb71.js.map