import type { ComponentPropsWithoutRef, MouseEventHandler } from "react";
import type { PressEvent } from "@react-types/shared";

export function convertButtonProps<
  Props extends {
    isDisabled?: boolean;
    onPress?: (e: PressEvent) => void;
    onFocusChange?: (e: boolean) => void;
  },
>(props: Props) {
  const {
    onPress: onClick,
    isDisabled: disabled,
    onFocusChange: _,
    ...rest
  } = props;

  const renamedProps: ComponentPropsWithoutRef<"button"> = rest;
  if (onClick !== undefined) {
    renamedProps.onClick =
      onClick as unknown as MouseEventHandler<HTMLButtonElement>;
  }
  if (disabled !== undefined) {
    renamedProps.disabled = disabled;
  }

  return renamedProps;
}
