import { h, JSX } from "preact";

export enum ButtonFormats {
   DEFAULT,
   PRIMARY,
   SECONDARY,
   ERROR,
   SUCCESS,
}

export interface IButtonProps extends JSX.HTMLAttributes<HTMLButtonElement> {
   format: ButtonFormats;
}

export default function Button({
   children,
   format,
   className,
   class: c,
   ...props
}: IButtonProps) {
   let cl = "ht-btn";

   if (className) cl += " " + (className || "") + (c || "");

   switch (format) {
      case ButtonFormats.DEFAULT:
         break;
      case ButtonFormats.PRIMARY:
         cl += " ht-btn-primary";
         break;
      case ButtonFormats.SECONDARY:
         cl += " ht-btn-secondary";
         break;
      case ButtonFormats.ERROR:
         cl += " ht-btn-error";
         break;
      case ButtonFormats.SUCCESS:
         cl += " ht-btn-success";
         break;
   }

   return (
      <button className={cl} {...props}>
         {children}
      </button>
   );
}
