'use client';

import { Loader2Icon } from 'lucide-react';

import { useTextController } from '@/shared/language/hooks/use-text-controller';
import { Button, type ButtonProps } from '@/shared/shadcn-ui/button';

interface SubmitButtonProps extends ButtonProps {
  title?: string;
  isLoading: boolean;
}

export const SubmitButton = ({
  title = 'common.buttons.login',
  size = 'default',
  type = 'submit',
  className,
  disabled,
  isLoading,
  onClick,
  ...props
}: SubmitButtonProps) => {
  const { t } = useTextController();

  return (
    <Button
      onClick={onClick}
      type={type}
      size={size}
      className={className}
      disabled={isLoading || disabled}
      {...props}
    >
      {isLoading ? (
        <Loader2Icon className='animate-spin' />
      ) : (
        (props.children ?? t(title))
      )}
    </Button>
  );
};
