import { useState } from 'react'; import { Button } from '@/components/ui/button'; import { Dialog, DialogContent, DialogHeader, DialogTitle } from '@/components/ui/dialog'; import { History } from 'lucide-react'; import { formatDistanceToNow } from 'date-fns'; import { EntityVersionHistory } from './EntityVersionHistory'; import { useEntityVersions } from '@/hooks/useEntityVersions'; import type { EntityType } from '@/types/versioning'; interface VersionIndicatorProps { entityType: EntityType; entityId: string; entityName: string; compact?: boolean; } export function VersionIndicator({ entityType, entityId, entityName, compact = false, }: VersionIndicatorProps) { const [showHistory, setShowHistory] = useState(false); const { currentVersion, loading } = useEntityVersions(entityType, entityId); if (loading || !currentVersion) { return null; } const timeAgo = currentVersion.created_at ? formatDistanceToNow(new Date(currentVersion.created_at), { addSuffix: true }) : 'Unknown'; if (compact) { return ( <> Version History: {entityName} ); } return ( <>
Last edited {timeAgo}
Version History: {entityName} ); }