'use client' import { useEffect, useLayoutEffect, useRef, useState, type ReactNode } from 'react' import { createPortal } from 'react-dom' import { CampaignHoverTooltip } from '@/components/campaign/shared/CampaignHoverTooltip' import { useCampaignListSheet } from '@/components/campaign/shared/CampaignListSheetHost' import { Drawer, DrawerCloseButton, DrawerContent, DrawerDescription, DrawerFooter, DrawerHeader, DrawerTitle, } from '@/components/ui/Drawer' import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/Popover' import { cn } from '@/lib/utils' export type CampaignCellEditOverlayVariant = 'popover' | 'sheet' /** `relative` is load-bearing: see the comment where it is composed below. */ const campaignCellEditTriggerClassName = 'relative min-h-11 rounded-md px-1 hover:bg-muted/60 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring' type CampaignCellEditOverlayProps = { variant: CampaignCellEditOverlayVariant open: boolean onOpenChange: (open: boolean) => void /** Dialog title: the Drawer's heading, and the Popover's accessible name. */ title: string trigger: ReactNode triggerLabel: string triggerClassName?: string triggerBusy?: boolean /** * Announced by the region this shell keeps OUTSIDE the overlay. Closing is * what commits a draft, and a region rendered inside the Popover/Drawer * unmounts with it — so the one announcement that matters most ("Salvando…", * and the failure that follows) was the one that never reached a screen * reader (B32+ F4). */ statusMessage?: string children: ReactNode // Popover only ───────────────────────────────────────────────────────────── /** B23's read-without-opening tooltip: there is no hover on touch. */ tooltipContent?: ReactNode align?: 'start' | 'center' | 'end' contentClassName?: string /** * Leaves focus on the trigger so the control's own fields decide what to * focus. The Drawer never needs it — it always opens with focus on its title, * never on a field (see `initialFocus` below). */ preventPopoverAutoFocus?: boolean // Sheet only ─────────────────────────────────────────────────────────────── /** Subject line under the title: which row is being edited. */ description?: string sheetBodyClassName?: string /** * Replaces the default "Fechar" for a sheet whose primary action is an * explicit submit (E14's "Registrar movimento"): in a scrolling body the * button drifts below the fold, and the footer is where a thumb expects it. * A submit that belongs to a `