// Learn TypeScript:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/life-cycle-callbacks.html

import User from "../../FrameWork/User/User";
import AppPlatform from "../../FrameWork/Util/AppPlatform";
import Common5 from "../../Platform/th/Common5";
import TTAPI from "../../Platform/tt/TTAPI";
import TaskManager from "../JuQingChat/TaskManager";
import LevelUpManager from "../Manager/LevelUpManager";
import UserManager from "../Manager/UserManager";

const { ccclass, property } = cc._decorator;

@ccclass
export default class renZheng extends cc.Component {

    @property(cc.Node)
    icon: cc.Node = null

    @property(cc.Label)
    lab: cc.Label = null
    @property(cc.Label)
    jiachenglab: cc.Label = null

    @property(cc.Label)
    faillab: cc.Label = null
    finishCallFunc: any;
    restartCallFunc: any;
    // @property
    // text: string = 'hello';



    // LIFE-CYCLE CALLBACKS:

    // onLoad () {}

    start() {
        Common5.playRemoteAudioEffect("remotesound/effect/游戏点击音效")
        Common5.showInterstitialAd()
    }

    showResult(id, resultIndex, finishCallFunc, restartCallFunc) {
        this.finishCallFunc = finishCallFunc
        this.restartCallFunc = restartCallFunc
        if (resultIndex >= 1) {
            this.node.getChildByName("成功").active = true
            let chenghaoConfig = LevelUpManager.getChenghaoConfigById(id + 3)
            if (chenghaoConfig) {
                this.lab.string = `成功认证${chenghaoConfig.chenghaoStr}称号`
                Common5.getSpriteFrameFromBundle('renZheng', `res/${chenghaoConfig.chenghaoStr}`, this.node.getChildByName("成功").getChildByName("icon").getComponent(cc.Sprite))
                this.jiachenglab.string = `点击收益加成:${Math.ceil(chenghaoConfig.inComeMultiple * 100)}% 秒赚收益加成:${Math.ceil(chenghaoConfig.inComeMultiple * 100)}%`
            }
        } else {
            this.node.getChildByName("失败").active = true
        }

    }

    onTouchSure() {
        if (this.finishCallFunc) {
            this.finishCallFunc()
        }
        this.node.removeFromParent()
        this.node.destroy()
    }

    onTouchAgain() {
        if (this.restartCallFunc) {
            this.restartCallFunc()
        }
        this.node.removeFromParent()
        this.node.destroy()
    }

    onTouchPass() {
        let tab = {
            onClose: (finish) => {
                if (finish) {
                    User.setShowAdNum(User.getShowAdNum() + 1)
                    Common5.ReportDY("inLevel", `任务${TaskManager.getCurUnLockMainTaskId()}-AD-认证直接通过`)
                    // Common5.ReportDY("inLevel", '认证-AD-直接通过');
                    if (this.finishCallFunc) {
                        this.finishCallFunc()
                    }
                    this.node.removeFromParent()
                    this.node.destroy()
                }
                else {
                    Common5.showTips_custom("广告未观看完");
                }
            }, onFailed: () => {

            }
        }
        AppPlatform.playVideo_custom(tab)

    }

    // update (dt) {}
}