import { redirect } from "next/navigation";
import { apiFetch, getCurrentUser } from "@/lib/api";
import { getDict } from "@/lib/i18n";
import { MyProfileView, type MyProfileData } from "@/components/MyProfileView";

export const dynamic = "force-dynamic";

export default async function MyProfilePage() {
  const user = await getCurrentUser();
  if (!user) redirect("/login");
  const t = await getDict();

  if (!user.hasMemberFile) {
    return (
      <p className="rounded-xl border border-slate-200 bg-white p-8 text-center text-sm text-slate-500 shadow-card">
        {t.myProfile.noFile}
      </p>
    );
  }

  const { status, data } = await apiFetch<MyProfileData>("/api/my");
  if (status !== 200 || !data) redirect("/dashboard");

  return <MyProfileView initial={data} />;
}
