"use client" import { AlertTriangle, CheckCircle2, Clock, MessageSquare, RefreshCw, Star, XCircle, } from "lucide-react" import Link from "next/link" import { useEffect } 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 sessions = useChatStore((state) => state.sessions) 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 = chatSessionId ?? sessions.find((session) => session.type === "order" && session.orderId === orderId)?.id const status = order?.status ?? initialStatus useEffect(() => { if (chatSessionId || !order || resolvedChatSessionId) return ensureOrderSession(order) }, [chatSessionId, order, ensureOrderSession, resolvedChatSessionId]) 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 (