/// class PD.Manage.Modules.DocumentTypeDeleteCommand

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

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

    setDefaults: function () {

        this.props("id", "document-type/delete");
        this.props("enabled", false);
        this.props("icon", PD.Path.to16x16("delete.png"));
        this.props("label", "Delete");
        this.props("tooltip", "Delete the selected Document Type.");

        this.state("documentType", null);

    },

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

    isEnabled: function () {
        return this.state("documentType") != null
            && this.state("documentType").id != null;
    },

    execute: function (e) {
        this._super(e);
        
        let documentType = this.state("documentType");

        Jade.UI.MessageDialog.open({
            dialogStyle: Jade.UI.MessageDialogStyle.Warning,
            dialogButtons: Jade.UI.MessageDialogButtonStyle.OKCancel,
            allowClose: true,
            title: "Delete Document Type",
            message: this._getDeletePromptText(),
            select: (e) => {
                e.close();
                if (e.button === Jade.UI.MessageDialogButton.ok) {
                    this._executeDelete(documentType);
                }
            }
        });

    },

    _getDeletePromptText: function (fileCount) {

        var result = ["Delete the selected document type?"];
        var prompt = [
            "<br/><br/>",
            "<b>WARNING:</b> This document type is currently in use. ",
            "Proceeding with deletion will remove this document type assignment",
            "from all documents to which it is currently assigned."
        ];

        if (fileCount > 0) {
            result = result.concat(result, prompt);
        }

        return result.join("");

    },

    _executeDelete: function (documentType) {

        let service = new PD.Manage.Services.DocumentTypeService();

        service.deleteDocumentType(documentType.id, function () {
            PD.context.get_default().get_events().publish("document-type/delete", {
                id: documentType.id
            });
        });

    }

});