/// class PD.Manage.Modules.EntityType
/// using PD.Manage.Module

PD.Manage.Modules.EntityType =
PD.Manage.Module.extend({

    //===================================
    // FIELDS
    //===================================
    
    _module: null,
    
    //===================================
    // EVENT HANDLERS
    //===================================

    onPrepare: function () {

        PD.ajax({
            url: PD.Path.resolve("~/Manage/EntityType/Index/" + this.data("targetId")),
            success: (data) => {
                this.data("entityTypeId", data.entityTypeId);
                this.data("entityTypeName", data.entityTypeName);
                this.data("explorerModel", data.explorerModel);
                this.data("label", data.entityTypeName);
                this.data("tooltip", `<div class="-pd-module-tab-tooltip-resources">Entity Type</div>`);
                this.ready();
            },
            error: (e) => {
                this.error();
                e.errorHandled = true;
            }
        });

    },


    onActivate: function () {
        this._init_module();
    },

    onFocus: function () {
        if (this._module != null) {
            this._module.resize();
        }
    },

    onRemove: function () {
        if (this._module != null) {
            this._module.destroy();
        }
    },

    //===================================
    // PROTECTED METHODS
    //===================================

    template: function (e) {
        return `<div style="position:absolute;inset:0;overflow:hidden;"></div>`;
    },

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

    _init_module: function () {

        this._module = new PDJS.Manage.EntityType.EntityTypeModule({
            container: $(`div[id=${this.get_id()}]`),
            entityTypeId: this.data("entityTypeId"),
            entityTypeName: this.data("entityTypeName"),
            explorerModel: this.data("explorerModel")
        });

    }

});