"use client";

import { useRouter } from "next/navigation";

import { DashboardPageLayout } from "@/components/templates/DashboardPageLayout";
import { ForgejoRepositoryForm } from "@/components/git/ForgejoRepositoryForm";
import {
  createForgejoRepository,
  type ForgejoRepositoryCreate,
} from "@/lib/api-forgejo";

export default function ForgejoRepositoriesNewPage() {
  const router = useRouter();

  const handleSubmit = async (values: ForgejoRepositoryCreate) => {
    await createForgejoRepository(values);
    router.push("/git-projects/repositories");
  };

  return (
    <DashboardPageLayout
      signedOut={{
        message: "Sign in to add a Git Project repository.",
        forceRedirectUrl: "/git-projects/repositories/new",
        signUpForceRedirectUrl: "/git-projects/repositories/new",
      }}
      title="Add Git Project Repository"
      description="Add a repository for Pipeline to sync and display in Git Projects."
      stickyHeader
    >
      <div className="w-full max-w-2xl">
        <ForgejoRepositoryForm onSubmit={handleSubmit} />
      </div>
    </DashboardPageLayout>
  );
}
