"use client"

import * as Sentry from "@sentry/nextjs"
import { useEffect } from "react"
import { useIntl } from "react-intl"

export default function Error({
  error,
}: {
  error: Error & { digest?: string }
}) {
  const intl = useIntl()

  useEffect(() => {
    if (!error) return

    console.error(error)
    Sentry.captureException(error)
  }, [error])

  return (
    <p>
      <strong>
        {intl.formatMessage(
          {
            defaultMessage: "Error loading this page ({errorId})",
          },
          {
            errorId: `${error.digest}@${Date.now()}`,
          }
        )}
      </strong>
    </p>
  )
}
