import { type ButtonHTMLAttributes, type FC, memo, type ReactNode } from 'react'
import MoonLoader from "react-spinners/MoonLoader"
import { type XOR } from '../helpers/types'
import { clx } from '../helpers/utils'

type Props = {
    className?: string;
    isloading?: boolean,
    colorLoading?: string,
} & ButtonHTMLAttributes<HTMLButtonElement> &
    XOR<{ children: ReactNode }, { label: string }>;

const Button: FC<Props> = memo((props: Props) => {

    const buttonClass = clx(
        'flex rounded-xl items-center justify-center text-center h-10 text-sm  bg-primary text-white w-full',
        props.disabled && 'cursor-not-allowed opacity-60',
        props.className
    );

    return (
        <button disabled={props.isloading} {...props} className={`${buttonClass} ${props.className}`} >
            {
                props.isloading ?
                    <MoonLoader color={props.colorLoading || 'white'} size={16} />
                    :
                    props.label || props.children
            }
        </button>
    )
})

export default Button