/// class PD.Manage.Modules.SelectionListDeleteCommand

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

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

    setDefaults: function () {

        this.props("id", "selection-list/delete");
        this.props("enabled", false);
        this.props("icon", PD.Path.to16x16("delete.png"));
        this.props("label", "Delete");
        this.props("tooltip", "Delete the selected Selection List.");

        this.state("selectionList", null);

    },

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

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

        var selectionList = this.state("selectionList");

        Jade.UI.MessageDialog.open({
            dialogStyle: Jade.UI.MessageDialogStyle.Warning,
            dialogButtons: Jade.UI.MessageDialogButtonStyle.OKCancel,
            allowClose: true,
            title: "Delete Selection List",
            message: `Delete the "${selectionList.name}" selection list?`,
            select: (e) => {
                e.close();
                if (e.button === Jade.UI.MessageDialogButton.ok) {
                    this._deleteList(selectionList.id, selectionList.name);
                }
            }
        });

    },

    isEnabled: function () {
        return this.state("selectionList") != null && this.state("selectionList").id != null;
    },

    _deleteList: function (id, name) {

        var that = this;
        var service = new PD.Manage.Services.SelectionListService();

        service.deleteSelectionList(id, function (e) {
            if (e.requiresConfirmation) {
                that._showDeleteDeniedDialog(id, name);
            }
            else {
                PD.context.get_default().get_events().publish("selection-list/delete", id);
            }
        });

    },

    _showDeleteDeniedDialog: function (id, name) {

        Jade.UI.MessageDialog.open({
            dialogStyle: Jade.UI.MessageDialogStyle.Warning,
            dialogButtons: Jade.UI.MessageDialogButtonStyle.OK,
            allowClose: true,
            title: "Delete List",
            message: `The "${name}" list is currently in use and cannot be deleted?`
        });

    }

});