"use client";
import { useState, type ReactNode } from "react";
import { useTranslation } from "react-i18next";
import { IconInfoCircle } from "@tabler/icons-react";
import { Button } from "@kandev/ui/button";
import { Label } from "@kandev/ui/label";
import { Popover, PopoverContent, PopoverTrigger } from "@kandev/ui/popover";
import { Switch } from "@kandev/ui/switch";
import { Tooltip, TooltipContent, TooltipTrigger } from "@kandev/ui/tooltip";
import { useResponsiveBreakpoint } from "@/hooks/use-responsive-breakpoint";
import { autoFixRoundForState } from "@/lib/gitlab/mr-automation";
import type {
TaskMRAutomationOptionsForMR,
TaskMRAutomationPatch,
TaskMRLifecycleState,
} from "@/lib/types/gitlab";
/** Shared compact-row height: taller touch target on mobile/coarse pointers. */
export function compactRowMinHeight(isMobile: boolean, isFinePointer: boolean): string {
return isMobile || !isFinePointer ? "min-h-11" : "min-h-7";
}
/**
* Dual-mode help affordance: a tap popover on coarse pointers, a hover
* tooltip on fine pointers. Mirrors CIAutomationHelpButton (GitHub).
*/
export function MRAutomationHelpButton({
ariaLabel,
testId,
children,
}: {
ariaLabel: string;
testId: string;
children: ReactNode;
}) {
const { isFinePointer } = useResponsiveBreakpoint();
const [open, setOpen] = useState(false);
const trigger = (
);
if (!isFinePointer) {
return (
{trigger}
{children}
);
}
return (
{trigger}
{children}
);
}
function MRAutomationRow({
id,
label,
checked,
disabled,
onCheckedChange,
help,
describedBy,
}: {
id: string;
label: string;
checked: boolean;
disabled: boolean;
onCheckedChange: (checked: boolean) => void;
help?: ReactNode;
describedBy?: string;
}) {
const { isFinePointer, isMobile } = useResponsiveBreakpoint();
const minHeight = compactRowMinHeight(isMobile, isFinePointer);
return (
{help}
);
}
function MRAutoFixRoundHelpButton({
state,
maxRounds,
}: {
state: TaskMRLifecycleState | undefined;
maxRounds: number | null | undefined;
}) {
const { t } = useTranslation();
const round = autoFixRoundForState(state, maxRounds);
return (
{t("gitlab:mrAutoFixRoundExplanation", { current: round.current, max: round.max })}
);
}
function MRAutoMergeHelpButton() {
const { t } = useTranslation();
return (
{t("gitlab:mrAutoMergeReadyExplanation")}
);
}
/**
* Props shared by every switch-row group. `elementIDSuffix` scopes the DOM ids
* to one merge request: the multi-MR dropdown renders one group per linked MR,
* so a task-only suffix would emit duplicate ids and point every `