var e = arequire("../@babel/runtime/helpers/toConsumableArray"), t = arequire("../@babel/runtime/helpers/get"), i = arequire("../@babel/runtime/helpers/getPrototypeOf"), n = arequire("../@babel/runtime/helpers/inherits"), a = arequire("../@babel/runtime/helpers/createSuper"), o = arequire("../@babel/runtime/helpers/createClass"), r = arequire("../@babel/runtime/helpers/classCallCheck");

!function(s) {
    var l = o(function e() {
        r(this, e);
    });
    l.ITTSDK = "ITTSDK", l.ITTSDKModel = "ITTSDKModel", l.ITTSDKConfig = "ITTSDKConfig";
    var h = function(e) {
        n(i, e);
        var t = a(i);
        function i() {
            return r(this, i), t.apply(this, arguments);
        }
        return o(i, null, [ {
            key: "that",
            get: function() {
                return this.getThat();
            }
        }, {
            key: "showInterstitial",
            value: function() {
                this.that.showInterstitial();
            }
        }, {
            key: "startRecorder",
            value: function() {
                this.that.startRecorder();
            }
        }, {
            key: "stopRecorder",
            value: function() {
                this.that.stopRecorder();
            }
        }, {
            key: "hasShareVideo",
            value: function() {
                return this.that.hasShareVideo();
            }
        }, {
            key: "shareAppVideoMessage",
            value: function(e, t) {
                this.that.shareAppVideoMessage(e, t);
            }
        }, {
            key: "addShortcut",
            value: function(e, t) {
                this.that.addShortcut(e, t);
            }
        }, {
            key: "checkShortcut",
            value: function(e, t) {
                this.that.checkShortcut(e, t);
            }
        } ]), i;
    }(TY.Facade);
    h.serviceName = l.ITTSDK;
    var d = function(e) {
        n(i, e);
        var t = a(i);
        function i() {
            return r(this, i), t.apply(this, arguments);
        }
        return o(i, null, [ {
            key: "that",
            get: function() {
                return this.getThat();
            }
        } ]), i;
    }(TY.Facade);
    d.serviceName = l.ITTSDKConfig;
    var c = function(e) {
        n(i, e);
        var t = a(i);
        function i() {
            return r(this, i), t.apply(this, arguments);
        }
        return o(i, null, [ {
            key: "that",
            get: function() {
                return this.getThat();
            }
        }, {
            key: "darenShangBao",
            value: function(e, t) {
                this.that.darenShangBao(e, t);
            }
        }, {
            key: "getDaren",
            value: function(e, t, i) {
                this.that.getDaren(e, t, i);
            }
        } ]), i;
    }(TY.Facade);
    c.serviceName = l.ITTSDKModel;
    var u = function(s) {
        n(h, s);
        var l = a(h);
        function h() {
            var e;
            return r(this, h), (e = l.apply(this, arguments)).channel = TY.LayaCore.API.SDK.SDKChannel.TT, 
            e.isRecording = !1, e.daren_channelid = 0, e.daren_channel = "", e;
        }
        return o(h, [ {
            key: "init",
            value: function(n) {
                var a = this;
                t(i(h.prototype), "init", this).call(this, function() {
                    var t, i = a.sdkModel.getAdRate("topics");
                    null != i && "" != i && (t = d.that.ShareVideoTopic).push.apply(t, e(i.split(",")));
                }), this.initSysInfo(), this.getLaunchOptionsSync(), this.initRewardVideo(), this.initRecorder(), 
                this.initInterstitial();
            }
        }, {
            key: "initSysInfo",
            value: function() {
                this.isTTPlatform && (this.sysInfo = tt.getSystemInfoSync());
            }
        }, {
            key: "initInterstitial",
            value: function() {
                var e = this;
                this.isTTPlatform && ("Douyin" == this.sysInfo.appName ? (this.interstitialAd = tt.createInterstitialAd({
                    adUnitId: d.that.InterstitialId
                }), this.interstitialAd.onLoad(function() {
                    console.log("插屏广告加载成功");
                }), this.interstitialAd.onError(function(e) {
                    console.log("插屏广告加载失败:", e);
                }), this.interstitialAd.onClose(function() {
                    e.interstitialAd.load();
                }), this.interstitialAd.load()) : console.log("插屏广告仅今日头条安卓客户端支持"));
            }
        }, {
            key: "initRewardVideo",
            value: function() {
                var e = this;
                this.isTTPlatform && tt.createRewardedVideoAd && (this.adRewardVideo = tt.createRewardedVideoAd({
                    adUnitId: d.that.VideoAdPos
                }), this.adRewardVideo.onClose(function(t) {
                    t && t.isEnded ? e.onVedioRewardHandler && (e.onVedioRewardHandler(), e.onVedioRewardHandler = null) : (e.onVedioCloseHandler && e.onVedioCloseHandler(), 
                    e.showToast("视频未看完"));
                }), this.adRewardVideo.onError(function(t) {
                    console.log("激励视频加载失败", JSON.stringify(t)), e.onVedioCloseHandler && e.onVedioCloseHandler();
                }), this.adRewardVideo.load());
            }
        }, {
            key: "initRecorder",
            value: function() {
                var e = this;
                this.isTTPlatform && (this.videoRecorder = tt.getGameRecorderManager(), this.videoRecorder.onStart(function(t) {
                    e.isRecording = !0, console.log("录屏开始", t), e.startRecorderTime = new Date().getTime();
                }), this.videoRecorder.onStop(function(t) {
                    e.isRecording = !1, e.videoPath = t.videoPath;
                    var i = new Date().getTime();
                    d.that.MinVideoTime || (d.that.MinVideoTime = 15), console.log("录屏结束,时常：" + (i - e.startRecorderTime) / 1e3 + "s,videoPath：" + e.videoPath), 
                    i - e.startRecorderTime < 1e3 * d.that.MinVideoTime ? e.videoPath = null : e.videoRecorder.clipVideo({
                        path: e.videoPath,
                        timeRange: [ d.that.ClipVideoTime, 0 ],
                        success: function(t) {
                            e.videoPath = t.videoPath;
                        },
                        fail: function(t) {
                            e.videoPath = null, console.log("剪辑视频失败：", t);
                        }
                    });
                }));
            }
        }, {
            key: "hasShareVideo",
            value: function() {
                return !!this.videoPath;
            }
        }, {
            key: "showToast",
            value: function(e) {
                this.isTTPlatform && tt.showToast({
                    title: e,
                    duration: 2e3,
                    icon: "none"
                });
            }
        }, {
            key: "setVibrate",
            value: function(e) {
                this.isTTPlatform && (e > 200 ? tt.vibrateLong({
                    success: function(e) {},
                    fail: function(e) {
                        console.log("长震动失败:", e);
                    },
                    complete: function() {}
                }) : tt.vibrateShort({
                    success: function(e) {},
                    fail: function(e) {
                        console.log("短震动失败:", e);
                    },
                    complete: function() {}
                }));
            }
        }, {
            key: "showVideo",
            value: function(e, t) {
                var i = this;
                this.isTTPlatform ? (this.onVedioRewardHandler = e, this.onVedioCloseHandler = t, 
                this.adRewardVideo.load().then(function() {
                    i.adRewardVideo.show().then(function() {
                        null != i.daren_channel && null != i.daren_channelid && c.darenShangBao(i.daren_channel, i.daren_channelid.toString());
                    }).catch(function(e) {
                        i.onVedioCloseHandler && i.onVedioCloseHandler(), console.log("广告显示失败:", e), i.showToast("广告加载失败");
                    });
                })) : e && e();
            }
        }, {
            key: "showInterstitial",
            value: function() {
                null != this.interstitialAd && this.interstitialAd.show();
            }
        }, {
            key: "startRecorder",
            value: function() {
                null != this.videoRecorder && (this.isRecording || this.videoRecorder.start({
                    duration: d.that.RecorderDuration
                }));
            }
        }, {
            key: "stopRecorder",
            value: function() {
                null != this.videoRecorder && this.isRecording && this.videoRecorder.stop();
            }
        }, {
            key: "isTTPlatform",
            get: function() {
                var e = !0;
                return "undefined" == typeof tt && (e = !1), e;
            }
        }, {
            key: "IsAndroidPlatform",
            get: function() {
                return "android" == this.sysInfo.platform;
            }
        }, {
            key: "shareAppVideoMessage",
            value: function(e, t) {
                var i = this;
                if (this.shareVedioSuc = e, this.shareVedioFail = t, null == this.videoRecorder) return this.showToast("暂无视频"), 
                this.shareVedioFail && (this.shareVedioFail(), this.shareVedioFail = null), void (this.shareVedioSuc = null);
                if (null != this.videoPath) {
                    var n;
                    n = this.daren_channelid && "qrcode" == this.daren_channel ? "channel=share&channelid=" + this.daren_channelid : "", 
                    tt.shareAppMessage({
                        channel: "video",
                        title: d.that.ShareVideoTitle,
                        desc: d.that.ShareVideoDesc,
                        imageUrl: "",
                        templateId: d.that.ShareId,
                        query: n,
                        extra: {
                            videoPath: this.videoPath,
                            videoTopics: d.that.ShareVideoTopic,
                            hashtag_list: d.that.ShareVideoTopic
                        },
                        success: function(e) {
                            i.shareVedioSuc && (i.shareVedioSuc(), i.shareVedioSuc = null), console.log("分享视频成功"), 
                            i.shareVedioFail = null;
                        },
                        fail: function(e) {
                            console.log("分享视频失败", e), i.shareVedioFail && (i.shareVedioFail(), i.shareVedioFail = null), 
                            i.shareVedioSuc = null;
                        }
                    });
                } else this.shareVedioFail && (this.shareVedioFail(), this.shareVedioFail = null), 
                this.shareVedioSuc = null, console.log("没有视频"), this.showToast("录屏太短");
            }
        }, {
            key: "report",
            value: function(e, t) {
                this.isTTPlatform && tt.reportAnalytics(e, t);
            }
        }, {
            key: "getLaunchOptionsSync",
            value: function() {
                if (this.isTTPlatform) {
                    var e = tt.getLaunchOptionsSync();
                    console.log(e);
                    var t = localStorage.getItem("game_query");
                    this.daren_channelid = 0, this.daren_channel = "", "" != e.query && (t = e.query, 
                    localStorage.setItem("game_query", t), this.daren_channelid = t.channelid, this.daren_channel = t.channel, 
                    null != this.daren_channel && null != this.daren_channelid && c.getDaren(this.daren_channel, this.daren_channelid + "")), 
                    t || (console.log(t), t && t.channelid && (this.daren_channelid = t.channelid, this.daren_channel = t.channel));
                    var i;
                    i = this.daren_channelid && "qrcode" == this.daren_channel ? "channel=share&channelid=" + this.daren_channelid : "", 
                    tt.onShareAppMessage(function() {
                        return {
                            title: d.that.ShareVideoTitle,
                            query: i,
                            success: function() {
                                console.log("分享成功");
                            },
                            fail: function(e) {
                                console.log("分享失败", e);
                            }
                        };
                    });
                }
            }
        }, {
            key: "addShortcut",
            value: function(e, t) {
                this.isTTPlatform && tt.addShortcut({
                    success: function(t) {
                        e && e();
                    },
                    fail: function(e) {
                        t && t();
                    }
                });
            }
        }, {
            key: "checkShortcut",
            value: function(e, t) {
                this.isTTPlatform && (this.IsAndroidPlatform ? this.sysInfo.platform && tt.checkShortcut({
                    success: function(i) {
                        i.status.exist ? e && e() : t && t();
                    },
                    fail: function(e) {
                        t && t();
                    }
                }) : e && e());
            }
        } ]), h;
    }(TY.LayaCore.API.SDK.SDKMgrBase), f = function(e) {
        n(l, e);
        var s = a(l);
        function l() {
            return r(this, l), s.apply(this, arguments);
        }
        return o(l, [ {
            key: "init",
            value: function(e, n) {
                var a = 1;
                t(i(l.prototype), "init", this).call(this, e, function() {
                    --a <= 0 && n && (n(), n = null);
                });
            }
        }, {
            key: "getDaren",
            value: function(e, t, i) {
                TY.LayaCore.Server.GameServer.httpGet("admin/api/daren", {
                    channel: e,
                    channelId: t
                }, null, null);
            }
        }, {
            key: "darenShangBao",
            value: function(e, t) {
                TY.LayaCore.Server.GameServer.httpGet("admin/api/darenshangbao", {
                    channel: e,
                    channelId: t
                }, null, null);
            }
        } ]), l;
    }(TY.LayaCore.API.SDK.SDKModelBase), v = function(e) {
        n(i, e);
        var t = a(i);
        function i() {
            return r(this, i), t.apply(this, arguments);
        }
        return o(i, [ {
            key: "shareAppVideoMessage",
            value: function(e, t) {
                e && e();
            }
        }, {
            key: "showInterstitial",
            value: function() {}
        }, {
            key: "startRecorder",
            value: function() {}
        }, {
            key: "stopRecorder",
            value: function() {}
        }, {
            key: "hasShareVideo",
            value: function() {}
        }, {
            key: "addShortcut",
            value: function(e, t) {}
        }, {
            key: "checkShortcut",
            value: function(e, t) {}
        } ]), i;
    }(TY.LayaCore.Services.PCSDK);
    s.ProviderTTSDK = function(e) {
        n(h, e);
        var s = a(h);
        function h() {
            return r(this, h), s.apply(this, arguments);
        }
        return o(h, [ {
            key: "register",
            value: function() {
                t(i(h.prototype), "register", this).call(this), this.cfg = this.app.make(TY.LayaCore.API.ServiceType.IConfig);
                var e = this.cfg.productMode == TY.ProductMode.Develop ? v : u;
                TY.App.singleton(l.ITTSDK, e).alias(TY.LayaCore.API.ServiceType.ISDK);
            }
        } ]), h;
    }(TY.ServiceProvider), s.ProviderTTSDKConfig = function(e) {
        n(h, e);
        var s = a(h);
        function h(e) {
            var t;
            return r(this, h), (t = s.call(this)).cfg = null, t.cfg = e, t;
        }
        return o(h, [ {
            key: "register",
            value: function() {
                t(i(h.prototype), "register", this).call(this), TY.App.singleton(l.ITTSDKConfig, this.cfg).alias(TY.LayaCore.API.ServiceType.ISDKConfig);
            }
        } ]), h;
    }(TY.ServiceProvider), s.ProviderTTSDKModel = function(e) {
        n(h, e);
        var s = a(h);
        function h() {
            return r(this, h), s.apply(this, arguments);
        }
        return o(h, [ {
            key: "register",
            value: function() {
                t(i(h.prototype), "register", this).call(this), TY.App.singleton(l.ITTSDKModel, f).alias(TY.LayaCore.API.ServiceType.ISDKModel);
            }
        } ]), h;
    }(TY.ServiceProvider), s.SDK = h, s.SDKConfig = d, s.SDKModel = c, s.ServicesType = l, 
    s.TTModel = f, s.TTSDK = u, s.TTSDKConfig = function(e) {
        n(i, e);
        var t = a(i);
        function i() {
            var e;
            return r(this, i), (e = t.apply(this, arguments)).GameId = "837", e.APIVersion = "1.0.1", 
            e.AppID = "tt4cf13a4cd3c81d7d02", e.VideoAdPos = "886mj46sco7cq77q40", e.BannerId = "2bo9kqtevssop5g8ex", 
            e.ShareId = "2w9pgh7d9631iihfac", e.InterstitialId = "7258kg0edijf53opg5", e.ShareVideoTitle = "", 
            e.ShareVideoDesc = "", e.ShareVideoTopic = [], e.ClipVideoTime = 30, e.RecorderDuration = 60, 
            e.MinVideoTime = 15, e;
        }
        return o(i);
    }(TY.LayaCore.API.SDK.SDKConfigBase), Object.defineProperty(s, "__esModule", {
        value: !0
    });
}(window.TY.TTSDK = window.TY.TTSDK || {});