import { ActionsMenu } from '@/components/ActionsMenu';
import { CloneButton, EditButton } from 'react-admin';
import { DeleteWithConfirmButton } from '@/components/ra-buttons';

function ActionsField({ canEdit = true, canDelete = true, canClone = false }: ActionsFieldProps): JSX.Element | null {
  if (!canEdit && !canDelete && !canClone) {
    return null;
  }

  return (
    <ActionsMenu>
      {canEdit ? <EditButton /> : null}
      {canDelete ? <DeleteWithConfirmButton /> : null}
      {canClone ? <CloneButton /> : null}
    </ActionsMenu>
  );
}

type ActionsFieldProps = {
  canEdit?: boolean;
  canDelete?: boolean;
  canClone?: boolean;
};

export { ActionsField };
export type { ActionsFieldProps };
