"use client";
import React from "react";
import {Button} from "./ui/button";
import {RefreshCcw, Trash} from "lucide-react";
import privateApi from "@/service/http/privateCall.axios";
import {usePathname, useRouter} from "next/navigation";
import {
  Dialog,
  DialogClose,
  DialogContent,
  DialogDescription,
  DialogFooter,
  DialogHeader,
  DialogTitle,
  DialogTrigger,
} from "./ui/dialog";

async function restoreUser(id: number | string,route:string) {
  try {
    const data = await privateApi.put(`/${route}/restore/${id}`);
  } catch (error) {
    console.log(error);
  }
}
export default function RestoreUserButton({id,route}: {id: number | string,route:string}) {
  const router = useRouter();
  const pathname = usePathname();
  const handleDelete = async () => {
    await restoreUser(id,route);
    window.location.pathname = pathname;
  };
  return (
    <>
      <Dialog>
        <DialogTrigger asChild>
          <Button variant="secondary">
            <RefreshCcw />
          </Button>
        </DialogTrigger>
        <DialogContent className="sm:max-w-[425px]" dir="rtl">
          <DialogHeader>
            <DialogTitle>بازگردانی آیتم</DialogTitle>
            <DialogDescription>
              آیا از بازگردانی این آیتم اطمینان دارد ؟
            </DialogDescription>
          </DialogHeader>

          <DialogFooter>
            <DialogClose asChild>
              <Button variant="outline">انصراف</Button>
            </DialogClose>
            <Button onClick={handleDelete} type="submit">
              بله
            </Button>
          </DialogFooter>
        </DialogContent>
      </Dialog>
    </>
  );
}
