"use client";

import { useAuth } from "@/hooks/useAuth";
import { AuthGuard } from "@/components/auth/AuthGuard";

/**
 * 어드민 권한 디버깅 페이지
 */
export default function AdminDebugPage() {
  const { user, isLoggedIn, isAdmin, loading, error } = useAuth();

  return (
    <AuthGuard requireAdmin={true}>
      <div className="p-6">
        <h1 className="mb-4 text-2xl font-bold">어드민 권한 디버깅</h1>

        <div className="space-y-4">
          <div className="rounded bg-muted p-4">
            <h2 className="mb-2 font-semibold">인증 상태</h2>
            <p>로딩: {loading ? "예" : "아니오"}</p>
            <p>로그인: {isLoggedIn ? "예" : "아니오"}</p>
            <p>관리자: {isAdmin ? "예" : "아니오"}</p>
            {error && <p className="text-destructive">에러: {error}</p>}
          </div>

          {user && (
            <div className="rounded bg-primary/10 p-4">
              <h2 className="mb-2 font-semibold">사용자 정보</h2>
              <p>ID: {user.userId}</p>
              <p>이름: {user.userName}</p>
              <p>타입: {user.userType}</p>
              <p>부서: {user.deptName}</p>
              <p>회사: {user.companyCode}</p>
            </div>
          )}

          <div className="rounded bg-emerald-100 p-4">
            <h2 className="mb-2 font-semibold">토큰 정보</h2>
            <p>
              localStorage 토큰: {typeof window !== "undefined" && localStorage.getItem("authToken") ? "존재" : "없음"}
            </p>
          </div>
        </div>
      </div>
    </AuthGuard>
  );
}
