import { NetManager } from './../../libs/tw/manager/NetManager';
import { DataManager } from './../../libs/tw/manager/DataManager';
import { HtmlTextParser } from "./HtmlTextParser";
import Panel from "../views/Panel";
import NetConst from '../NetConst';

export default class RulePanel extends Panel {
    public labContent: eui.Label;
    public scroller: eui.Scroller;
    public textstring:string = "";
    public endstr:string = "";
    // public ruleMask:eui.Rect;

    start() {
        
        // // this.scroller.height = 750 / window.innerWidth *860;
        // // this.labContent.mask = this.ruleMask;
        // // this.ruleMask.visible = false;
        // // console.log("window['ruleTxt']:"+window['ruleTxt']);
        // if (window['ruleTxt']) {
        //     // console.log(window['ruleTxt']);
        //     // setTimeout(()=>{
        //         // this.labContent.textFlow = (new HtmlTextParser).parser(window['ruleTxt']);
        //         // this.labContent.textColor = 0xb1d1e7;
        //         // console.log(this.labContent);
        //     // },2000)
            
        // } else {
        //     if (!DataManager.ins.getData("gameAjaxElement").data || !DataManager.ins.getData("gameAjaxElement").data.rule) {
        //         NetConst.ajaxElement(() => {
        //             // DataManager
        //             this.addRule();
        //         });
        //     }
        //     else {
        //         this.addRule();
        //     }
        // }
    }

    group: eui.Group;
    private addRule() {
        const text = DataManager.ins.getData("gameAjaxElement").data.rule;
        this.textstring = text;
        this.replaceWord();
        this.labContent.textFlow = (new HtmlTextParser).parser(this.textstring);
        this.labContent.textColor = parseInt("fcffb4",16);
    }

    replaceWord(){

        if (this.textstring.search("</p>") == -1) {
            if(this.endstr){
                this.textstring = this.endstr;
            }
        } else {
            this.textstring = this.textstring.replace("</p>", "</p><br>");
            this.endstr = this.endstr.concat(this.textstring.slice(0, this.textstring.search("</p>") + 8));
            this.textstring = this.textstring.slice(this.textstring.search("</p>") + 8, this.textstring.length);
            this.replaceWord();
        }
    }
    get skinKey() { return 'Rule' }
}