export class FilterCommand {
    static invoke(content, term) {
        if (Jade.String.isNullOrWhiteSpace(term)) {
            content.node.removeClass("-fb-grid-filtered");
        }
        else {
            content.node.addClass("-fb-grid-filtered");
        }
        let result = this.filterCategories(content, term);
        if (result.lastVisible == null) {
            this.writeMessage(content, `No inputs matched the text <b>"${term}"</b>.`);
        }
        else {
            this.clearMessage(content);
        }
    }
    static filterCategories(content, term) {
        let result = {
            lastVisible: null
        };
        content.categories.each((view) => {
            let inputs = this.filterInputs(view, term);
            if (inputs.lastVisible != null) {
                result.lastVisible = view;
            }
            view.node.css({
                borderBottom: ""
            });
        });
        return result;
    }
    static filterInputs(category, term) {
        let result = {
            lastVisible: null
        };
        category.inputs.each((input) => {
            let isMatch = input.editorModel.label.toLowerCase().indexOf(term.toLowerCase()) >= 0;
            if (isMatch) {
                input.node.removeClass("-fb-filtered");
                result = {
                    lastVisible: input
                };
            }
            else {
                input.node.addClass("-fb-filtered");
            }
        });
        if (result.lastVisible != null) {
            category.node.show();
        }
        else {
            category.node.hide();
        }
        return result;
    }
    static clearMessage(content) {
        content.node.find("div[role=fb-content-message]").remove();
    }
    static writeMessage(content, text) {
        this.clearMessage(content);
        let message = $(`<div role="fb-content-message"><div>${text}</div></div>`);
        message.css({
            display: "flex",
            justifyContent: "center",
            alignItems: "center",
            position: "absolute",
            top: 0,
            right: 0,
            bottom: 0,
            left: 0,
            textAlign: "center",
            fontSiz: "12px",
            fontFamily: "Arial"
        });
        content.node.append(message);
    }
}
