import Link from 'next/link'
import {cookies} from 'next/headers'
import {Button} from '@/components/ui/button'
import {AuthContext} from '@/lib/auth'

export type UserCenterProps = {}

export default async function UserCenter(props: UserCenterProps) {

  const store = await cookies()
  const info = store.get('auth_info')?.value
  const data = info ? JSON.parse(info) as AuthContext : undefined

  return (
    <div className={`flex items-center`}>
      {data == undefined
        ? <>
          <Link
            href="/login"
            className={`w-24 h-12 flex items-center justify-center lg:text-lg`}
          >
            <span>登录</span>
          </Link>
          <Link
            href="/login"
            className={[
              `w-20 lg:w-24 h-10 lg:h-12 bg-gradient-to-r  rounded-sm flex items-center justify-center lg:text-lg text-white`,
              `transition-colors duration-200 ease-in-out`,
              `from-blue-500 to-cyan-400 hover:from-blue-500 hover:to-cyan-300`,
            ].join(' ')}
          >
            <span>注册</span>
          </Link>
        </>
        : (
          <Link href={`/admin`}>
            <Button theme={`gradient`}>
              进入控制台
            </Button>
          </Link>
        )
      }
    </div>
  )
}
