import { useNostrAuth } from '@/hooks/useNostrAuth'
import { t } from '@/lib/i18n'
import { ConnectRequiredCard } from './reviewForms/ConnectRequiredCard'
import { ReviewTipFormView } from './reviewForms/ReviewTipFormView'
import { useReviewTipFormController } from './reviewForms/useReviewTipFormController'
import type { ReviewTipFormProps } from './reviewForms/reviewFormTypes'

export function ReviewTipForm({ review, article, onSuccess, onCancel }: ReviewTipFormProps): React.ReactElement {
  const { pubkey, connect } = useNostrAuth()
  const ctrl = useReviewTipFormController({ review, article, pubkey, onSuccess })

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