/// 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);

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

        this._showConfirmationDialog(function (e) {

            var deleteLinked = e.value === "delete";

            e.close();

            service.deleteView(view.id, deleteLinked, function (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) {

        var message = [
            "The view you are attempting to delete may have linked views. ",
            "A linked view is a view created by an end user which uses this view as its source.",
            "<br/><br/>",
            "How do you want to handle any linked views found during the deletion process.",
            "{{options}}",
            "<b>WARNING:</b> This action cannot be undone."
        ];

        var deleteMessage = [
            "<b>Delete the view and all of its linked views.</b><br/>",
            "This will permanently delete this view and all views users have created using this view from the system. ",
            "Suggested if the view is considered completely invalid."
        ];

        var unlinkMessage = [
            "<b>Delete the view and unlink its linked views.</b><br/>",
            "This will allow users that may have created new views from this view to retain those views. ",
            "Suggested if the view is no longer required, but the view is still considered valid."
        ];

        PD.Web.UI.RadioDialog.warn({
            message: message.join(""),
            ok: callback,
            radios: [
                { value: "delete", label: deleteMessage.join("") },
                { value: "unlink", label: unlinkMessage.join("") }
            ]
        });

    }

});
