/// 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) {

        ProspectDirector.Web.UI.FeatureSets.NHibTargetEditorDialog.open({
            config: {
                title: "Tag Properties",
                height: 400,
                width: 500
            },
            data: {
                targetArbiter: "ProspectDirector.Web.Manage.Modules.Tags.TagArbiter",
                targetType: "ProspectDirector.Web.Manage.Modules.Tags.TagUIO",
                layoutType: ProspectDirector.Web.UI.FeatureSets.Layouts.TabStripLayout,
                targetId: id
            },
            callbacks: {
                ok: function (sender, e) {
                    PD.context.get_default().get_events().publish("tag/edit", {
                        id: e.target.id
                    });
                }
            }
        });

    }

});