'use client'; import { RefreshCw, Edit, Trash2, Clock, AlertCircle, ChevronDown, ChevronUp } from 'lucide-react'; import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'; import MarkdownRenderer from '@/components/MarkdownRenderer'; import { useState } from 'react'; interface Source { url: string; type: 'Web Page' | 'HTTP Data'; } interface Widget { id: string; title: string; sources: Source[]; prompt: string; provider: string; model: string; refreshFrequency: number; refreshUnit: 'minutes' | 'hours'; lastUpdated: Date | null; isLoading: boolean; content: string | null; error: string | null; } interface WidgetDisplayProps { widget: Widget; onEdit: (widget: Widget) => void; onDelete: (widgetId: string) => void; onRefresh: (widgetId: string) => void; } const WidgetDisplay = ({ widget, onEdit, onDelete, onRefresh }: WidgetDisplayProps) => { const [isFooterExpanded, setIsFooterExpanded] = useState(false); const formatLastUpdated = (date: Date | null) => { if (!date) return 'Never'; const now = new Date(); const diffMs = now.getTime() - date.getTime(); const diffMins = Math.floor(diffMs / (1000 * 60)); const diffHours = Math.floor(diffMins / 60); const diffDays = Math.floor(diffHours / 24); if (diffMins < 1) return 'Just now'; if (diffMins < 60) return `${diffMins}m ago`; if (diffHours < 24) return `${diffHours}h ago`; return `${diffDays}d ago`; }; const getRefreshFrequencyText = () => { return `Every ${widget.refreshFrequency} ${widget.refreshUnit}`; }; return (
{widget.title}
{/* Last updated date with refresh frequency tooltip */} {formatLastUpdated(widget.lastUpdated)} {/* Refresh button */}
{widget.isLoading ? (
Loading content...
) : widget.error ? (

Error Loading Content

{widget.error}

) : widget.content ? (
) : (

No content yet

Click refresh to load content

)}
{/* Collapsible footer with sources and actions */}
{isFooterExpanded && (
{/* Sources */} {widget.sources.length > 0 && (

Sources:

{widget.sources.map((source, index) => (
{source.url} ({source.type})
))}
)} {/* Action buttons */}
)}
); }; export default WidgetDisplay;