'use client'


import { signIn } from 'next-auth/react'
import { useState } from 'react'

import { cn } from '@/lib/utils'
import { Button, type ButtonProps } from '@/components/ui/button'
import { IconGitHub, IconSpinner, IconUser, IconW3GPT } from '@/components/ui/icons'
import { useRouter } from 'next/navigation'
import React from 'react'



interface LoginButtonProps extends ButtonProps {
  showGithubIcon?: boolean
  text?: string
}

export function LoginButton({
  // text = 'Login with GitHub',
  text = 'Login with Google',
  showGithubIcon = true,
  className,
  ...props
}: LoginButtonProps) {
  const [isLoading, setIsLoading] = useState(false)

  const router = useRouter()
  return (
    <Button
      variant="outline"
      onClick={() => {
        setIsLoading(true)
        // next-auth signIn() function doesn't work yet at Edge Runtime due to usage of BroadcastChannel
        // signIn('github', { callbackUrl: `/` })
        // signIn('google', { callbackUrl: `/` })
        // router.refresh()

        router.push('/auth/sign-in')
      }}
      disabled={isLoading}
      className={cn(className)}
      {...props}
    >
      {
        // showGithubIcon &&
        // (isLoading ? (
        //   <IconSpinner className="mr-2 animate-spin" />
        // ) : (
        //   <IconUser className="mr-2" />
        // ))
      }
      {!showGithubIcon && isLoading ? (
        <IconSpinner className="mr-1 animate-spin" />
      ) :
        text}
    </Button>
  )
}
