/// class PD.Manage.Modules.RecycleBinEmptyCommand

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

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

    setDefaults: function () {
        this.props("id", "recycle-bin/empty");
        this.props("enabled", true);
        this.props("icon", PD.Path.to16x16("arrow_circle2.png"));
        this.props("label", "Empty Recycle Bin");
        this.props("tooltip", "Permanently delete all Entities in the Recycle Bin.");
    },

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

        PDJS.Manage.RecycleBin.RecycleBinConfirmationDialog.open({
            select: (e) => {
                this._emptyRecycleBin(e === "delete");
            }
        });

    },

    _emptyRecycleBin: function (deleteReferences) {

        PDJS.Shared.TaskStatusDialog.open({
            title: "Empty Recycle Bin",
            taskStart: (e) => {

                PD.ajax({
                    type: "DELETE",
                    url: PD.Path.resolve("~/Manage/RecycleBin/Empty"),
                    data: {
                        removeReferences: deleteReferences
                    },
                    success: (e2) => {
                        e.startPolling(e2);
                    },
                    error: (e2) => {
                        e.abort(e2.responseJSON);
                        e2.errorHandled = true;
                    }
                });

            },
            taskSuccess: (e) => {

                PD.context
                    .get_default()
                    .get_events()
                    .publish("recycle-bin/empty");

            }
        });

    }

});