"use client"; import type { ReactNode } from "react"; import { IconChevronDown, IconPlus, IconRocket } from "@tabler/icons-react"; import { Button } from "@kandev/ui/button"; import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger, } from "@kandev/ui/dropdown-menu"; import { Tooltip, TooltipContent, TooltipTrigger } from "@kandev/ui/tooltip"; import { cn } from "@kandev/ui/lib/utils"; import { useTranslation } from "react-i18next"; /** * Split-button: primary "Implement" runs the plan inline in the current * session; the dropdown caret offers "Implement in fresh agent" which starts * a new session with a clean context window. `onClick(fresh)` is invoked * with `false` for the primary path and `true` for the fresh-agent path. */ type ImplementPlanButtonProps = { onClick: (fresh: boolean) => void | Promise; disabled?: boolean; disabledReason?: string; framed?: boolean; testIds?: { root?: string; button?: string; menuTrigger?: string; freshItem?: string; }; }; function legacyRootTestId(rootId: string) { return rootId === "implement-plan-control" ? undefined : "implement-plan-control"; } function DisabledImplementTooltip({ disabledReason, children, }: { disabledReason: string; children: ReactNode; }) { return ( {children} {disabledReason} ); } export function ImplementPlanButton({ onClick, disabled, disabledReason, framed, testIds, }: ImplementPlanButtonProps) { const { t } = useTranslation(); const ids = { root: testIds?.root ?? "implement-plan-control", button: testIds?.button ?? "implement-plan-button", menuTrigger: testIds?.menuTrigger ?? "implement-plan-menu-trigger", freshItem: testIds?.freshItem ?? "implement-fresh-menu-item", }; const controlHeightClass = framed ? "h-5" : "h-7"; const primaryButton = ( ); const primary = disabledReason ? ( primaryButton ) : ( {primaryButton} {t("task:implementThePlanInThisSession")} ); const splitButton = (
{primary} onClick(true)} className="cursor-pointer" >
{t("task:implementInFreshAgent")}
{t("task:startsANewSessionWithA")}
); if (!disabledReason) return splitButton; return ( {splitButton} ); }