/// class PD.Manage.Modules.TagEditDialogCommand

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

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

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

    get_tag: function () {
        return _.first(this.get_tags());
    },

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

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

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

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

        var tag = this.get_tag();

        this._showDialog(tag.id);

    },

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

    _isEnabled: function () {
        return this.get_tags().length === 1;
    },

    _showDialog: function (id) {

        PDJS.Shared.Features.FeatureDialogForNhib.open({
            title: "Tag Properties",
            args: {
                targetId: id,
                targetType: "ProspectDirector.Web.Manage.Modules.Tags.TagUIO",
                arbiterType: "ProspectDirector.Web.Manage.Modules.Tags.TagArbiter"
            },
            callbacks: {
                ok: (sender, e) => {

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

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

    }

});