import type { ComponentProps, ReactNode } from 'react';
import { Button } from '@/components/ui/button';
import { cn } from '@/lib/utils';

type Tone = 'primary' | 'accent' | 'destructive' | 'muted';

const base =
    'bg-transparent text-muted-foreground hover:bg-accent hover:text-foreground';

const tones: Record<Tone, string> = {
    primary: base,
    accent: base,
    muted: base,
    destructive:
        'bg-transparent text-muted-foreground hover:bg-red-50 hover:text-destructive dark:hover:bg-red-500/10',
};

type Props = ComponentProps<typeof Button> & {
    label: string;
    tone?: Tone;
    icon: ReactNode;
};

export function DataTableActionButton({
    label,
    tone = 'muted',
    icon,
    className,
    ...props
}: Props) {
    return (
        <Button
            type="button"
            variant="ghost"
            size="icon"
            title={label}
            aria-label={label}
            className={cn('size-10 shrink-0 md:size-8', tones[tone], className)}
            {...props}
        >
            {icon}
        </Button>
    );
}
