import { clsx } from 'clsx';
import { ButtonHTMLAttributes, forwardRef } from 'react';

import { Priority, PriorityPrimary, PrioritySecondary, PriorityTertiary } from '../common';

export type ActionButtonProps = {
  priority?: PriorityPrimary | PrioritySecondary | PriorityTertiary;
  /**
   * @deprecated use `children` instead
   */
  text?: string;
} & ButtonHTMLAttributes<HTMLButtonElement>;

const ActionButton = forwardRef<HTMLButtonElement, ActionButtonProps>(
  (
    {
      disabled = false,
      className = undefined,
      onClick,
      priority = Priority.PRIMARY,
      text,
      children,
      ...rest
    }: ActionButtonProps,
    reference,
  ) => (
    <button
      ref={reference}
      type="button"
      className={clsx(
        'np-action-btn',
        'np-text-body-default-bold',
        priority === Priority.TERTIARY
          ? 'btn-priority-3'
          : priority === Priority.SECONDARY
            ? 'btn-priority-2'
            : 'btn-priority-1',
        className,
      )}
      disabled={disabled}
      onClick={onClick}
      {...rest}
    >
      {children || text}
    </button>
  ),
);

export default ActionButton;
