import { AppShell } from "@/components/AppShell";
import { ProvidersSettings } from "@/components/settings/ProvidersSettings";
import { fetchProviders } from "@/lib/api/server";
import type { ProvidersResponse } from "@/lib/api/types";

// 模型与提供商设置（UX §6.10）。Server Component 取初始数据。
export default async function ProvidersSettingsPage() {
  let initial: ProvidersResponse = { providers: [], tier_routing: [] };
  let loadError = false;
  try {
    initial = await fetchProviders();
  } catch {
    loadError = true;
  }

  return (
    <AppShell title="设置 › 模型与提供商">
      <div className="mx-auto max-w-3xl px-8 py-10">
        {loadError ? (
          <p className="rounded border border-conflict bg-panel p-6 text-conflict">
            无法连接后端服务，请确认 API 已启动后刷新。
          </p>
        ) : (
          <ProvidersSettings initial={initial} />
        )}
      </div>
    </AppShell>
  );
}
