import { InputVariablePopUp } from "./InputVariablePopUp.js";
export class InputVariableView extends Jade.UI.Control {
    constructor(options) {
        super(options);
    }
    get editorModel() {
        return this.m_editorModel;
    }
    get inputNode() {
        return this.node.find("input");
    }
    get focusCallback() {
        return this.state.get("focus", () => { });
    }
    get variableUsed() {
        return this.state.get("variableSupported", false);
    }
    get buttonNode() {
        return this.node.find("button");
    }
    get imgNode() {
        return this.node.find("img");
    }
    template() {
        return `<div class="-fb-grid-input-variable">
                    <div>
                        <input type="text" readonly />
                        <img src="${Jade.IconSet.get("pdjs").resolve("cancel.png", Jade.IconSetSizeSpecificDirectory.x16)}" title="Clear variable" />
                    </div>
                    <div>
                        <button>...</button>
                    </div>
                </div>`;
    }
    show() {
        this.node.css({
            display: "grid"
        });
    }
    hide() {
        this.node.css({
            display: "none"
        });
    }
    onActivate(e) {
        super.onActivate(e);
        this.inputNode.on(Jade.BrowserEvent.FOCUS, () => {
            this.input_onFocus();
        });
        this.node.on(Jade.BrowserEvent.MOUSEENTER, "input,img", () => {
            this.imgNode.show();
        });
        this.node.on(Jade.BrowserEvent.MOUSELEAVE, "input,img", () => {
            this.imgNode.hide();
        });
        this.variableUsed ? this.show() : this.hide();
        this.popup_init();
        let variableNames = [
            "BackgroundColor",
            "ThemeColor",
            "CurrentStatus",
            "MaxCount",
            "IsCurrentUserTeamLeader",
            "MinCompleted",
            "MaxCostGreaterThanMinBudget",
            "IsShelved",
            "SuggestedForPromotion",
            "Position"
        ];
        this.inputNode.val(variableNames[Jade.Arithmetic.randomInteger(0, 9)]);
    }
    popup_init() {
        let popup = new InputVariablePopUp({
            handle: this.buttonNode
        });
        this.controls.add(popup);
    }
    input_onFocus() {
        this.focusCallback();
        this.inputNode.select();
    }
}
