"use client" import { AlertTriangle, CheckCircle2, Clock, MessageSquare, RefreshCw, Star, XCircle, } from "lucide-react" import Link from "next/link" import { useEffect, useState } from "react" import { Button } from "@/components/ui/button" import { notifySuccess } from "@/lib/toast" import type { OrderStatus } from "@/lib/types" import { useChatStore } from "@/store/chat" import { useOrderStore } from "@/store/orders" import { useShopStore } from "@/store/shops" interface OrderActionsProps { orderId: string initialStatus: OrderStatus chatSessionId?: string serviceId: string } function showFeedback(message: string) { notifySuccess(message) } export default function OrderActions({ orderId, initialStatus, chatSessionId, serviceId, }: OrderActionsProps) { const order = useOrderStore((state) => state.orders.find((item) => item.id === orderId)) const updateOrderStatus = useOrderStore((state) => state.updateOrderStatus) const ensureOrderSession = useChatStore((state) => state.ensureOrderSession) const dispatchMode = useShopStore((state) => { if (!order?.shopId) return "manual" const shop = state.shops.find((item) => item.id === order.shopId) return shop?.dispatchMode ?? "manual" }) const [resolvedChatSessionId, setResolvedChatSessionId] = useState(chatSessionId) const status = order?.status ?? initialStatus useEffect(() => { if (chatSessionId) { setResolvedChatSessionId(chatSessionId) return } if (!order) return const session = ensureOrderSession(order) setResolvedChatSessionId(session.id) }, [chatSessionId, order, ensureOrderSession]) useEffect(() => { if (!order) return if (order.status !== "pending_accept") return if (!order.shopId) return if (dispatchMode !== "auto") return const timer = setTimeout(() => { updateOrderStatus(orderId, "in_progress") showFeedback("系统已自动派单") }, 3000) return () => clearTimeout(timer) }, [dispatchMode, order, orderId, updateOrderStatus]) return (