import type {FunctionComponent} from 'react'
import {Button} from '@/components/ui/button'
import {Loader2} from 'lucide-react'

interface SubmitButtonWithLoadingProps {
  text: string
  loadingText: string
  pending?: boolean
}

const SubmitButtonWithLoading: FunctionComponent<SubmitButtonWithLoadingProps> = ({text, loadingText, pending}) => {
  return (
    <Button disabled={pending} type="submit" className="w-full">
      {pending && <Loader2 className="mr-2 h-4 w-4 animate-spin" />}
      {pending ? loadingText : text}
    </Button>
  )
}

export default SubmitButtonWithLoading
