"use client";
import Link from "next/link";
import { Button, buttonVariants } from "../ui/button";
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuTrigger,
} from "../ui/dropdown-menu";
import {
AlertDialog,
AlertDialogAction,
AlertDialogCancel,
AlertDialogContent,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogTitle,
AlertDialogTrigger,
} from "../ui/alert-dialog";
import { Input } from "../ui/input";
import {
banUser,
sendAlert,
suspendUser,
unsuspendUser,
updateBotDiscoverability,
updateUserBadges,
} from "@/lib/actions";
import { useRef, useState } from "react";
import { useToast } from "../ui/use-toast";
import { Bot, User } from "revolt-api";
import { Card, CardHeader } from "../ui/card";
import { cn } from "@/lib/utils";
import { decodeTime } from "ulid";
const badges = [1, 2, 4, 8, 16, 32, 128, 0, 256, 512, 1024];
export function UserActions({ user, bot }: { user: User; bot?: Bot }) {
const alertMessage = useRef("");
const { toast } = useToast();
const [userDraft, setUserDraft] = useState(user);
const [botDraft, setBotDraft] = useState(bot);
const userInaccessible = userDraft.flags === 4 || userDraft.flags === 2;
return (
<>
{
if (sysBadge) return;
try {
const badges =
(decodeTime(user._id) < 1629638578431 ? 256 : 0) |
((userDraft.badges ?? 0) ^ badge);
await updateUserBadges(user._id, badges);
setUserDraft((user) => ({ ...user!, badges }));
toast({
title: "Updated user badges",
});
} catch (err) {
toast({
title: "Failed to update user badges",
description: String(err),
variant: "destructive",
});
}
}}
/>
);
})}