/// class PD.Manage.Modules.ViewDeleteDialogCommand

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

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

    setDefaults: function () {
        this.props("id", "view/delete");
        this.props("enabled", true);
        this.props("icon", PD.Path.to16x16("delete.png"));
        this.props("label", "Delete");
        this.props("tooltip", "Delete 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((e) => {

            let deleteLinked = e === "delete";

            service.deleteView(view.id, deleteLinked, (e) => {

                PD.context
                    .get_default()
                    .get_events()
                    .publish("view/delete", {
                        id: view.id
                    });

            });

        });

    },

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

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

    _showConfirmationDialog: function (callback) {

        PDJS.Manage.Views.ViewDeleteDialog.open({
            select: (e) => {
                callback(e);
            }
        });

    }

});
