import { useQuery } from '@tanstack/react-query' import { AlertTriangle } from 'lucide-react' import { useTranslation } from 'react-i18next' import { Button } from '@/shared/ui/button' import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from '@/shared/ui/dialog' import { cn } from '@/shared/lib/cn' import { getApplyDiff } from '../api' import { formatChannelTime } from '../lib/format' /** * Диф перед применением (см. 6.6). Изменения в ближайшие сутки подсвечены отдельно — это самая * частая причина случайного ущерба: у зрителя из-под носа уезжает то, что он уже видит в программе. */ export function ApplyDialog({ channelId, utcOffsetMinutes, pending, onApply, onClose, }: { channelId: string utcOffsetMinutes: number pending: boolean onApply: () => void onClose: () => void }) { const { t } = useTranslation() const { data, isFetching } = useQuery({ queryKey: ['admin', 'channels', channelId, 'diff'], queryFn: () => getApplyDiff(channelId), staleTime: 0, gcTime: 0, }) return ( !open && onClose()}> {t('admin.channels.apply')} {isFetching || !data ? t('common.loading') : t('admin.channels.diffSummary', { total: data.total, changed: data.changed })} {data && (
{data.changedSoon > 0 && (

{t('admin.channels.diffSoon', { count: data.changedSoon })}

)} {data.changes.length === 0 ? (

{t('admin.channels.diffNoChanges')}

) : (
    {data.changes.map((change, index) => (
  • {formatChannelTime(change.startsAtUtc, utcOffsetMinutes)} {change.before ?? '—'} {change.after ?? '—'}
  • ))}
)} {data.changed > data.changes.length && (

{t('admin.channels.andMore', { count: data.changed - data.changes.length })}

)}
)}
) }