import { Dialog, DialogTrigger, DialogClose, DialogDescription, DialogContent, DialogTitle, DialogHeader, DialogFooter } from "@/components/ui/dialog"
import Link from "next/link"
import { Trash2, Search } from "lucide-react"
import { Button } from "@/components/ui/button"

export function actions({ pathname, deleteFn }: { pathname: string, deleteFn: (id: number) => void }) {
  return {
    id: "actions",
    // header: "Actions",
    cell: ({ row }) => {
      return <div className="flex items-center justify-around">
        <Link href={`${pathname}/${row.original.id}`}><Search /></Link>
        <Dialog>
          <DialogTrigger asChild>
            <Button variant="ghost"><Trash2 color="red" /></Button>
          </DialogTrigger>
          <DialogContent>
            <DialogHeader>
              <DialogTitle>Are you sure?</DialogTitle>
              <DialogDescription>
                Deleting a {pathname.slice(1)} cannot be undone!
              </DialogDescription>
            </DialogHeader>
            <DialogFooter>
              <DialogClose asChild>
                <Button variant="destructive"
                  onClick={() => {
                    deleteFn(row.original.id)
                  }}>Yes, delete it!
                </Button>
              </DialogClose>
            </DialogFooter>
          </DialogContent>
        </Dialog>
      </div>
    }
  }
}

