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, parseTabKey, } 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 FeatureDrawerTabPage({ params }) {
    const { featureId, tab } = await params;
    const urlTab = parseTabKey(tab);
    try {
        const featureRepo = resolve('IFeatureRepository');
        const agentRunRepo = resolve('IAgentRunRepository');
        const repoRepo = resolve('IRepositoryRepository');
        const gitPrService = resolve('IGitPrService');
        const feature = await featureRepo.findById(featureId);
        if (!feature)
            return null;
        const run = feature.agentRunId ? await agentRunRepo.findById(feature.agentRunId) : null;
        const getArtifact = resolve('GetFeatureArtifactUseCase');
        const [repo, baseBranch, artifact, remoteUrl] = await Promise.all([
            repoRepo.findByPath(feature.repositoryPath).catch(() => null),
            gitPrService.getDefaultBranch(feature.repositoryPath).catch(() => 'main'),
            getArtifact.execute(featureId).catch(() => null),
            gitPrService.getRemoteUrl(feature.repositoryPath).catch(() => null),
        ]);
        const { workflow, interactiveAgent } = getSettings();
        const nodeData = buildFeatureNodeData(feature, run, {
            repositoryName: repo?.name,
            baseBranch,
            oneLiner: artifact?.oneLiner,
            remoteUrl: remoteUrl ?? undefined,
            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, urlTab: urlTab, interactiveAgentEnabled: interactiveAgent?.enabled ?? true }));
    }
    catch {
        return null;
    }
}
