import "./request-timeline";
import "./cache-runtime-records";

import initCharts from "./charts";
import initKpiCards from "./kpi-cards";
import initActivityOverview from "./components/activity-overview";
import initTechnicalInsightsExplorer from "./components/technical-insights-explorer";
import initExternalRequestsPreview from "./components/external-requests-preview";
import initCacheRuntimeHealth from "./components/cache-runtime-health";
import initDatabaseObservability from "./components/database-observability";
import initBreakdownDonut from "./components/breakdown-donut";

(function nativeObservabilityDashboardBehavior(Drupal, once, drupalSettings) {
  /**
   * Attaches the Native Observability dashboard frontend behaviors.
   */
  Drupal.behaviors.nativeObservabilityDashboard = {
    attach(context) {
      once(
        "native-observability-dashboard",
        ".no-dashboard-wrapper",
        context,
      ).forEach((element) => {
        initKpiCards(element);
        initCharts(element);
        initActivityOverview(element);
        initTechnicalInsightsExplorer(
          element,
          drupalSettings.nativeObservabilityDashboard
            ?.technicalInsightsExplorer || null,
        );
        initExternalRequestsPreview(
          element,
          drupalSettings.nativeObservabilityDashboard
            ?.externalRequestsPreview || null,
        );
        initCacheRuntimeHealth(
          element,
          drupalSettings.nativeObservabilityDashboard
            ?.cacheObservabilityCharts || {},
        );
        initDatabaseObservability(
          element,
          drupalSettings.nativeObservabilityDashboard
            ?.databaseObservabilityCharts || {},
        );
        initBreakdownDonut(
          element,
          drupalSettings.nativeObservabilityDashboard?.breakdownDonut || null,
        );
      });
    },
  };
})(Drupal, once, drupalSettings);
