"use client" import { Button } from "@/components/ui/button" import { Sword, Search, Loader2 } from "lucide-react" import { Input } from "@/components/ui/input" import { useState } from "react" import { useToast } from "@/components/ui/use-toast" import { ROLES } from "@/lib/permissions" export function PromotePanel() { const [email, setEmail] = useState("") const [loading, setLoading] = useState(false) const { toast } = useToast() const handlePromote = async () => { if (!email) return setLoading(true) try { const res = await fetch(`/api/roles/users?email=${encodeURIComponent(email)}`) const data = await res.json() as { user?: { id: string; name?: string; email: string }; error?: string } if (!res.ok) throw new Error(data.error || '未知错误') if (!data.user) { toast({ title: "未找到用户", description: "请确认邮箱地址是否正确", variant: "destructive" }) return } const promoteRes = await fetch('/api/roles/promote', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ userId: data.user.id, roleName: ROLES.KNIGHT }) }) if (!promoteRes.ok) throw new Error('册封失败') toast({ title: "册封成功", description: `已将 ${data.user.email} 册封为骑士` }) setEmail("") } catch (error) { toast({ title: "册封失败", description: error instanceof Error ? error.message : "请稍后重试", variant: "destructive" }) } finally { setLoading(false) } } return (