
import Panel from "../views/Panel";
import DogData from "../startScene/DogData";
export default class SharePanel extends Panel {
    public panelGroup:eui.Group;
    public titleLb:eui.Label;
    public erweimaImg:eui.Image;
    public dogShadowImg:eui.Image;
    public dogImg:eui.Image;
    public closeBtn:eui.Button;
    public rectJie:eui.Rect;


    private mdata:any;

    public get skinKey() { return 'Share' }
	public get groupName() { return 'share_panel'}
    constructor(data?){
        super(data);
        this.mdata = data;
    }

    start(data?):void{
        this.percentHeight = 100;
    }

    initEvents():void{
         this.closeBtn.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onTap_closeBtn, this);
    }

    removeEvents():void{
         this.closeBtn.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.onTap_closeBtn, this);
    }

    onSkinComplete(): void {
        super.onSkinComplete();
        this.once(egret.Event.ADDED_TO_STAGE, this.onLoad, this);
        if (this.stage) {
            this.onLoad();
        }
    }

    private onLoad():void{
      //  this.erweimaImg.visible = false;
        this.dogImg.source = 'dog_lv_' + (this.mdata.level) + '_png';
        this.dogImg.anchorOffsetX = DogData.getSizeData[this.mdata.level - 1][0] * 0.5;
        this.dogImg.anchorOffsetY = DogData.getSizeData[this.mdata.level - 1][1];

        this.dogImg.x = 750 * 0.5;
        this.dogImg.y = this.dogShadowImg.y;

        this.titleLb.text = '我在萌宠汪星球领养了' + this.mdata.dNum + '只狗狗';

        
        setTimeout(() => {
            this.scanImg();
        }, 1000);

        //img.style.display = 'none';//block
    }


    img

    private scanImg():void{
        let renderTexture: egret.RenderTexture = new egret.RenderTexture();
        renderTexture.drawToTexture(this.panelGroup, new egret.Rectangle(this.rectJie.x, this.rectJie.y, this.rectJie.width, this.rectJie.height));
        let imageData = renderTexture.toDataURL("image/png");
        this.img = document.getElementById('shareImg');
        this.img.style.position = 'absolute';
        this.img['src'] = imageData;
        this.img.style.width = "93.4vw";//`${widthP}%`;
        this.img.style.left  = "3.4vw";//`${leftP}%`;
        this.img.style.top   = "15.8vw";//`${topP}%`;
        this.img.style.display           = 'block';
    }

    onTap_closeBtn(){
        this.img.style.display = 'none';
        this.hidePanel();
    }
}