"use client" import { AlertTriangle, CheckCircle2, Clock, MessageSquare, RefreshCw, Star, XCircle, } from "lucide-react" import Link from "next/link" import { useCallback } from "react" import { Button } from "@/components/ui/button" import { acceptOrder, cancelPreAccept, confirmClose, payOrder, requestClose, } from "@/lib/api/orders" import { notifyInfo, notifySuccess } from "@/lib/toast" import type { OrderStatus } from "@/lib/types" import { useAuthStore } from "@/store/auth" 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 currentUserId = useAuthStore((state) => state.user?.id) const order = useOrderStore((state) => state.orders.find((item) => item.id === orderId)) const sessions = useChatStore((state) => state.sessions) 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 const isConsumer = order?.consumerId === currentUserId const isPlayer = order?.playerId === currentUserId const handleDecision = useCallback( (okMessage: string, result: { decision: { ok: boolean; message?: string } }) => { if (result.decision.ok) { showFeedback(okMessage) return } notifyInfo(result.decision.message ?? "当前操作不允许") }, [], ) return (
{status === "pending_payment" && isConsumer && ( <> )} {status === "pending_accept" && ( <> {isConsumer && ( )} {isPlayer && (order?.shopId && dispatchMode === "auto" ? ( ) : ( ))} )} {(status === "in_progress" || status === "pending_close") && resolvedChatSessionId && ( )} {status === "in_progress" && ( <> )} {status === "pending_close" && ( <> {isConsumer && ( )} )} {status === "pending_review" && ( )} {status === "completed" && ( )} {status === "cancelled" && ( )} {status === "disputed" && ( )}
) }