"use client";

import { useRouter } from "next/navigation";

import { DashboardPageLayout } from "@/components/templates/DashboardPageLayout";
import { ForgejoConnectionForm } from "@/components/git/ForgejoConnectionForm";
import {
  createForgejoConnection,
  type ForgejoConnectionCreate,
} from "@/lib/api-forgejo";

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

  const handleSubmit = async (values: ForgejoConnectionCreate) => {
    await createForgejoConnection(values);
    router.push("/git-projects/connections");
  };

  return (
    <DashboardPageLayout
      signedOut={{
        message: "Sign in to create a Git Project connection.",
        forceRedirectUrl: "/git-projects/connections/new",
        signUpForceRedirectUrl: "/git-projects/connections/new",
      }}
      title="New Git Project Connection"
      description="Connect a Git provider so Pipeline can track repository issues."
      stickyHeader
    >
      <div className="w-full max-w-2xl">
        <ForgejoConnectionForm onSubmit={handleSubmit} />
      </div>
    </DashboardPageLayout>
  );
}
