/*
 * 特别声明：本技术材料受《中华人民共和国著作权法》、《计算机软件保护条例》等法律、法规、行政
 * 规章以及有关国际条约的保护，赞同科技享有知识产权、保留一切权利并视其为技术秘密。未经本公司书
 * 面许可，任何人不得擅自（包括但不限于：以非法的方式复制、传播、展示、镜像、上载、下载）使用，
 * 不得向第三方泄露、透露、披露。否则，本公司将依法追究侵权者的法律责任。特此声明！
 *
 * Special Declaration: These technical material reserved as the technical secrets by AGREE
 * TECHNOLOGY have been protected by the "Copyright Law" "ordinances on Protection of Computer
 * Software" and other relevant administrative regulations and international treaties. Without
 * the written permission of the Company, no person may use (including but not limited to the
 * illegal copy, distribute, display, image, upload, and download) and disclose the above
 * technical documents to any third party. Otherwise, any infringer shall afford the legal
 * liability to the company.
 */
import {Composite} from "widget/Composite";


/**
 * 一体化界面容器组件的基类，继承Composite
 * 无需维护parent、layout、layouData
 * 
 * Created by huang.dy on 2016/7/27.
 */
export abstract class AbstractContainer extends Composite {

    private reinitCount: number = 0;
    private static _this: AbstractContainer;

    constructor(parentId: string, id: string, style: number) {
        super(parentId, id, style);
        AbstractContainer._this = this;
        this.$thisNode = $("#" + id); // 
        if (this.$thisNode.length === 0) {
            setTimeout(AbstractContainer._this.reinit, 200);
        } else {
            this.reset();
        }
    }

    private reinit() {
        let own = AbstractContainer._this;
        own.$thisNode = $("#" + own.id);
        if (own.$thisNode.length === 0) {
            if (own.reinitCount < 10) {
                own.reinitCount++;
                setTimeout(own.reinit, 200);
            } else {
                console.error("not found element[" + own.id + "]");
            }
        } else {
            own.reset();
        }
    }

    protected abstract reset(): void;

    public toString(): string {
        return "AbstractContainer";
    }

    public dispose() {
        super.dispose();
        AbstractContainer._this = null;
    }

    public append() {// 无需维护layout
    }
    public layout() {// 无需维护layout
    }
    public setLayoutData(args: { layoutData: any }) {// 无需维护layoutData
    }

}