import type { Metadata } from "next";
import { redirect } from "next/navigation";

import { getCurrentUser } from "@/lib/appwrite/server";
import { getUserTeams } from "@/lib/appwrite/tenant";
import { CreateWorkspaceForm } from "./components/create-workspace-form";

export const metadata: Metadata = {
  title: "İşletmem — Çalışma alanı oluştur",
  description: "İşletmem için ilk çalışma alanınızı kurun.",
};

export default async function OnboardingPage() {
  const user = await getCurrentUser();
  if (!user) redirect("/sign-in");

  const teams = await getUserTeams();
  if (teams && teams.total > 0) {
    redirect("/dashboard");
  }

  return (
    <div className="bg-muted flex min-h-svh flex-col items-center justify-center p-6 md:p-10">
      <div className="w-full max-w-md">
        <CreateWorkspaceForm userName={user.name?.split(" ")[0]} />
      </div>
    </div>
  );
}
