/// class PD.Manage.Modules.SystemSettingExportConfigCommand

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

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

    setDefaults: function (options) {

        this.props("id", "system-setting/export-config");
        this.props("enabled", true);
        this.props("icon", PD.Path.to16x16("inbox_out.png"));
        this.props("label", "Export Configuration");
        this.props("tooltip", "Export the application's configuration.");

    },

    execute: function (e) {
        this._super(e);
        this._showConfirmationDialog();
    },

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

    _showConfirmationDialog: function () {

        Jade.UI.MessageDialog.open({
            dialogStyle: Jade.UI.MessageDialogStyle.Information,
            dialogButtons: Jade.UI.MessageDialogButtonStyle.OKCancel,
            title: "Export?",
            message: "Export application configuration?",
            select: (e) => {
                e.close();
                if (e.button == Jade.UI.MessageDialogButton.ok) {
                    this._execute();
                }
            }
        });

    },

    _execute: function () {

        PDJS.Shared.TaskStatusDialog.open({
            title: "Export | Configuration",
            taskStart: (e) => {

                PD.ajax({
                    type: "POST",
                    url: PD.Path.resolve("~/Manage/Settings/ExportConfig"),
                    success: (e2) => {
                        e.startPolling(e2);
                    },
                    error: (e2) => {
                        e.abort(e2.responseJSON);
                        e2.errorHandled = true;
                    }
                });

            },
            taskSuccess: (e) => {
                if (e.output != null && e.output.path != null) {
                    PDJS.Shared.Downloader.downloadWithProgress({
                        url: `~/Manage/Settings/DownloadConfigFile?path=${e.output.path}&name=${e.output.name}`
                    });
                }
            }
        });

    }

});
