'use client';

import { IamSectionCard } from '@/components/iam/IamSectionCard';
import { MenuTreeView } from '@/components/iam/MenuTreeView';
import { useApi } from '@/lib/hooks/use-api';
import { iamMenu } from '@/lib/api/iam';
import type { MenuNode } from '@/lib/api/types/menu';

export default function IamResourcePage() {
  const { data, loading, error } = useApi<MenuNode[]>(() => iamMenu.tree());

  return (
    <IamSectionCard
      title="资源（菜单）"
      description="全局菜单树，对接 GET /api/v1/iam/menu/tree；与侧栏 nav 数据源一致（nav 会按角色过滤）。"
    >
      {loading ? <p className="text-sm text-neutral-500">加载中…</p> : null}
      {error ? <p className="text-sm text-red-600">{error}</p> : null}
      {!loading && !error && data ? <MenuTreeView tree={data} /> : null}
    </IamSectionCard>
  );
}
