"use client";

import { Eye, Pencil, Trash2 } from "lucide-react";

import { usePermissions } from "@/components/admins/rbac/hooks/use-permissions";
import { TableRowActions } from "@/components/shared/table-row-actions";

type RbacRowActionsProps = {
  editHref: string;
  viewLabel: string;
  editLabel: string;
  deleteLabel: string;
  onView: () => void;
  onDelete: () => void;
  viewDisabled?: boolean;
};

export function RbacRowActions({
  editHref,
  viewLabel,
  editLabel,
  deleteLabel,
  onView,
  onDelete,
  viewDisabled,
}: RbacRowActionsProps) {
  const { can } = usePermissions();
  const canManage = can("rbac.manage");

  return (
    <TableRowActions
      iconActions={[
        {
          label: viewLabel,
          icon: Eye,
          variant: "outline",
          onClick: onView,
          disabled: viewDisabled,
        },
        ...(canManage
          ? [
              {
                label: deleteLabel,
                icon: Trash2,
                variant: "destructive" as const,
                onClick: onDelete,
              },
            ]
          : []),
      ]}
      linkActions={
        canManage
          ? [{ label: editLabel, icon: Pencil, variant: "secondary", href: editHref }]
          : []
      }
    />
  );
}
