
const DWTool = require("./DWTool");

/**
 * 通用弹窗管理
 */
class AlertManager {

    // 显示培养弹窗
    static showTrainAlert(targetUid, zIndex = 0) {

        DWTool.loadResPrefab("./prefabs/artist_train")
            .then((result) => {
                let artistTrain = cc.instantiate(result);
                artistTrain.zIndex = zIndex;
                artistTrain.getComponent('ArtistTrain').init(targetUid);
                let canvas = cc.find("Canvas");
                canvas.addChild(artistTrain);
            });
    };

    // 显示充值弹窗
    static showRechargeAlert(zIndex = 0) {

        DWTool.loadResPrefab("./prefabs/artist_train_alert")
            .then((result) => {
                let alert = cc.instantiate(result);
                alert.zIndex = zIndex;
                let canvas = cc.find("Canvas");
                canvas.addChild(alert);
            });
    };

    // 显示星探界面
    static showTalentAlert() {
        cc.loader.loadRes('/prefabs/talent_mission', cc.Prefab, (error, prefab) => {
            if (error === null) {
                let mission = cc.instantiate(prefab);
                mission = mission.getComponent('TalentMission');
                mission.init();
            } else {
                console.log(JSON.stringify(error));
            }
        });
    };

    // 显示培养成功界面
    static showArtistTrainCompletion(data, zIndex = 0) {

        DWTool.loadResPrefab("./prefabs/artist_train_completion")
            .then((result) => {

                let alert = cc.instantiate(result);
                alert.zIndex = zIndex;
                let canvas = cc.find("Canvas");
                canvas.addChild(alert);
                alert.getComponent('ArtistTrainCompletion').init(data);
            });
    };

    // 艺人没有职业时弹窗提示
    static showArtistTrainNoJob(cb, zIndex = 0) {
        DWTool.loadResPrefab("./prefabs/artist_train_no_job")
            .then((result) => {

                let alert = cc.instantiate(result);
                alert.zIndex = zIndex;
                let canvas = cc.find("Canvas");
                canvas.addChild(alert);
                alert.getComponent('ArtistTrainNoJob').init(cb);
            });
    }

    // 显示选择驻场艺人
    static showArtistResident(buildingInfo, uid, isSelf) {
        DWTool.loadResPrefab("./prefabs/artist_resident")
            .then((result) => {
                let artistResident = cc.instantiate(result);
                let canvas = cc.find("Canvas");
                artistResident.getComponent('ArtistResident').init(buildingInfo, uid, isSelf);
                canvas.addChild(artistResident);
            });
    }

    // 显示通知消息弹窗
    static showNoticePopup() {
        DWTool.loadResPrefab("./prefabs/notice_popup")
            .then((result) => {
                let alert = cc.instantiate(result);
                let canvas = cc.find("Canvas");
                canvas.addChild(alert);
            });
    }

    // 显示任务大厅弹窗
    static showQuestPopup() {
        DWTool.loadResPrefab("./prefabs/quest/quest_popup")
            .then((result) => {
                let alert = cc.instantiate(result);
                let canvas = cc.find("Canvas");
                canvas.addChild(alert);
            });
    }

    // 显示亲密度不够的弹窗
    static showIntimacyBotEnough() {

        DWTool.loadResPrefab("./prefabs/intimacy_not_enough")
            .then((result) => {
                let alert = cc.instantiate(result);
                let canvas = cc.find("Canvas");
                canvas.addChild(alert);
            });
    }

    // 显示亲密度不够的弹窗
    static showArtistReportSuccess(coinCount) {

        DWTool.loadResPrefab("./prefabs/artist_report_success")
            .then((result) => {
                let alert = cc.instantiate(result);
                let canvas = cc.find("Canvas");
                canvas.addChild(alert);
                alert.getComponent('ArtistReportSuccess').init(coinCount);
            });
    }

    // 显示艺人操作弹窗
    static showArtistOperationAlert(buildingInfo, uid, isSelf, artistData) {
        DWTool.loadResPrefab("./prefabs/artist_operation_alert")
            .then((result) => {
                let alert = cc.instantiate(result);
                let canvas = cc.find("Canvas");
                canvas.addChild(alert);
                alert.getComponent('ArtistOperationAlert').init(buildingInfo, uid, isSelf, artistData);
            });
    }

    static showOfflineGrossIncome(offlineGold) {
        DWTool.loadResPrefab("./prefabs/levelHome/offline_grossIncome")
            .then((result) => {
                let alert = cc.instantiate(result);
                let canvas = cc.find("Canvas");
                canvas.addChild(alert);
                alert.getComponent('OfflineGrossIncome').init(offlineGold);
            });
    }

    static showRankPage() {
        DWTool.loadResPrefab('./prefabs/rank_page')
            .then((result) => {
                let alert = cc.instantiate(result);
                let canvas = cc.find('Canvas');
                canvas.addChild(alert);
            });
    }

    /// 显示抽奖界面
    static showDrawAlert(data = 1) {
    
        DWTool.loadResPrefab("./prefabs/draw/draw_content")
            .then((result) => {
                let alert = cc.instantiate(result);
                let canvas = cc.find("Canvas");
                alert.setPosition(0, 0);
                canvas.addChild(alert);
            });
    }

    /// 显示抽奖滚动界面
    static showDrawScrollAlert(drawData, typeId) {
    
        DWTool.loadResPrefab("./prefabs/draw/drawScroll")
            .then((result) => {
                let alert = cc.instantiate(result);
                let canvas = cc.find("Canvas");
                alert.setPosition(0, 0);
                canvas.addChild(alert);
                alert.getComponent("DrawScroll").init(drawData, typeId);
        });
    }

    /// 显示抽奖成功得到明星的界面
    static showDrawSuccessAlert(drawData, typeId, backGroudId) {
        DWTool.loadResPrefab("./prefabs/draw/drawStarSuccss")
            .then((result) => {
                let alert = cc.instantiate(result);
                let canvas = cc.find("Canvas");
                alert.setPosition(0, 0);
                canvas.addChild(alert);
                alert.getComponent("DrawStarSuccss").init(drawData, typeId, backGroudId);
        });
    }

    /// 显示技能弹窗界面
    static showSkillAlert() {
        DWTool.loadResPrefab("./prefabs/skill/skill_content")
            .then((result) => {
                let alert = cc.instantiate(result);
                let canvas = cc.find("Canvas/commonNode");
                canvas.addChild(alert);
        });
    }

    /// 显示明星图鉴
    static showStarHandbookAlert() {
        DWTool.loadResPrefab("./prefabs/star/starHandbook")
            .then((result) => {
                let alert = cc.instantiate(result);
                let canvas = cc.find("Canvas");
                canvas.addChild(alert);
            });
    }

    /// 显示明星界面
    static showStarAlert() {
        DWTool.loadResPrefab("./prefabs/star/star_content")
            .then((result) => {
                let alert = cc.instantiate(result);
                // 116 108 992
                
                let canvas = cc.find("Canvas/commonNode");
                canvas.addChild(alert);
        });
    }

    /// 显示获取道具弹窗界面
    static showActGiftAlert(type, showText) {
        DWTool.loadResPrefab("./prefabs/common/actgift")
            .then((result) => {
                let alert = cc.instantiate(result);
                let canvas = cc.find("Canvas");
                canvas.addChild(alert);
                alert.getComponent("Actgift").init(type, showText);
        });
    }
}

module.exports = AlertManager;