var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
import { Component, ChangeDetectionStrategy, ViewChild } from '@angular/core';
import { Subject } from 'rxjs';
import { RegisterClass } from '@memberjunction/global';
import { BaseResourceComponent } from '@memberjunction/ng-shared';
import { DataExplorerDashboardComponent } from './data-explorer-dashboard.component';
import * as i0 from "@angular/core";
import * as i1 from "@memberjunction/ng-shared";
import * as i2 from "./data-explorer-dashboard.component";
/**
 * Resource component for the Data Explorer.
 * Wraps DataExplorerDashboardComponent as a BaseResourceComponent for use
 * in application nav items with ResourceType: "Custom".
 */
let DataExplorerResourceComponent = class DataExplorerResourceComponent extends BaseResourceComponent {
    cdr;
    navigationService;
    // ========================================
    // State
    // ========================================
    entityFilter = null;
    contextName = null;
    contextIcon = null;
    dataExplorer;
    _destroy$ = new Subject();
    _dataLoaded = false;
    // ========================================
    // Constructor
    // ========================================
    constructor(cdr, navigationService) {
        super();
        this.cdr = cdr;
        this.navigationService = navigationService;
    }
    // ========================================
    // Data Property Override
    // ========================================
    set Data(value) {
        const previousConfig = JSON.stringify(super.Data?.Configuration || {});
        super.Data = value;
        const newConfig = JSON.stringify(value?.Configuration || {});
        // Load on first set, or when the configuration has changed
        if (!this._dataLoaded || previousConfig !== newConfig) {
            this._dataLoaded = true;
            this.loadConfiguration();
        }
    }
    get Data() {
        return super.Data;
    }
    // ========================================
    // Lifecycle
    // ========================================
    ngOnInit() {
        // Configuration loaded via Data setter
    }
    ngOnDestroy() {
        this._destroy$.next();
        this._destroy$.complete();
    }
    // ========================================
    // BaseResourceComponent Implementation
    // ========================================
    async GetResourceDisplayName(data) {
        return data.Name || 'Data';
    }
    async GetResourceIconClass(data) {
        return 'fa-solid fa-table-cells';
    }
    // ========================================
    // Private Methods
    // ========================================
    loadConfiguration() {
        const data = this.Data;
        if (!data) {
            this.NotifyLoadComplete();
            return;
        }
        const config = data.Configuration || {};
        // Extract configuration options
        this.entityFilter = config['entityFilter'] || null;
        this.contextName = config['appName'] || null;
        this.contextIcon = config['appIcon'] || null;
        this.cdr.detectChanges();
        // Setup LoadCompleteEvent after view initializes
        setTimeout(() => {
            if (this.dataExplorer) {
                this.dataExplorer.LoadCompleteEvent = () => {
                    this.NotifyLoadComplete();
                };
                // Initialize with minimal config (no database dashboard)
                const dashboardConfig = {
                    dashboard: null,
                    userState: {}
                };
                this.dataExplorer.Config = dashboardConfig;
                this.dataExplorer.Refresh();
            }
            else {
                this.NotifyLoadComplete();
            }
        }, 0);
    }
    // ========================================
    // Event Handlers
    // ========================================
    onOpenEntityRecord(event) {
        if (event && event.EntityName && event.RecordPKey) {
            this.navigationService.OpenEntityRecord(event.EntityName, event.RecordPKey);
        }
    }
    onDisplayNameChanged(name) {
        this.NotifyDisplayNameChanged(name);
    }
    static ɵfac = function DataExplorerResourceComponent_Factory(__ngFactoryType__) { return new (__ngFactoryType__ || DataExplorerResourceComponent)(i0.ɵɵdirectiveInject(i0.ChangeDetectorRef), i0.ɵɵdirectiveInject(i1.NavigationService)); };
    static ɵcmp = /*@__PURE__*/ i0.ɵɵdefineComponent({ type: DataExplorerResourceComponent, selectors: [["mj-data-explorer-resource"]], viewQuery: function DataExplorerResourceComponent_Query(rf, ctx) { if (rf & 1) {
            i0.ɵɵviewQuery(DataExplorerDashboardComponent, 5);
        } if (rf & 2) {
            let _t;
            i0.ɵɵqueryRefresh(_t = i0.ɵɵloadQuery()) && (ctx.dataExplorer = _t.first);
        } }, standalone: false, features: [i0.ɵɵInheritDefinitionFeature], decls: 2, vars: 3, consts: [[1, "data-explorer-resource-container"], [3, "OpenEntityRecord", "DisplayNameChanged", "entityFilter", "contextName", "contextIcon"]], template: function DataExplorerResourceComponent_Template(rf, ctx) { if (rf & 1) {
            i0.ɵɵelementStart(0, "div", 0)(1, "mj-data-explorer-dashboard", 1);
            i0.ɵɵlistener("OpenEntityRecord", function DataExplorerResourceComponent_Template_mj_data_explorer_dashboard_OpenEntityRecord_1_listener($event) { return ctx.onOpenEntityRecord($event); })("DisplayNameChanged", function DataExplorerResourceComponent_Template_mj_data_explorer_dashboard_DisplayNameChanged_1_listener($event) { return ctx.onDisplayNameChanged($event); });
            i0.ɵɵelementEnd()();
        } if (rf & 2) {
            i0.ɵɵadvance();
            i0.ɵɵproperty("entityFilter", ctx.entityFilter)("contextName", ctx.contextName)("contextIcon", ctx.contextIcon);
        } }, dependencies: [i2.DataExplorerDashboardComponent], styles: ["[_nghost-%COMP%] {\n            display: block;\n            width: 100%;\n            height: 100%;\n        }\n        .data-explorer-resource-container[_ngcontent-%COMP%] {\n            width: 100%;\n            height: 100%;\n        }"], changeDetection: 0 });
};
DataExplorerResourceComponent = __decorate([
    RegisterClass(BaseResourceComponent, 'DataExplorerResource')
], DataExplorerResourceComponent);
export { DataExplorerResourceComponent };
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(DataExplorerResourceComponent, [{
        type: Component,
        args: [{ standalone: false, selector: 'mj-data-explorer-resource', template: `
        <div class="data-explorer-resource-container">
            <mj-data-explorer-dashboard
                [entityFilter]="entityFilter"
                [contextName]="contextName"
                [contextIcon]="contextIcon"
                (OpenEntityRecord)="onOpenEntityRecord($event)"
                (DisplayNameChanged)="onDisplayNameChanged($event)">
            </mj-data-explorer-dashboard>
        </div>
    `, changeDetection: ChangeDetectionStrategy.OnPush, styles: ["\n        :host {\n            display: block;\n            width: 100%;\n            height: 100%;\n        }\n        .data-explorer-resource-container {\n            width: 100%;\n            height: 100%;\n        }\n    "] }]
    }], () => [{ type: i0.ChangeDetectorRef }, { type: i1.NavigationService }], { dataExplorer: [{
            type: ViewChild,
            args: [DataExplorerDashboardComponent]
        }] }); })();
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassDebugInfo(DataExplorerResourceComponent, { className: "DataExplorerResourceComponent", filePath: "src/DataExplorer/data-explorer-resource.component.ts", lineNumber: 42 }); })();
//# sourceMappingURL=data-explorer-resource.component.js.map