'use client'
import {useProfileStore} from '@/components/stores/profile'
import {useRouter} from 'next/navigation'
import {Suspense, use} from 'react'

export default function FreeTrial(props: {
  className: string
}) {
  return (
    <Suspense fallback={<Pending className={props.className}/>} >
      <Resolved className={props.className}/>
    </Suspense>
  )
}

function Resolved(props: {
  className: string
}) {
  const router = useRouter()
  const profile = use(useProfileStore(store => store.profile))

  return (
    <button
      className={props.className}
      onClick={async () => {
        router.push(profile ? '/admin/purchase' : '/product')
      }}
    >
      免费试用
    </button>
  )
}

function Pending(props: {
  className: string
}) {
  const router = useRouter()
  return (
    <button
      className={props.className}
      onClick={async () => {
        router.push('/product')
      }}
    >
      免费试用
    </button>
  )
}
