/** All valid tab key values — used for URL param validation. */
export const VALID_TAB_KEYS = new Set([
    'overview',
    'activity',
    'log',
    'plan',
    'prd-review',
    'tech-decisions',
    'product-decisions',
    'merge-review',
    'chat',
    'bedrock',
]);
/** Type-guard: returns the value as FeatureTabKey if valid, otherwise undefined. */
export function parseTabKey(value) {
    if (value && VALID_TAB_KEYS.has(value))
        return value;
    return undefined;
}
/** Derives the initial tab from node lifecycle + state. */
export function deriveInitialTab(node) {
    if (node.lifecycle === 'requirements' && node.state === 'action-required')
        return 'prd-review';
    // Fast-mode features skip the tech-decisions phase entirely, so don't focus
    // a tab that isn't visible.
    if (!node.fastMode && node.lifecycle === 'implementation' && node.state === 'action-required')
        return 'tech-decisions';
    if (node.lifecycle === 'review' && (node.state === 'action-required' || node.state === 'error'))
        return 'merge-review';
    return 'overview';
}
/**
 * Derives the active DrawerView from control-center state.
 * Priority: feature-create > selected-node > repository
 */
export function computeDrawerView({ selectedNode, isCreateDrawerOpen, pendingRepositoryPath, pendingParentFeatureId, selectedRepoNode, features, workflowDefaults, }) {
    if (isCreateDrawerOpen) {
        return {
            type: 'feature-create',
            repositoryPath: pendingRepositoryPath,
            initialParentId: pendingParentFeatureId,
            features,
            workflowDefaults,
        };
    }
    if (selectedNode) {
        return { type: 'feature', node: selectedNode, initialTab: deriveInitialTab(selectedNode) };
    }
    if (selectedRepoNode) {
        return { type: 'repository', data: selectedRepoNode };
    }
    return null;
}
