Skip to content

Codebase intelligence for AI and humans: code health scores, auto-generated docs, git analytics, dead code detection, and architectural decisions via MCP.

1.8 KB
Raw Blame
"use client";

import { GenerateConfirmDialog } from "@repowise-dev/ui/wiki/regenerate-button";
import { providerSetupHref } from "@/lib/utils/page-href";
import { formatEstimateCost } from "@/lib/generate-format";
import { type useBulkGenerate } from "@/lib/hooks/use-bulk-generate";
import { useTranslations } from "next-intl";

/**
 * Maps a `useBulkGenerate` flow onto the shared, presentational
 * `GenerateConfirmDialog` (selection-scoped cascade wording). One estimate, one
 * confirm: no coverage picker, since a free file layer has nothing to ration.
 */
export function BulkGenerateConfirm({
  flow,
  repoId,
  title,
}: {
  flow: ReturnType<typeof useBulkGenerate>;
  repoId: string;
  /** Dialog title, e.g. "Write the subsystem pages". */
  title?: string;
}) {
  const t = useTranslations("docs");
  const { estimate, noProvider } = flow;
  const pages = estimate?.total_pages ?? 0;

  return (
    <GenerateConfirmDialog
      open={flow.confirmOpen}
      onOpenChange={flow.setConfirmOpen}
      mode="write"
      title={title ?? t("bulk.title")}
      cascadeScope="selection"
      description={t("bulkConfirm.description")}
      confirmLabel={
        pages > 0
          ? t("bulkConfirm.writePages", { count: pages })
          : t("bulkConfirm.writeWithAi")
      }
      cascade={flow.cascade}
      onCascadeChange={flow.changeCascade}
      estimate={
        estimate && !noProvider
          ? {
              totalPages: estimate.total_pages,
              costText: formatEstimateCost(estimate.estimate),
              staleCount: estimate.pages_to_mark_stale,
            }
          : null
      }
      estimateLoading={flow.estimateLoading}
      estimateError={flow.estimateError}
      noProvider={noProvider}
      settingsHref={providerSetupHref(repoId)}
      onConfirm={flow.confirm}
      launching={flow.launching}
    />
  );
}