"use client"; import { useCallback, useState } from "react"; import { IconInfoCircle } from "@tabler/icons-react"; import { Button } from "@kandev/ui/button"; import { Checkbox } from "@kandev/ui/checkbox"; import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, } from "@kandev/ui/dialog"; import { Drawer, DrawerContent, DrawerDescription, DrawerHeader, DrawerTitle, } from "@kandev/ui/drawer"; import { Textarea } from "@kandev/ui/textarea"; import { Tooltip, TooltipContent, TooltipTrigger } from "@kandev/ui/tooltip"; import { useTouchDrawer } from "@/hooks/use-compact-task-chrome"; import { cn } from "@/lib/utils"; import { useTranslation } from "react-i18next"; import type { WorkflowMoveEntryOptions } from "@/lib/api/domains/kanban-api"; export type WorkflowMoveOptionsDraft = { resetContext: boolean; instructions: string; skipStepPrompt: boolean; }; const EMPTY_DRAFT: WorkflowMoveOptionsDraft = { resetContext: false, instructions: "", skipStepPrompt: false, }; export function workflowMoveOptionsPayload( draft: WorkflowMoveOptionsDraft, ): WorkflowMoveEntryOptions | undefined { const payload: WorkflowMoveEntryOptions = {}; if (draft.resetContext) payload.reset_context = true; if (draft.skipStepPrompt) payload.skip_step_prompt = true; if (draft.instructions.trim()) payload.instructions = draft.instructions.trim(); return Object.keys(payload).length > 0 ? payload : undefined; } /** * Draft state shared by every move-options surface (stepper disclosure, * proceed popover, dialog, drawer). */ export function useWorkflowMoveOptionsForm() { const [draft, setDraft] = useState(EMPTY_DRAFT); const patchDraft = useCallback((patch: Partial) => { setDraft((current) => ({ ...current, ...patch })); }, []); const resetDraft = useCallback(() => setDraft(EMPTY_DRAFT), []); return { draft, patchDraft, resetDraft, }; } type WorkflowMoveOptionsFieldsProps = { draft: WorkflowMoveOptionsDraft; onDraftChange: (patch: Partial) => void; isTouchSurface: boolean; instructionsRows?: number; }; /** * Move fields own their typography because portaled menus do not share the * dialog/popover text baseline. Touch surfaces retain larger labels and targets. */ export function WorkflowMoveOptionsFields({ draft, onDraftChange, isTouchSurface, instructionsRows = 4, }: WorkflowMoveOptionsFieldsProps) { const { t } = useTranslation(); const rowClass = isTouchSurface ? "flex items-center gap-2.5 min-h-11" : "flex items-start gap-2.5"; const checkboxClass = cn("shrink-0", !isTouchSurface && "mt-0.5"); const hintButtonClass = cn( "inline-flex shrink-0 cursor-pointer items-center justify-center rounded-sm text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring", isTouchSurface ? "size-11" : "mt-0.5 size-4", ); return (
{t("task:workflowMoveSkipStepPromptHint")}