"use client";

import { useEffect } from "react";
import Link from "next/link";
import { Box, Stack, Text, Title } from "@mantine/core";
import { PrimaryButton } from "@/components/ui/PrimaryButton";
import { SecondaryButton } from "@/components/ui/SecondaryButton";
import { colors, gradients } from "@/styles/tokens";

export default function RootError({
  error,
  reset,
}: {
  error: Error & { digest?: string };
  reset: () => void;
}) {
  useEffect(() => {
    console.error(error);
  }, [error]);

  return (
    <Box
      className="noga-grid-bg"
      style={{
        minHeight: "100vh",
        background: gradients.dark,
        display: "flex",
        alignItems: "center",
        justifyContent: "center",
        padding: 24,
      }}
    >
      <Stack gap="lg" maw={440} align="center" ta="center">
        <Title order={2} style={{ color: colors.white }}>
          Não foi possível carregar a página
        </Title>
        <Text size="sm" style={{ color: colors.grayMedium, lineHeight: 1.6 }}>
          Feche todos os terminais com <code>npm run dev</code>, rode{" "}
          <strong style={{ color: colors.white }}>npm run dev:clean</strong> (libera as
          portas 3000–3002 e limpa o cache) e abra{" "}
          <strong style={{ color: colors.white }}>http://localhost:3000</strong> com
          Ctrl+Shift+R.
        </Text>
        <Stack gap="sm" w="100%">
          <PrimaryButton fullWidth onClick={() => reset()}>
            Tentar novamente
          </PrimaryButton>
          <Link href="/" style={{ textDecoration: "none", width: "100%" }}>
            <SecondaryButton fullWidth>Ir para a página inicial</SecondaryButton>
          </Link>
        </Stack>
      </Stack>
    </Box>
  );
}
