import { Download, Edit, Mic, Trash2 } from 'lucide-react'; import { useState } from 'react'; import { Badge } from '@/components/ui/badge'; import { Button } from '@/components/ui/button'; import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'; import { CircleButton } from '@/components/ui/circle-button'; import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from '@/components/ui/dialog'; import type { VoiceProfileResponse } from '@/lib/api/types'; import { useDeleteProfile, useExportProfile } from '@/lib/hooks/useProfiles'; import { cn } from '@/lib/utils/cn'; import { useServerStore } from '@/stores/serverStore'; import { useUIStore } from '@/stores/uiStore'; interface ProfileCardProps { profile: VoiceProfileResponse; } export function ProfileCard({ profile }: ProfileCardProps) { const [deleteDialogOpen, setDeleteDialogOpen] = useState(false); const [avatarError, setAvatarError] = useState(false); const deleteProfile = useDeleteProfile(); const exportProfile = useExportProfile(); const setEditingProfileId = useUIStore((state) => state.setEditingProfileId); const setProfileDialogOpen = useUIStore((state) => state.setProfileDialogOpen); const selectedProfileId = useUIStore((state) => state.selectedProfileId); const setSelectedProfileId = useUIStore((state) => state.setSelectedProfileId); const serverUrl = useServerStore((state) => state.serverUrl); const isSelected = selectedProfileId === profile.id; const avatarUrl = profile.avatar_path ? `${serverUrl}/profiles/${profile.id}/avatar` : null; const handleSelect = () => { setSelectedProfileId(isSelected ? null : profile.id); }; const handleEdit = () => { setEditingProfileId(profile.id); setProfileDialogOpen(true); }; const handleDeleteClick = (e: React.MouseEvent) => { e.stopPropagation(); setDeleteDialogOpen(true); }; const handleDeleteConfirm = () => { deleteProfile.mutate(profile.id); setDeleteDialogOpen(false); }; const handleExport = (e: React.MouseEvent) => { e.stopPropagation(); exportProfile.mutate(profile.id); }; const handleKeyDown = (e: React.KeyboardEvent) => { const target = e.target as HTMLElement; if (target.closest('button')) return; if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); handleSelect(); } }; const selectLabel = isSelected ? `${profile.name}, ${profile.language}. Selected as voice for generation.` : `${profile.name}, ${profile.language}. Select as voice for generation.`; return ( <> {avatarUrl && !avatarError ? ( setAvatarError(true)} /> ) : ( )} {profile.name} {profile.description || 'No description'} {profile.language} { e.stopPropagation(); handleEdit(); }} aria-label="Edit profile" /> Delete Profile Are you sure you want to delete "{profile.name}"? This action cannot be undone. setDeleteDialogOpen(false)}> Cancel {deleteProfile.isPending ? 'Deleting...' : 'Delete'} > ); }
{profile.description || 'No description'}