'use client' import { useState } from 'react' import { Sheet, SheetContent, SheetHeader, SheetTitle } from '@/components/ui/sheet' import { Button } from '@/components/ui/button' import { Input } from '@/components/ui/input' import { useConfigHistory, usePinSnapshot, useRestoreConfig } from '@/hooks/use-channels' import { cn } from '@/lib/utils' interface Props { channelId: string open: boolean onOpenChange: (open: boolean) => void } export function ConfigHistorySheet({ channelId, open, onOpenChange }: Props) { const { data: snapshots } = useConfigHistory(channelId) const pin = usePinSnapshot() const restore = useRestoreConfig() const [pinningId, setPinningId] = useState(null) const [pinLabel, setPinLabel] = useState('') return ( Config history
{(snapshots ?? []).map((snap, i) => (
v{snap.version_num} —{' '} {new Date(snap.created_at).toLocaleString()} {i === 0 && ( current )}
{snap.label ? (
📌 {snap.label}
) : (
Auto-saved
)}
{i === 0 && ( pinningId === snap.id ? (
setPinLabel(e.target.value)} className="h-7 text-xs w-32" placeholder="label…" onKeyDown={e => { if (e.key === 'Enter') { pin.mutate({ channelId, snapId: snap.id, label: pinLabel }) setPinningId(null) } if (e.key === 'Escape') setPinningId(null) }} />
) : ( ) )} {i > 0 && ( )}
))} {(snapshots ?? []).length === 0 && (

No history yet. History is created automatically when you save changes.

)}
) }