"use client"

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

import Body from "@/components/TempDesignSystem/Text/Body"

import { GenericError } from "./components/GenericError"
import { SASModalContactBlock } from "./components/SASModal"

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

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

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

  return (
    <GenericError
      title={intl.formatMessage({
        id: "Something went wrong",
      })}
    >
      <Body textAlign="center">
        {intl.formatMessage({
          id: "Please try again later",
        })}
      </Body>
      <SASModalContactBlock />
    </GenericError>
  )
}
