Spaces:
Sleeping

axeronis
fix: strictly hide back/toggle button on tablets in chat header
61fe938
Raw History Blame
7.76 kB
'use client'
import { cn } from '@/lib/utils'
import { ArrowLeft, Bot, Brain, Calendar, Info, Loader2, MoreVertical, Sparkles, GraduationCap } from 'lucide-react'
import { motion } from 'framer-motion'
import type { Lead } from '@/types'
interface ChatHeaderProps {
lead?: Lead
isAnalyzing?: boolean
isAIActive: boolean
isTogglingAI: boolean
isLeadsListOpen?: boolean
onToggleLeadsList?: () => void
onBack?: () => void
onToggleAI: () => void
onOpenMobileDrawer?: () => void
onOpenBookingModal: () => void
onTrainAI?: () => void
}
export function ChatHeader({
lead,
isAnalyzing,
isAIActive,
isTogglingAI,
isLeadsListOpen,
onToggleLeadsList,
onBack,
onToggleAI,
onOpenMobileDrawer,
onOpenBookingModal,
onTrainAI,
}: ChatHeaderProps) {
return (
<div className="h-16 shrink-0 flex items-center justify-between px-4 md:px-6 relative z-20 border-b border-white/5 bg-[#0D0E18]/50 backdrop-blur-xl backdrop-saturate-[1.8]">
{/* Aurora Background Atmosphere - Synced */}
<div className="absolute inset-0 pointer-events-none overflow-hidden -z-10 bg-gradient-to-r from-indigo-500/5 to-purple-500/5 opacity-50" />
{/* Left: Lead Info */}
<div className="flex items-center gap-3 overflow-hidden">
{/* Back Button (Phone only - strictly hidden on md+) */}
<div className="md:hidden">
<button
onClick={onBack}
className="p-2 -ml-2 text-slate-400 hover:text-white hover:bg-white/10 rounded-full transition-colors"
>
<ArrowLeft className="w-5 h-5" />
</button>
</div>
{/* Tablet/Desktop Toggle - only visible on Desktop (lg+) */}
<button
onClick={onToggleLeadsList}
className="hidden lg:flex p-2 -ml-2 text-slate-400 hover:text-indigo-400 hover:bg-white/5 rounded-lg transition-all"
title={isLeadsListOpen ? "Скрыть список" : "Показать список"}
>
{isLeadsListOpen ? <ArrowLeft className="w-5 h-5" /> : <MoreVertical className="w-5 h-5 rotate-90" />}
</button>
<div className="flex items-center gap-3">
<div className="w-10 h-10 rounded-full bg-gradient-to-br from-indigo-600/30 to-purple-600/30 flex items-center justify-center text-indigo-400 font-bold text-sm border border-indigo-500/30 relative shadow-sm">
{lead?.name?.charAt(0) || 'L'}
<div className={cn(
"absolute bottom-0 right-0 w-3 h-3 rounded-full border-2 border-white",
lead?.heat_level === 'HOT' ? "bg-red-500" :
lead?.heat_level === 'WARM' ? "bg-amber-500" :
"bg-blue-500"
)} />
</div>
<div>
<h2 className="font-bold text-white text-sm">{lead?.name || 'Лид'}</h2>
<div className="flex items-center gap-2">
<span className="text-xs text-slate-400 font-medium">{(lead as any)?.channel_source || 'Неизвестно'}</span>
{lead?.needs_attention && (
<span className="flex items-center gap-1 text-[10px] text-red-400 bg-red-500/20 px-2 py-0.5 rounded-full animate-pulse border border-red-500/30 font-semibold">
🚨 Внимание
</span>
)}
{isAnalyzing && (
<span className="flex items-center gap-1 text-[10px] text-indigo-600 bg-indigo-50 px-2 py-0.5 rounded-full animate-pulse border border-indigo-100 font-semibold">
<Sparkles className="w-3 h-3" />
AI думает...
</span>
)}
</div>
</div>
</div>
</div>
<div className="flex items-center gap-3">
<button
onClick={onOpenBookingModal}
className="hidden md:flex items-center gap-2 px-3 py-1.5 rounded-lg text-xs font-semibold bg-white/5 text-slate-300 border border-white/10 hover:bg-white/10 transition-all"
title="Записать на встречу"
>
<Calendar className="w-3.5 h-3.5 text-slate-500" />
Записать
</button>
{/* Train AI Button */}
{onTrainAI && (
<button
onClick={onTrainAI}
className="hidden md:flex items-center gap-2 px-3 py-1.5 rounded-lg text-xs font-semibold bg-purple-500/10 text-purple-400 border border-purple-500/20 hover:bg-purple-500/20 transition-all"
title="Обучить AI на этом диалоге"
>
<GraduationCap className="w-3.5 h-3.5" />
Обучить
</button>
)}
{/* AI Toggle Switch */}
<div className="flex items-center gap-2">
<Bot className={cn(
"w-4 h-4 transition-colors",
isAIActive ? "text-indigo-400" : "text-slate-500"
)} />
<button
onClick={onToggleAI}
disabled={isTogglingAI}
className={cn(
"relative w-12 h-6 rounded-full transition-all duration-300 flex-shrink-0",
isAIActive
? "bg-gradient-to-r from-indigo-500 to-purple-600"
: "bg-zinc-700",
isTogglingAI && "opacity-80"
)}
title={isAIActive ? 'AI Активен' : 'AI Отключен'}
>
<motion.div
animate={{
x: isAIActive ? 26 : 4,
scale: isTogglingAI ? 0.8 : 1
}}
transition={{ type: "spring", stiffness: 500, damping: 30 }}
className="absolute top-1 w-4 h-4 bg-white rounded-full shadow-lg flex items-center justify-center overflow-hidden"
>
{isTogglingAI && (
<Loader2 className="w-2.5 h-2.5 animate-spin text-indigo-500" />
)}
</motion.div>
</button>
</div>
{/* AI Summary Button - Visible on mobile/tablet to toggle intelligence panel/drawer. Hidden on lg where it's persistent. */}
<button
onClick={onOpenMobileDrawer}
className="flex lg:hidden p-2 text-slate-400 hover:text-indigo-400 hover:bg-white/5 rounded-lg transition-all"
title="Посмотреть AI-анализ"
>
<Brain className="w-5 h-5 transition-colors group-hover:text-indigo-400" />
</button>
</div>
</div >
)
}