import { PopUpItem } from "../PopUp/PopUpItem";
export class NavigationOverflowItem extends PopUpItem {
    constructor(options) {
        super(options);
        this.m_source = options.source;
        this.state.unset("source");
    }
    get source() {
        return this.m_source;
    }
    template() {
        let icon = Jade.IconSet.get("pdjs")
            .resolve("sign_warning.png", Jade.IconSetSizeSpecificDirectory.x16);
        return `<a href="#" role="tab" class="-fb-navigation-overflow-item">
                    ${this.source.name}
                    <img src="${icon}"/>
                </a>`;
    }
    onActivate(e) {
        super.onActivate(e);
        this.node.on(Jade.BrowserEvent.CLICK, e => {
            e.cancelBubble = true;
            e.returnValue = false;
            e.stopPropagation();
            this.onSelect();
            return false;
        });
        this.m_selectEventSubscription =
            this.source.globals.events.navigationSelectSubscribe((e) => {
                e.id == this.source.id ?
                    this.node.addClass("-fb-selected") :
                    this.node.removeClass("-fb-selected");
            });
        this.source.globals.events.errorsLoadSubscribe(() => {
            this.processValidationErrors();
        });
    }
    onSelect() {
        this.source.globals.events.navigationSelectPublish({
            id: this.source.id,
            scrollIntoView: true
        });
    }
    processValidationErrors() {
        if (this.node == null) {
            return;
        }
        this.source.errors.length === 0 ?
            this.node.removeClass("-fb-error") :
            this.node.addClass("-fb-error");
    }
}
