import { _decorator, Component, Node, sys } from 'cc';
import { tools } from '../tools';
const { ccclass, property } = _decorator;

@ccclass('pause')
export class pause extends Component {
    @property(Node) btn_back:Node;
    private m_cancel_back = null;
    private InterstitialAd:any = null;
    start() {
        let self = this;
        this.btn_back.on(Node.EventType.TOUCH_START,()=>{
            if(this.m_cancel_back!=null){
                this.m_cancel_back()
            }
            self.close();
        },this);
    }
    close(){
        this.node.removeFromParent();
        if(this.InterstitialAd ){
            this.InterstitialAd.destroy()
            this.InterstitialAd =null;
        }
    }

    public show(cancel_back){
        if(sys.platform==sys.Platform.BYTEDANCE_MINI_GAME){
            // this.InterstitialAd = tt.createInterstitialAd({
            //     adUnitId: "3d0ecl882ic9ed7apr",
            // });
            // this.InterstitialAd.load()
            // .then(() => {
            //     this.InterstitialAd.show().then(() => {
            //         tools.showToast("插屏广告展示成功");
            //     });
            // })
            // .catch((err) => {
            //     tools.showToast(err)
            //     console.log(err);
            // });
     //最佳实践
            const videoAd = tt.createRewardedVideoAd({adUnitId: "8d19519ih5ab5msq6n"});
            videoAd.onLoad(() => {
            videoAd.show();
            console.log("广告加载完成");
            });
            videoAd.load()
        }
        this.m_cancel_back = cancel_back;
    }
}


