/// class PD.Manage.Modules.ExpressionEditDialogCommand

PD.Manage.Modules.ExpressionEditDialogCommand =
PD.Commands.Command.extend({

    //===================================
    // PROPERTIES
    //===================================

    get_expressions: function () {
        return this.state("expressions") || [];
    },

    get_expression: function () {
        return _.first(this.get_expressions());
    },

    //===================================
    // PUBLIC METHODS
    //===================================

    setDefaults: function () {
        this.props("id", "expression/edit-dialog");
        this.props("enabled", false);
        this.props("icon", PD.Path.to16x16("pencil.png"));
        this.props("label", "Edit");
        this.props("tooltip", "Edit the selected Expression.");
        this.state("expressions", null);
    },

    setState: function (state) {
        this._super(state);
        this.props("enabled", this._isEnabled());
    },

    execute: function (e) {
        this._super(e);

        var expression = this.get_expression();

        if (expression != null) {
            this._showDialog(expression.id, expression.name);
        }

    },

    //===================================
    // PRIVATE METHODS
    //===================================

    _isEnabled: function () {
        return this.get_expression() != null && this.get_expressions().length == 1;
    },

    _showDialog: function (id, name) {

        PDJS.Shared.Features.FeatureDialogForNhib.open({
            title: `Tag Expression | ${name}`,
            args: {
                targetId: id,
                targetType: "ProspectDirector.Web.Manage.Modules.Tags.ExpressionUIO",
                arbiterType: "ProspectDirector.Web.Manage.Modules.Tags.ExpressionArbiter"
            },
            callbacks: {
                "ok": (sender, e) => {

                    PD.context
                        .get_default()
                        .get_events()
                        .publish("expression/edit", {
                            id: e.target.id
                        });

                }
            }
        }, {
            height: 400,
            width: 500,
        });

    }

});