import { jsx as _jsx } from "react/jsx-runtime";
import { resolve } from '../../../../../lib/server-container.js';
import { buildFeatureNodeData } from '../../../../build-feature-node-data.js';
import { getSettings } from '../../../../../../../../packages/core/src/infrastructure/services/settings.service.js';
import { computeDrawerView } from '../../../../../components/common/control-center-drawer/drawer-view.js';
import { FeatureDrawerClient } from '../../../../../components/common/control-center-drawer/feature-drawer-client.js';
/** Skip static pre-rendering since we need runtime DI container. */
export const dynamic = 'force-dynamic';
export default async function FeatureDrawerPage({ params }) {
    const { featureId } = await params;
    try {
        const featureRepo = resolve('IFeatureRepository');
        const agentRunRepo = resolve('IAgentRunRepository');
        // Critical path only: feature + agent run (fast DB lookups).
        // Expensive operations (git remote URL, GitHub CI/mergeable status,
        // artifact, repo name, base branch) are deferred to useDrawerSync
        // which runs client-side after the drawer is already visible.
        const feature = await featureRepo.findById(featureId);
        if (!feature)
            return null;
        const run = feature.agentRunId ? await agentRunRepo.findById(feature.agentRunId) : null;
        const { workflow, interactiveAgent } = getSettings();
        const nodeData = buildFeatureNodeData(feature, run, {
            enableEvidence: workflow.enableEvidence,
            commitEvidence: workflow.commitEvidence,
            ciWatchEnabled: workflow.ciWatchEnabled,
        });
        const view = computeDrawerView({
            selectedNode: nodeData,
            isCreateDrawerOpen: false,
            pendingRepositoryPath: '',
            pendingParentFeatureId: undefined,
            selectedRepoNode: null,
            features: [],
            workflowDefaults: undefined,
        });
        if (!view)
            return null;
        return (_jsx(FeatureDrawerClient, { view: view, interactiveAgentEnabled: interactiveAgent?.enabled ?? true }));
    }
    catch {
        // Feature not found — render nothing (drawer stays closed)
        return null;
    }
}
