
import Gamecfg from "../../common/gameCfg";
import GameDataCenter from "../../data/GameDataCenter";
import { MergeItem } from "../../data/model/GridMap/GridMapModel";
import ResSprite from "../../frameWork/compment/ResSprite";
import UEBase from "../../frameWork/compment/UEBase";
import { HcType } from "../../shared/hc/PtlHcInfo";
import AssetMgr from "../../utils/AssetMgr";

const { ccclass, property } = cc._decorator;

export interface I_MergeTipItemData {
    data: MergeItem;
}
@ccclass
export default class UEMergeTipItem extends UEBase {
    static readonly BundleKey: string = "gridMap";
    static readonly PrefabUrl: string = "UEMergeTipItem";
    static readonly CLS: string = "UEMergeTipItem";
    @property(ResSprite)
    sp_quality: ResSprite = null!;
    @property(ResSprite)
    sp_icon: ResSprite = null!;
    @property(cc.Node)
    node_lock: cc.Node = null!;
    @property(cc.Label)
    lbt_rate: cc.Label = null;
    data: I_MergeTipItemData = null!;
    Init(data: I_MergeTipItemData) {
        this.data = data;
        this.ShowItem(this.data.data);
    }

    private ShowItem(data: MergeItem) {
        if (data) {
            this.lbt_rate.string = `${(this.data.data.rate / 100).toFixed(0)}%`;
            this.node.active = true;
            this.node_lock.active = false;
            this.sp_icon.node.active = true;
            let quality = 0;

            if (data.type == HcType.emitter) {
                let mergePropCfg = Gamecfg.emitterInfo.getItem(data.id.toString());
                this.sp_icon.setSpriteFrame('gridMap', `mergeProp/${mergePropCfg?.icon}`);
                quality = mergePropCfg.quality;
            } else if (data.type == HcType.material) {
                let mergePropCfg = Gamecfg.mergePropInfo.getItem(data.id.toString());
                this.sp_icon.setSpriteFrame('gridMap', `mergeProp/${mergePropCfg?.icon}`);
                quality = mergePropCfg.quality;
            } else if (data.type == HcType.equip) {
                let mergePropCfg = Gamecfg.equipInfo.getItem(data.id.toString());
                this.sp_icon.setSpriteFrame('gridMap', `mergeEquip/${mergePropCfg?.icon}`);
                quality = mergePropCfg.quality;
            }
            this.sp_quality.setSpriteFrame('gridMap', `images/Img_zjm_pinzhi0${quality}`);

        } else {
            this.node.active = false;
        }
    }


}
