import { useNostrAuth } from '@/hooks/useNostrAuth'
import { t } from '@/lib/i18n'
import { ConnectRequiredCard } from './reviewForms/ConnectRequiredCard'
import { ReviewFormView } from './reviewForms/ReviewFormView'
import { useReviewFormController } from './reviewForms/useReviewFormController'
import type { ReviewFormProps } from './reviewForms/reviewFormTypes'

export function ReviewForm({ article, onSuccess, onCancel }: ReviewFormProps): React.ReactElement {
  const { pubkey, connect } = useNostrAuth()
  const ctrl = useReviewFormController({ article, pubkey, onSuccess })

  if (!pubkey) {
    return (
      <ConnectRequiredCard
        message={t('review.form.connectRequired')}
        onConnect={() => {
          void connect()
        }}
      />
    )
  }

  return <ReviewFormView ctrl={ctrl} onCancel={onCancel} />
}
