/// class PD.Manage.Modules.ReportDeleteCommand

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

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

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

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

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

        var service = new PD.Manage.Services.ReportService(),
            report = this.state("report");

        this._showConfirmationDialog(report, function () {

            service.deleteReport(report.id, function (e) {
                PD.context.get_default().get_events().publish("report/delete", {
                    id: report.id
                });
            });

        });

    },

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

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

    _showConfirmationDialog: function (report, okFn) {

        Jade.UI.MessageDialog.open({
            dialogStyle: Jade.UI.MessageDialogStyle.Warning,
            dialogButtons: Jade.UI.MessageDialogButtonStyle.OKCancel,
            title: "Delete Report",
            message: `Delete the "${report.name}" report?`,
            select: (e) => {
                e.close();
                if (e.button == Jade.UI.MessageDialogButton.ok) {
                    okFn();
                }
            }
        });

    }

});