'use client'

import { useEffect } from 'react'
import Link from 'next/link'

export default function GlobalError({
  error,
  reset,
}: {
  error: Error & { digest?: string }
  reset: () => void
}) {
  useEffect(() => {
    // Log to error reporting service in production
    console.error('Plymouth Metro site error:', error)
  }, [error])

  return (
    <section className="min-h-[80vh] flex items-center bg-metro-light py-16">
      <div className="max-w-2xl mx-auto px-4 sm:px-6 text-center">
        <div
          className="w-20 h-20 rounded-full bg-amber-100 flex items-center justify-center mx-auto mb-6"
          aria-hidden="true"
        >
          <svg
            viewBox="0 0 24 24"
            fill="none"
            stroke="currentColor"
            strokeWidth={2}
            className="w-10 h-10 text-amber-600"
            aria-hidden="true"
          >
            <path
              strokeLinecap="round"
              strokeLinejoin="round"
              d="M12 9v3.75m-9.303 3.376c-.866 1.5.217 3.374 1.948 3.374h14.71c1.73 0 2.813-1.874 1.948-3.374L13.949 3.378c-.866-1.5-3.032-1.5-3.898 0L2.697 16.126zM12 15.75h.007v.008H12v-.008z"
            />
          </svg>
        </div>

        <h1 className="text-3xl font-black text-metro-navy mb-3">
          Something went wrong
        </h1>
        <p className="text-metro-muted leading-relaxed mb-8">
          An unexpected error occurred. Please try again — if the problem persists,
          contact us at{' '}
          <a
            href="mailto:hello@plymouthmetro.co.uk"
            className="text-metro-sky hover:underline"
          >
            hello@plymouthmetro.co.uk
          </a>
          .
        </p>

        <div className="flex flex-col sm:flex-row gap-4 justify-center">
          <button onClick={reset} className="btn-primary px-8 py-3" style={{color:"#ffffff"}}>
            Try again
          </button>
          <Link href="/" className="btn-secondary px-8 py-3">
            Return to Home
          </Link>
        </div>
      </div>
    </section>
  )
}
