import type { VariantProps } from 'class-variance-authority';
import { cva } from 'class-variance-authority';

export { default as Button } from './Button.vue';

export const buttonVariants = cva(
  'inline-flex items-center justify-center whitespace-nowrap border border-transparent transition-all relative disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none shrink-0 [&_svg]:shrink-0 outline-none focus-visible:border-border-surface-focus-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive',
  {
    variants: {
      variant: {
        default:
          'bg-background-button-primary-button text-content-on-button-primary-button hover-layer hover-layer-subtle',
        destructive:
          'bg-background-button-danger-button text-content-on-button-danger-button hover-layer hover-layer-default focus-visible:border-transparent focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40',
        outline:
          'border border-input bg-transparent text-foreground hover:bg-background-surface-muted-subtle',
        secondary:
          'bg-background-button-secondary-button text-content-on-button-secondary-button hover-layer hover-layer-default',
        ghost: 'text-foreground hover:bg-background-surface-muted-subtle',
        link: 'text-link overlay-link-hover-subtle',
      },
      size: {
        // Text sizes — render label with optional start/end icons.
        // Heights are pinned via `h-*` (spacing token = 4px × N) so buttons
        // line up with their icon-only counterparts (default↔icon, lg↔icon-lg).
        sm: 'rounded-sm gap-1 px-2 py-1 label-12-medium [&_svg]:size-3',
        default: 'h-9 rounded-md gap-2 px-4 py-2 body-14-medium [&_svg]:size-4',
        lg: 'h-10 rounded-md gap-2 px-6 py-2 body-14-medium [&_svg]:size-4',

        // Icon-only sizes — render a single icon (no label, no gap).
        // The outer square is pinned via `size-*` (spacing token = 4px × N);
        // the inner `[&_svg]:size-*` controls the icon itself.
        // `icon-xs` and `icon-sm-no-padding` are intended for the `ghost` variant only.
        'icon-sm-no-padding': 'size-4 rounded-sm p-0 [&_svg]:size-4',
        'icon-xs': 'size-6 rounded-sm p-0 [&_svg]:size-3',
        'icon-sm': 'size-6 rounded-sm p-0 [&_svg]:size-4',
        icon: 'size-9 rounded-sm p-0 [&_svg]:size-5',
        'icon-lg': 'size-10 rounded-md p-0 [&_svg]:size-6',
      },
    },
    defaultVariants: {
      variant: 'default',
      size: 'default',
    },
  },
);
export type ButtonVariants = VariantProps<typeof buttonVariants>;
