'use client' import { useState, useEffect } from 'react' import { draftService, Draft } from '@/services/draftService' import { useToast } from '@/components/ui/toast' interface DraftManagerProps { onLoadDraft: (draft: { id: string; content: string | null; mediaUrls: string[] }) => void onClose: () => void } export default function DraftManager({ onLoadDraft, onClose }: DraftManagerProps) { const [drafts, setDrafts] = useState([]) const [loading, setLoading] = useState(true) const [deletingId, setDeletingId] = useState(null) const { showToast } = useToast() useEffect(() => { loadDrafts() }, []) const loadDrafts = async () => { try { const data = await draftService.getDrafts() setDrafts(Array.isArray(data) ? data : []) } catch { setDrafts([]) } finally { setLoading(false) } } const handleDelete = async (id: string) => { setDeletingId(id) try { await draftService.deleteDraft(id) setDrafts(prev => prev.filter(d => d.id !== id && d.localId !== id)) showToast('Draft deleted', 'success') } catch { showToast('Failed to delete draft', 'error') } finally { setDeletingId(null) } } const formatDate = (dateStr: string) => { const date = new Date(dateStr) const now = new Date() const diffMs = now.getTime() - date.getTime() const diffMins = Math.floor(diffMs / 60000) const diffHours = Math.floor(diffMs / 3600000) const diffDays = Math.floor(diffMs / 86400000) if (diffMins < 1) return 'Just now' if (diffMins < 60) return `${diffMins}m ago` if (diffHours < 24) return `${diffHours}h ago` if (diffDays < 7) return `${diffDays}d ago` return date.toLocaleDateString('en-US', { month: 'short', day: 'numeric' }) } return (
{/* Header */}

Drafts ({drafts.length})

{/* Drafts List */}
{loading ? (
) : drafts.length === 0 ? (

No drafts saved yet

Drafts are saved automatically while composing

) : (
    {drafts.map((draft) => (
  • ))}
)}
{/* Footer */}
) }