'use client';

import { useEffect } from 'react';

export default function ProjectsError({
  error,
  reset,
}: {
  error: Error & { digest?: string };
  reset: () => void;
}) {
  useEffect(() => {
    console.error('Projects (du-an) error:', error);
  }, [error]);

  return (
    <div className="mx-auto max-w-7xl px-4 py-12">
      <div className="flex min-h-[400px] flex-col items-center justify-center">
        <div className="mx-auto max-w-md text-center">
          <div className="mx-auto flex h-14 w-14 items-center justify-center rounded-full bg-destructive/10">
            <svg
              className="h-7 w-7 text-destructive"
              fill="none"
              stroke="currentColor"
              viewBox="0 0 24 24"
            >
              <path
                strokeLinecap="round"
                strokeLinejoin="round"
                strokeWidth={2}
                d="M19 21V5a2 2 0 00-2-2H7a2 2 0 00-2 2v16m14 0h2m-2 0h-5m-9 0H3m2 0h5M9 7h1m-1 4h1m4-4h1m-1 4h1m-5 10v-5a1 1 0 011-1h2a1 1 0 011 1v5m-4 0h4"
              />
            </svg>
          </div>
          <h2 className="mt-4 text-xl font-semibold">Không thể tải danh sách dự án</h2>
          <p className="mt-2 text-sm text-muted-foreground">
            Đã xảy ra lỗi khi tải dự án bất động sản. Vui lòng thử lại.
          </p>
          {error.digest && (
            <p className="mt-1 text-xs text-muted-foreground">Mã lỗi: {error.digest}</p>
          )}
          <div className="mt-6 flex justify-center gap-3">
            <button
              onClick={reset}
              className="inline-flex h-9 items-center rounded-md bg-primary px-4 text-sm font-medium text-primary-foreground shadow transition-colors hover:bg-primary/90"
            >
              Thử lại
            </button>
            <a
              href="/"
              className="inline-flex h-9 items-center rounded-md border border-input bg-background px-4 text-sm font-medium shadow-sm transition-colors hover:bg-accent hover:text-accent-foreground"
            >
              Về trang chủ
            </a>
          </div>
        </div>
      </div>
    </div>
  );
}
