import { useState } from 'react' import { Link } from 'react-router-dom' import { Building2, Clock, ExternalLink, Mail, MapPin, Phone, Tags, Target, Zap, AlertTriangle, } from 'lucide-react' import { useMutation, useQueryClient } from '@tanstack/react-query' import { updateCustomer } from '@/services/api/customers' import { createTask } from '@/services/api/crm' import { analyzeConversation } from '@/services/api/ai' import { useAuthStore } from '@/app/store/auth' import type { Customer, Conversation } from '@/types' import { Avatar } from '@/components/ui/avatar' import { Button } from '@/components/ui/button' import { Badge } from '@/components/ui/badge' import { Select } from '@/components/ui/select' import { Card, CardHeader } from '@/components/ui/card' import { Switch } from '@/components/ui/switch' import { Spinner } from '@/components/ui/feedback' import { ChannelIcon } from '@/components/common/ChannelIcon' import { CountryFlag } from '@/components/common/CountryFlag' import { IntentScoreBadge, CustomerStageBadge, SentimentBadge, RiskLevelBadge } from '@/components/common/StatusBadges' import { CUSTOMER_STAGES, NEXT_ACTIONS, countryMeta, INTENT_LEVELS } from '@/config/constants' import { toast, errorMessage } from '@/app/store/toast' import { cn } from '@/utils/cn' import { CustomerProfileRadar } from '@/components/customer/CustomerProfileRadar' import { CustomerSemanticTag } from '@/components/customer/CustomerSemanticTag' export function InsightPanel({ customer, conversation, }: { customer: Customer conversation: Conversation }) { const queryClient = useQueryClient() const user = useAuthStore((state) => state.user) const [analyzing, setAnalyzing] = useState(false) const [analysis, setAnalysis] = useState(customer.aiProfile.summary) const c = countryMeta(customer.country) const localTime = new Date( new Date().getTime() + new Date().getTimezoneOffset() * 60000 + c.tzOffset * 3600000, ).toLocaleTimeString('zh-CN', { hour: '2-digit', minute: '2-digit' }) const updateMut = useMutation({ mutationFn: (data: Partial) => updateCustomer(customer.id, data), onSuccess: () => { queryClient.invalidateQueries({ queryKey: ['customers'] }) queryClient.invalidateQueries({ queryKey: ['conversations'] }) toast.success('客户信息已更新') }, onError: (e) => toast.error(errorMessage(e)), }) const taskMut = useMutation({ mutationFn: (title: string) => createTask({ title, type: 'revisit', priority: customer.riskLevel === 'urgent' || customer.riskLevel === 'high' ? 'high' : 'medium', status: 'pending', customerId: customer.id, customerName: customer.name, conversationId: conversation.id, ownerId: user?.id || '', dueAt: new Date(Date.now() + 24 * 60 * 60 * 1000).toISOString(), note: `由客户洞察建议创建:${title}`, }), onSuccess: () => { queryClient.invalidateQueries({ queryKey: ['tasks'] }) toast.success('已创建跟进任务', '默认明天到期') }, onError: (error) => toast.error(errorMessage(error)), }) const handleAnalyze = async () => { setAnalyzing(true) try { const result = await analyzeConversation(conversation.id) setAnalysis(result.summary) toast.success('会话分析完成', `意向评分 ${result.intentScore} · ${INTENT_LEVELS.find(l => l.value === result.intentLevel)?.label}`) } catch { toast.error('分析失败,请稍后重试') } finally { setAnalyzing(false) } } return (
{/* 客户基本信息 */}

{customer.name}

{customer.telegramUsername && (

@{customer.telegramUsername}

)} {customer.company && (

{customer.company}

)}
当地时间:{localTime}
{customer.email && (
{customer.email}
)} {customer.phone && (
{customer.phone}
)}
{customer.channel} · {customer.sourcePath ?? '—'}
{customer.products?.map((p) => ( {p} ))} {customer.tags?.map((t) => ( ))}
意向评分
成交阶段