/// class PD.Manage.Modules.Resources.ResourceEditor
// using PD.Manage.Module

PD.Manage.Modules.Resources.ResourceEditor =
PD.Manage.Module.extend({

    //===================================
    // FIELDS
    //===================================

    _module: null,

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

    onActivate: function () {

        let id = this.data("targetId");
        let isGuid = Jade.Guid.isGuid(id);
        let fileType = id.toLowerCase().split(",")[0];
        let folderId = id.toLowerCase().split(",")[1];

        this._module = new PDJS.Manage.Resources.Editor.EditorModule({
            container: $(`div[id=${this.get_id()}]`),
            fileId: isGuid ? id : null,
            fileType: isGuid ? null : fileType,
            folderId: isGuid ? null : folderId,
            moduleId: this.data("id"),
            success: (e) => {
                this.data("label", e.fileName);
                this.data("tooltip", `<div class="-pd-module-tab-tooltip-resources">${e.folderPath}</div>`);
                this.ready();
            },
            error: (e) => {
                this.error(e);
            }
        });

    },

    onFocus: function () {
        this._module.focus();
    },

    remove: function () {
        this._super();
        if (this._module) {
            this._module.destroy();
        }
    },

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

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

});