import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { notFound } from 'next/navigation';
import { getFeatureFlags } from '../../lib/feature-flags.js';
import { resolve } from '../../lib/server-container.js';
import { OnboardingTutorial } from '../../components/onboarding/onboarding-tutorial.js';
import { ContributorOnboardingView } from '../../components/contributors/ContributorOnboardingView.js';
export const dynamic = 'force-dynamic';
const LEADERBOARD_LIMIT = 7;
async function loadInitialLeaderboard() {
    try {
        const useCase = resolve('GetContributorLeaderboardUseCase');
        const result = await useCase.execute({ scope: 'month', limit: LEADERBOARD_LIMIT });
        const entries = result.entries.map((e) => ({
            login: e.login,
            displayName: e.displayName,
            avatarUrl: e.avatarUrl,
            prCount: e.prCount,
            level: e.level,
            lane: e.lane,
        }));
        return { entries };
    }
    catch (error) {
        return {
            entries: [],
            error: error instanceof Error ? error.message : 'Failed to load leaderboard',
        };
    }
}
async function loadInitialDoctorReport() {
    try {
        const useCase = resolve('RunDoctorUseCase');
        const report = await useCase.execute();
        return {
            report: {
                results: report.results.map((r) => ({
                    name: r.name,
                    status: r.status,
                    detail: r.detail,
                    fixHint: r.fixHint,
                })),
                overallStatus: report.overallStatus,
                summary: report.summary,
            },
        };
    }
    catch (error) {
        return { error: error instanceof Error ? error.message : 'Doctor unavailable' };
    }
}
export default async function OnboardingRoute() {
    const flags = getFeatureFlags();
    if (!flags.collaboration) {
        notFound();
    }
    const [leaderboard, doctor] = await Promise.all([
        loadInitialLeaderboard(),
        loadInitialDoctorReport(),
    ]);
    return (_jsxs("div", { className: "mx-auto flex w-full max-w-3xl flex-col gap-12 p-6", children: [_jsx(ContributorOnboardingView, { initialLeaderboard: {
                    scope: 'month',
                    entries: leaderboard.entries,
                    error: leaderboard.error,
                }, initialDoctorReport: doctor.report, doctorError: doctor.error }), _jsx(OnboardingTutorial, {})] }));
}
