/// <reference path="leaf.d.ts" />
declare namespace Leaf {
    interface WidgetElement<TUIs extends {
        [index: string]: HTMLElement;
    }, TVMs, TVMField extends string> extends HTMLElement {
        controllingWidget: WidgetBase<TUIs, TVMs, TVMField>;
        selfWidget: WidgetBase<TUIs, TVMs, TVMField>;
        widgetId: string;
    }
    interface WidgetElementAny extends WidgetElement<any, any, any> {
    }
    class Namespace {
        private readonly Widgets;
        include(W: any): void;
        getWidgetByName(name: any): any;
        createWidgetByName(name: string, el?: HTMLElement): WidgetAny;
    }
    type WidgetTemplate = string | HTMLElement;
    type WidgetEventHandler = {
        (e: Event): void;
    };
    interface WidgetEnhancedEvent extends Event {
        capture?: {
            (): void;
        };
        bubblingTarget: HTMLElement;
    }
    interface WidgetDynamicAssignable {
        [index: string]: any;
    }
    type DOMEventInfo = {
        name: string;
        bubble: boolean;
        target?: string[];
    };
    class WidgetBase<TUIs extends {
        [index: string]: HTMLElement;
    }, TVMs, TVMField extends string> {
        template: WidgetTemplate;
        protected _VMFields: TVMField[];
        static namespace: Namespace;
        namespace: Namespace;
        VM: TVMs;
        availableEvents: DOMEventInfo[];
        ViewModel: Model<TVMs, TVMField>;
        parentWidget: WidgetAny;
        events: EventEmitter<string>;
        UI: TUIs;
        node: HTMLElement | WidgetElement<TUIs, TVMs, TVMField>;
        interestingUnbubblingEvents: DOMEventInfo[];
        interestingBubblingEvents: DOMEventInfo[];
        readonly name: string;
        before(who: WidgetAny | HTMLElement): boolean;
        after(who: WidgetAny | HTMLElement): boolean;
        prependTo(who: WidgetAny | HTMLElement): boolean;
        appendTo(who: WidgetAny | HTMLElement): boolean;
        constructor(template?: WidgetTemplate, name?: string, _VMFields?: TVMField[]);
        initTemplate(template?: WidgetTemplate): void;
        private initSubWidget(_el?);
        private initCommonWidget(_el?);
        private syncElementToChildWidget(el, widget);
        private mixChildWidgetClassRole(el, child);
        private initUI();
        private bindUI(node, id);
        private delegateTo(name, event);
        private initBubblingDelegates();
        private initUnbubblingDelegates();
    }
    class Widget<TUIs extends {
        [index: string]: HTMLElement;
    }, TVMs, TVMField extends string> extends WidgetBase<TUIs, TVMs, TVMField> {
        static makeList<TListItem extends ListItem>(el: HTMLElement): List<TListItem>;
        initTemplate(template?: WidgetTemplate): void;
        private initDataRole(el);
        private initElementRole(el);
        private initTextRole(text);
        private createSyncTemplates(templateString);
        private syncElementProperty(el, rule);
        private explain(t);
        private syncTextProperty(text, rule);
        protected emitDOMEvent(name: string, bubble: boolean, props?: any): void;
        protected emitWidgetEvent(name: string, value?: any): void;
        protected include(W: any): void;
        protected expose(name: string, remoteName?: string): void;
        protected makeList<T extends ListItem>(who: string | HTMLElement): List<T>;
    }
    interface CommonWidget {
        new (el: HTMLElement): void;
    }
    type WidgetAny = Widget<any, any, any>;
}
