import { Button as ButtonRAC } from "react-aria-components"

import { MaterialIcon } from "../Icons/MaterialIcon"
import { IconButtonProps } from "./types"
import { variants } from "./variants"

export function IconButton({
  variant,
  emphasis,
  size,
  iconName,
  className,
  ...props
}: IconButtonProps) {
  const classNames = variants({
    variant,
    emphasis,
    size,
    className,
  })

  return (
    <ButtonRAC {...props} className={classNames}>
      <MaterialIcon
        icon={iconName}
        size={getIconSize(size)}
        color="CurrentColor"
      />
    </ButtonRAC>
  )
}

function getIconSize(size: IconButtonProps["size"]) {
  switch (size) {
    case "sm":
      return 16
    case "md":
      return 20
    case "xl":
      return 28
    case "lg":
    default:
      return 24
  }
}
