"use client"

import { cn } from "@/lib/utils"

export type IconButtonProps = Omit<
  React.ComponentProps<"button">,
  "children"
> & {
  label: string
  children: React.ReactNode
}

/** Compact icon action with an accessible label (title + sr-only). */
export function IconButton({
  children,
  label,
  className,
  type = "button",
  ...rest
}: IconButtonProps) {
  return (
    <button
      type={type}
      title={label}
      aria-label={label}
      data-slot="icon-button"
      className={cn(
        "hover:bg-accent hover:text-accent-foreground inline-flex size-6 items-center justify-center rounded-md p-1 outline-none transition-colors focus-visible:ring-1 focus-visible:ring-ring/50 active:scale-90 disabled:pointer-events-none disabled:opacity-50 [&_svg]:size-4",
        className
      )}
      {...rest}
    >
      {children}
      <span className="sr-only">{label}</span>
    </button>
  )
}