import { format } from 'date-fns'
import { CheckCircle, Clock, Loader, Mic, Trash2, Volume2 } from 'lucide-react'
import { Badge } from '@/components/ui/badge'
import { Button } from '@/components/ui/button'
import {
Table,
TableBody,
TableCell,
TableHead,
TableHeader,
TableRow,
} from '@/components/ui/table'
import { Tooltip, TooltipContent, TooltipTrigger } from '@/components/ui/tooltip'
import { type TTSResponse, ttsService } from '@/lib/api/services/tts'
import { soundsService } from '@/lib/api/services/sounds'
import { toast } from 'sonner'
interface TTSTableProps {
ttsHistory: TTSResponse[]
onTTSDeleted?: (ttsId: number) => void
}
export function TTSTable({ ttsHistory, onTTSDeleted }: TTSTableProps) {
const handlePlaySound = async (tts: TTSResponse) => {
if (!tts.sound_id) {
toast.error('This TTS is still being processed.')
return
}
try {
await soundsService.playSound(tts.sound_id)
} catch (error) {
toast.error('Failed to play the sound.')
}
}
const handleDeleteTTS = async (tts: TTSResponse) => {
if (!confirm(`Are you sure you want to delete this TTS generation?\n\n"${tts.text}"\n\nThis will also delete the associated sound file and cannot be undone.`)) {
return
}
try {
await ttsService.deleteTTS(tts.id)
toast.success('TTS generation deleted successfully')
onTTSDeleted?.(tts.id)
} catch (error) {
toast.error('Failed to delete TTS generation')
}
}
const getProviderColor = (provider: string) => {
const colors = {
gtts: 'bg-blue-100 text-blue-800 dark:bg-blue-900 dark:text-blue-300',
}
return colors[provider as keyof typeof colors] || 'bg-gray-100 text-gray-800 dark:bg-gray-900 dark:text-gray-300'
}
const getStatusBadge = (tts: TTSResponse) => {
const isCompleted = tts.sound_id !== null
if (isCompleted) {
return (