/**
 * Pilot/Lab-Widgets registrieren. IDs müssen zu backend/widget_catalog.WIDGET_CATALOG passen.
 */
import PilotWelcome from '../components/pilot/PilotWelcome'
import PilotQuickCapture from '../components/pilot/PilotQuickCapture'
import PilotKpiBoard from '../components/pilot/PilotKpiBoard'
import PilotBodySection from '../components/pilot/PilotBodySection'
import PilotActivitySection from '../components/pilot/PilotActivitySection'
import DashboardGreetingWidget from '../components/dashboard-widgets/DashboardGreetingWidget'
import QuickWeightTodayWidget from '../components/dashboard-widgets/QuickWeightTodayWidget'
import BodyStatStripWidget from '../components/dashboard-widgets/BodyStatStripWidget'
import StatusPillsWidget from '../components/dashboard-widgets/StatusPillsWidget'
import ProfileGoalsProgressWidget from '../components/dashboard-widgets/ProfileGoalsProgressWidget'
import TrendKcalWeightWidget from '../components/dashboard-widgets/TrendKcalWeightWidget'
import NutritionActivitySummaryWidget from '../components/dashboard-widgets/NutritionActivitySummaryWidget'
import NutritionDetailChartsWidget from '../components/dashboard-widgets/NutritionDetailChartsWidget'
import RecoveryChartsPanelWidget from '../components/dashboard-widgets/RecoveryChartsPanelWidget'
import ProgressPhotosWidget from '../components/dashboard-widgets/ProgressPhotosWidget'
import RecoverySleepRestWidget from '../components/dashboard-widgets/RecoverySleepRestWidget'
import GoalsFocusTeaserWidget from '../components/dashboard-widgets/GoalsFocusTeaserWidget'
import AiPipelineInsightWidget from '../components/dashboard-widgets/AiPipelineInsightWidget'
import { normalizeBodyChartDays } from './bodyChartDays'
import { registerDashboardWidget } from './dashboardWidgetRegistry'

let _registered = false

export function ensurePilotLabWidgetsRegistered() {
  if (_registered) return
  _registered = true

  registerDashboardWidget({
    id: 'welcome',
    Component: PilotWelcome,
    mapProps: () => ({}),
  })
  registerDashboardWidget({
    id: 'quick_capture',
    Component: PilotQuickCapture,
    mapProps: (ctx) => ({
      onSaved: ctx.requestRefresh,
      captureConfig: ctx.layoutEntry?.config || {},
    }),
  })
  registerDashboardWidget({
    id: 'kpi_board',
    Component: PilotKpiBoard,
    mapProps: (ctx) => ({
      refreshTick: ctx.refreshTick,
      kpiConfig: ctx.layoutEntry?.config || {},
    }),
  })
  registerDashboardWidget({
    id: 'body_overview',
    Component: PilotBodySection,
    mapProps: (ctx) => ({
      refreshTick: ctx.refreshTick,
      chartDays: normalizeBodyChartDays(ctx.layoutEntry?.config?.chart_days),
    }),
  })
  registerDashboardWidget({
    id: 'activity_overview',
    Component: PilotActivitySection,
    mapProps: (ctx) => ({
      refreshTick: ctx.refreshTick,
      chartDays: normalizeBodyChartDays(ctx.layoutEntry?.config?.chart_days),
    }),
  })

  registerDashboardWidget({
    id: 'dashboard_greeting',
    Component: DashboardGreetingWidget,
    mapProps: (ctx) => ({ refreshTick: ctx.refreshTick }),
  })
  registerDashboardWidget({
    id: 'quick_weight_today',
    Component: QuickWeightTodayWidget,
    mapProps: (ctx) => ({ onSaved: ctx.requestRefresh }),
  })
  registerDashboardWidget({
    id: 'body_stat_strip',
    Component: BodyStatStripWidget,
    mapProps: (ctx) => ({ refreshTick: ctx.refreshTick }),
  })
  registerDashboardWidget({
    id: 'status_pills',
    Component: StatusPillsWidget,
    mapProps: (ctx) => ({ refreshTick: ctx.refreshTick }),
  })
  registerDashboardWidget({
    id: 'profile_goals_progress',
    Component: ProfileGoalsProgressWidget,
    mapProps: (ctx) => ({ refreshTick: ctx.refreshTick }),
  })
  registerDashboardWidget({
    id: 'trend_kcal_weight',
    Component: TrendKcalWeightWidget,
    mapProps: (ctx) => ({
      refreshTick: ctx.refreshTick,
      chartDays: ctx.layoutEntry?.config?.chart_days,
    }),
  })
  registerDashboardWidget({
    id: 'nutrition_activity_summary',
    Component: NutritionActivitySummaryWidget,
    mapProps: (ctx) => ({ refreshTick: ctx.refreshTick }),
  })
  registerDashboardWidget({
    id: 'nutrition_detail_charts',
    Component: NutritionDetailChartsWidget,
    mapProps: (ctx) => ({
      refreshTick: ctx.refreshTick,
      chartDays: ctx.layoutEntry?.config?.chart_days,
    }),
  })
  registerDashboardWidget({
    id: 'recovery_charts_panel',
    Component: RecoveryChartsPanelWidget,
    mapProps: (ctx) => ({
      refreshTick: ctx.refreshTick,
      chartDays: ctx.layoutEntry?.config?.chart_days,
    }),
  })
  registerDashboardWidget({
    id: 'progress_photos',
    Component: ProgressPhotosWidget,
    mapProps: (ctx) => ({ refreshTick: ctx.refreshTick }),
  })
  registerDashboardWidget({
    id: 'recovery_sleep_rest',
    Component: RecoverySleepRestWidget,
    mapProps: () => ({}),
  })
  registerDashboardWidget({
    id: 'goals_focus_teaser',
    Component: GoalsFocusTeaserWidget,
    mapProps: (ctx) => ({ refreshTick: ctx.refreshTick }),
  })
  registerDashboardWidget({
    id: 'ai_pipeline_insight',
    Component: AiPipelineInsightWidget,
    mapProps: (ctx) => ({ refreshTick: ctx.refreshTick }),
  })
}

/** @internal Nur für Tests */
export function __resetPilotLabRegistrationForTests() {
  _registered = false
}
