Spaces:
Running

File size: 6,383 Bytes
526e04d
 
 
f0e1c07
cb3f8d3
ae7f86f
526e04d
 
 
 
 
 
 
 
 
 
 
3612601
526e04d
f0e1c07
526e04d
 
 
 
 
 
 
 
 
 
 
 
 
f0e1c07
526e04d
cb3f8d3
 
 
 
 
8e132dd
 
526e04d
cb528a9
1ba9153
cb528a9
1ba9153
 
2dd979f
2e7cd01
 
 
 
cb528a9
2e7cd01
 
 
 
1ba9153
61fe938
526e04d
 
61fe938
526e04d
 
 
 
 
ad6161c
2dd979f
526e04d
 
ad6161c
2dd979f
526e04d
57a0bd5
 
 
e6d0a09
57a0bd5
2dd979f
526e04d
 
 
 
 
 
 
ad6161c
526e04d
 
2dd979f
526e04d
 
 
 
 
 
3425727
 
 
 
 
4c9faf8
3425727
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ae7f86f
3425727
 
 
 
 
526e04d
2dd979f
526e04d
 
2dd979f
 
782696b
2dd979f
782696b
526e04d
1ba9153
526e04d
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
'use client'

import { cn } from '@/lib/utils'
import { ArrowLeft, Bot, Brain, Calendar, Info, Loader2, MoreVertical, Sparkles, GraduationCap } from 'lucide-react'
import { useState, useEffect } from '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) {
    const [mounted, setMounted] = useState(false)

    useEffect(() => {
        setMounted(true)
    }, [])
    if (!mounted) return null

    return (
        <div className="h-[52px] md:h-16 shrink-0 flex items-center justify-between px-3 md:px-6 relative z-[50] bg-[#050510]/60 backdrop-blur-xl border-b border-white/5">
            {/* 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-30 blur-xl" />

            {/* Left: Lead Info */}
            <div className="flex items-center gap-2 md:gap-3 overflow-hidden">
                {/* Back Button (Phone only - strictly hidden on md+) */}
                <div className="md:hidden">
                    <button
                        onClick={onBack}
                        className="p-1.5 -ml-1 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-2 md:gap-3">
                    <div className="w-7 h-7 md:w-10 md: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-[10px] md:text-sm border border-indigo-500/20 shadow-sm shrink-0">
                        {lead?.name?.charAt(0) || 'L'}
                    </div>
                    <div className="min-w-0">
                        <h2 className="font-bold text-white text-[13px] md:text-sm truncate max-w-[100px] sm:max-w-none leading-none mb-0.5">{lead?.name || 'Лид'}</h2>
                        <div className="flex items-center gap-2">
                            {(lead as any)?.channel_source && (
                                <span className="text-[10px] text-slate-500 font-medium">{(lead as any)?.channel_source}</span>
                            )}
                            {lead?.needs_attention && (
                                <span className="flex items-center gap-1 text-[9px] text-red-400 bg-red-500/10 px-1.5 py-0 rounded-full border border-red-500/20 font-semibold leading-tight animate-pulse">
                                    Внимание
                                </span>
                            )}
                        </div>
                    </div>
                </div>
            </div>

            <div className="flex items-center gap-1.5 md:gap-3">
                <button
                    onClick={onOpenBookingModal}
                    className="hidden sm:flex items-center gap-2 px-2 md:px-3 py-1.5 rounded-lg text-[11px] 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>

                {/* AI Toggle Switch - Clean Design */}
                <button
                    onClick={onToggleAI}
                    disabled={isTogglingAI}
                    className={cn(
                        "relative w-12 min-w-[48px] h-6 flex-shrink-0 rounded-full transition-all duration-300 border",
                        isAIActive
                            ? "bg-indigo-500 border-indigo-400 shadow-[0_2px_8px_rgba(99,102,241,0.3)]"
                            : "bg-white/10 border-white/10 hover:bg-white/20",
                        isTogglingAI && "opacity-80"
                    )}
                    title={isAIActive ? 'AI Активен' : 'AI Отключен'}
                >
                    {/* Thumb */}
                    <motion.div
                        animate={{
                            x: isAIActive ? 26 : 2,
                            scale: isTogglingAI ? 0.8 : 1,
                        }}
                        transition={{ type: "spring", stiffness: 500, damping: 30 }}
                        className="absolute top-[2px] w-[18px] h-[18px] rounded-full bg-white shadow-sm flex items-center justify-center z-10"
                    >
                        {isTogglingAI && (
                            <Loader2 className="w-3 h-3 animate-spin text-indigo-500" />
                        )}
                    </motion.div>
                </button>

                {/* AI Summary Button */}
                <button
                    onClick={onOpenMobileDrawer}
                    className="flex lg:hidden p-1.5 text-slate-400 hover:text-indigo-400 hover:bg-white/5 rounded-lg transition-all active:scale-95"
                    title="AI-анализ"
                >
                    <Brain className="w-[18px] h-[18px]" />
                </button>
            </div>
        </div >
    )
}