/// class PD.Manage.Modules.DataLoadDeleteJobCommand

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

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

    setDefaults: function () {
        this.props("id", "job/delete");
        this.props("enabled", false);
        this.props("icon", PD.Path.to16x16("delete.png"));
        this.props("label", "Delete");
        this.props("tooltip", "Delete the selected job.");
        this.state("jobs", null);
    },

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

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

        var service = new PD.Manage.Services.DataLoadService(),
            jobIds = _.map(this._selectedJobs(), "id");

        this._showConfirmationDialog(function (e) {

            service.deleteJobs(jobIds, function (e) {
                PD.context.get_default().get_events().publish("jobs/delete");
            });

        });

    },

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

    _isEnabled: function () {
        return this._selectedJobs().length > 0;
    },

    _selectedJobs: function () {

        var result = [];

        if (_.isArray(this.state("jobs"))) {
            result = this.state("jobs");
        }

        return result;

    },

    _showConfirmationDialog: function (callback) {

        Jade.UI.MessageDialog.open({
            dialogStyle: Jade.UI.MessageDialogStyle.Warning,
            dialogButtons: Jade.UI.MessageDialogButtonStyle.OKCancel,
            allowClose: true,
            title: "Delete Selected Jobs?",
            message: `Delete the selected data import jobs?`,
            select: (e) => {
                e.close();
                if (e.button === Jade.UI.MessageDialogButton.ok) {
                    callback(e);
                }
            }
        });

    }

});