import { Check, Circle, Loader2 } from 'lucide-react'
import { Card, Table, TableBody, TableCell, TableHead, TableHeader, TableRow, cn } from 'ui'
import { BACKUP_STEP, DATABASE_UPGRADE_STEPS } from './UpgradingState.constants'
type UpgradeStepsTableProps =
| {
/**
* Pre-upgrade view: all steps shown as pending
*/
variant: 'pending'
}
| {
/**
* Active upgrade view: shows current progress through steps
*/
variant: 'upgrading'
progress: string | undefined
}
| {
/**
* Backing up view: all upgrade steps completed, backup step in progress
*/
variant: 'backingUp'
}
| {
/**
* Completed view: all steps including backup shown as completed
*/
variant: 'completed'
}
| {
/**
* Failed view: all steps shown as completed (project is back online)
*/
variant: 'failed'
}
export const UpgradeStepsTable = (props: UpgradeStepsTableProps) => {
const { variant } = props
const progress = variant === 'upgrading' ? props.progress : undefined
const progressStage = Number((progress || '').split('_')[0])
const isTerminalState = variant === 'completed' || variant === 'failed'
const showProgress = variant === 'upgrading' || variant === 'backingUp' || isTerminalState
const allUpgradeStepsCompleted = variant === 'backingUp' || isTerminalState
// Only append backup step when actively backing up
const steps =
variant === 'backingUp' ? [...DATABASE_UPGRADE_STEPS, BACKUP_STEP] : DATABASE_UPGRADE_STEPS
return (
{/* Manual strike-through to ensure proper centering */}
{isCurrentStep ? step.activeTitle : step.staticTitle}
{statusText}