/// class PD.Manage.Modules.GroupMembersRemoveCommand

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

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

    setDefaults: function () {
        this.props("id", "group/members-remove");
        this.props("enabled", true);
        this.props("icon", PD.Path.to16x16("delete.png"));
        this.props("label", "Remove Member");
        this.props("tooltip", "Remove Member");
        this.state("members", null);
        this.state("membership", null);
    },

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

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

        var members = this.state("members"),
            membership = this.state("membership");

        _.each(members, function (member) {
            if (_.includes(membership.add, member.id)) {
                membership.add = _.without(membership.add, member.id);
            }
            if (!_.includes(membership.remove, member.id)) {
                membership.remove[membership.remove.length] = member.id;
            }
        });

        PD.context.get_default().get_events().publish("group/members-removed", function (e) {
            members: membership.remove
        });

    },

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

    _isEnabled: function () {

        var members = this.state("members"),
            membership = this.state("membership");

        return _.isArray(members)
            && members.length > 0
            && membership != null
            && _.isArray(membership.add)
            && _.isArray(membership.remove);

    }

});