import { useState } from 'react' import { RefreshCw, CheckCircle2, XCircle, Clock, Globe, AlertTriangle } from 'lucide-react' import { MOCK_CHANNELS } from '../data/mockData' import type { Channel, SyncStatus } from '../types' import { cn } from '../lib/utils' import { Badge } from '../components/ui/Badge' const CHANNEL_ICONS: Record = { booking_com: 'πŸ”΅', airbnb: 'πŸ”΄', expedia: '🟑', vrbo: '🟒', yandex_travel: 'πŸ”΄', ostrovok: '🟣', sutochno: '🟠', onetwotrip: 'πŸ”΅', } const RUSSIAN_CHANNELS = new Set(['yandex_travel', 'ostrovok', 'sutochno', 'onetwotrip']) function SyncStatusBadge({ status }: { status: SyncStatus }) { const map: Record = { idle: { icon: Clock, label: 'НС настроСн', cls: 'bg-slate-100 text-slate-600 dark:bg-slate-700 dark:text-slate-300' }, syncing: { icon: RefreshCw, label: 'Бинхронизация', cls: 'bg-blue-100 text-blue-700 dark:bg-blue-900/30 dark:text-blue-300' }, success: { icon: CheckCircle2, label: 'Π‘ΠΈΠ½Ρ…Ρ€ΠΎΠ½ΠΈΠ·ΠΈΡ€ΠΎΠ²Π°Π½', cls: 'bg-emerald-100 text-emerald-700 dark:bg-emerald-900/30 dark:text-emerald-300' }, error: { icon: XCircle, label: 'Ошибка', cls: 'bg-red-100 text-red-700 dark:bg-red-900/30 dark:text-red-300' }, } const { icon: Icon, label, cls } = map[status] return ( {label} ) } export function ChannelsPage() { const [channels, setChannels] = useState(MOCK_CHANNELS) const triggerSync = (id: string) => { setChannels(prev => prev.map(c => c.id === id ? { ...c, lastSyncStatus: 'syncing' } : c, )) setTimeout(() => { setChannels(prev => prev.map(c => c.id === id ? { ...c, lastSyncStatus: 'success', lastSyncAt: new Date().toISOString(), bookingsImported: c.bookingsImported + Math.floor(Math.random() * 3) } : c, )) }, 2000) } const toggleChannel = (id: string) => { setChannels(prev => prev.map(c => c.id === id ? { ...c, isEnabled: !c.isEnabled } : c, )) } const totalImported = channels.reduce((s, c) => s + c.bookingsImported, 0) const activeCount = channels.filter(c => c.isEnabled).length const internationalChannels = channels.filter(c => !RUSSIAN_CHANNELS.has(c.name)) const russianChannels = channels.filter(c => RUSSIAN_CHANNELS.has(c.name)) return (
{/* Header */}

ΠœΠ΅Π½Π΅Π΄ΠΆΠ΅Ρ€ ΠΊΠ°Π½Π°Π»ΠΎΠ²

Бинхронизация с OTA ΠΏΠ»ΠΎΡ‰Π°Π΄ΠΊΠ°ΠΌΠΈ

{/* Stats */}
{[ { label: 'Активных ΠΊΠ°Π½Π°Π»ΠΎΠ²', value: activeCount, icon: Globe }, { label: 'ВсСго ΠΊΠ°Π½Π°Π»ΠΎΠ²', value: channels.length, icon: Globe }, { label: 'Π˜ΠΌΠΏΠΎΡ€Ρ‚ΠΈΡ€ΠΎΠ²Π°Π½ΠΎ Π±Ρ€ΠΎΠ½Π΅ΠΉ', value: totalImported, icon: CheckCircle2 }, { label: 'ПослСдняя синхронизация', value: 'БСгодня', icon: RefreshCw }, ].map(s => (

{s.value}

{s.label}

))}
{/* International Channels */}

🌍 ΠœΠ΅ΠΆΠ΄ΡƒΠ½Π°Ρ€ΠΎΠ΄Π½Ρ‹Π΅ ΠΏΠ»ΠΎΡ‰Π°Π΄ΠΊΠΈ

{internationalChannels.map(channel => ( triggerSync(channel.id)} onToggle={() => toggleChannel(channel.id)} /> ))}
{/* Russian Channels */}

πŸ‡·πŸ‡Ί РоссийскиС ΠΏΠ»ΠΎΡ‰Π°Π΄ΠΊΠΈ

{russianChannels.map(channel => ( triggerSync(channel.id)} onToggle={() => toggleChannel(channel.id)} /> ))}
{/* Info */}

Π”Π΅ΠΌΠΎ-Ρ€Π΅ΠΆΠΈΠΌ

Π’ Π΄Π΅ΠΌΠΎ-Ρ€Π΅ΠΆΠΈΠΌΠ΅ синхронизация имитируСтся. Π’ ΠΏΡ€ΠΎΠ΄Π°ΠΊΡˆΠ½-вСрсии ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅Ρ‚ΡΡ webhook-интСграция с Ρ€Π΅Π°Π»ΡŒΠ½Ρ‹ΠΌΠΈ API ΠΊΠ°Π½Π°Π»ΠΎΠ² Ρ‡Π΅Ρ€Π΅Π· ΠΌΠ΅Π½Π΅Π΄ΠΆΠ΅Ρ€ ΠΊΠ°Π½Π°Π»ΠΎΠ² (Staah, SiteMinder, HotelRunner ΠΈ Π΄Ρ€.)

) } function ChannelCard({ channel, onSync, onToggle }: { channel: Channel onSync: () => void onToggle: () => void }) { const isSyncing = channel.lastSyncStatus === 'syncing' return (
{CHANNEL_ICONS[channel.name]}

{channel.displayName}

{/* Toggle */}
{channel.isEnabled && (

Π˜ΠΌΠΏΠΎΡ€Ρ‚ΠΈΡ€ΠΎΠ²Π°Π½ΠΎ Π±Ρ€ΠΎΠ½Π΅ΠΉ

{channel.bookingsImported}

ПослСдняя синхронизация

{channel.lastSyncAt ? new Intl.DateTimeFormat('ru-RU', { hour: '2-digit', minute: '2-digit' }).format(new Date(channel.lastSyncAt)) : 'β€”' }

{channel.mappings.length > 0 && (

Маппинг Π½ΠΎΠΌΠ΅Ρ€ΠΎΠ² ({channel.mappings.length})

{channel.mappings.slice(0, 2).map(m => (
β„–{ m.localRoomId.replace('r', '') } β†’ {m.channelRoomName}
))} {channel.mappings.length > 2 && (

+{channel.mappings.length - 2} Π΅Ρ‰Ρ‘

)}
)}
)} {!channel.isEnabled && (

Канал ΠΎΡ‚ΠΊΠ»ΡŽΡ‡Ρ‘Π½. Π’ΠΊΠ»ΡŽΡ‡ΠΈΡ‚Π΅ для настройки ΠΈΠ½Ρ‚Π΅Π³Ρ€Π°Ρ†ΠΈΠΈ.

)}
) }