/// class PD.Manage.Modules.ViewCopyCommand

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

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

    setDefaults: function () {
        this.props("id", "view/copy");
        this.props("enabled", true);
        this.props("icon", PD.Path.to16x16("copy.png"));
        this.props("label", "Copy View");
        this.props("tooltip", "Create a copy of the selected View.");
        this.state("view", null);
    },

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

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

        let service = new PD.Manage.Services.ViewService();
        let view = this.state("view");

        this._showConfirmationDialog(view.name, function (e) {
            service.copyView(view.id, function (e) {
                PD.context
                    .get_default()
                    .get_events()
                    .publish("view/copy", {
                        id: e.id
                    });
            });
        });

    },

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

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

    _showConfirmationDialog: function (name, callback) {

        Jade.UI.MessageDialog.open({
            dialogStyle: Jade.UI.MessageDialogStyle.Information,
            dialogButtons: Jade.UI.MessageDialogButtonStyle.OKCancel,
            title: "Copy View",
            message: `Make a copy of the "${name}" view?`,
            select: (e) => {
                e.close();
                if (e.button === Jade.UI.MessageDialogButton.ok) {
                    callback();
                }
            }
        });

    }

});
