import type { ButtonHTMLAttributes, ReactNode } from 'react';
import './button.css';

type Variant = 'primary' | 'secondary' | 'ai' | 'ghost' | 'danger';
type Size = 'sm' | 'md' | 'lg';

interface ButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
  variant?: Variant;
  /** Nifty 3단 크기 — sm(32) · md(40, 기본) · lg(48). */
  size?: Size;
  leadingIcon?: ReactNode;
  /** 정사각 아이콘 전용 버튼(aria-label 필수). */
  iconOnly?: boolean;
  block?: boolean;
}

/** design.md §1-4 / DESIGN_SYSTEM_NIFTY §2.1 — 주요 버튼(primary blue), AI 액션(ai-accent 보라). radius 4px. */
export function Button({
  variant = 'primary',
  size = 'md',
  leadingIcon,
  iconOnly,
  block,
  className = '',
  children,
  ...rest
}: ButtonProps) {
  const classes = [
    'kx-btn',
    `kx-btn--${variant}`,
    size !== 'md' && `kx-btn--${size}`,
    iconOnly && 'kx-btn--icon',
    block && 'kx-btn--block',
    className,
  ]
    .filter(Boolean)
    .join(' ');
  return (
    <button className={classes} {...rest}>
      {leadingIcon && <span className="kx-btn__icon" aria-hidden="true">{leadingIcon}</span>}
      {children}
    </button>
  );
}
