import React, { useId } from 'react' import { Drawer, DrawerTrigger, DrawerContent, DrawerHeader, DrawerTitle, DrawerDescription, DrawerBody, DrawerFooter, DrawerClose, DrawerOverlay, DrawerPortal, } from '../Drawer' import { X } from 'lucide-react' import Block from '../Primitives/Block/Block' import { ButtonSubType, ButtonType, Button } from '../Button' import type { PopoverProps } from './types' import { PopoverSize } from './types' import { FOUNDATION_THEME } from '../../tokens' import { useResponsiveTokens } from '../../hooks/useResponsiveTokens' import { type SkeletonVariant } from '../Skeleton' import type { PopoverTokenType } from './popover.tokens' import PopoverSkeleton from './PopoverSkeleton' type MobilePopoverProps = PopoverProps & { useDrawerOnMobile?: boolean } const MobilePopover: React.FC = ({ open, onOpenChange, heading, description, children, primaryAction, secondaryAction, showCloseButton = true, onClose, trigger, skeleton, size = PopoverSize.MEDIUM, }) => { const popoverTokens = useResponsiveTokens('POPOVER') const shouldShowSkeleton = skeleton?.show const skeletonVariant: SkeletonVariant = (skeleton?.variant as SkeletonVariant) || 'pulse' const bodySkeletonWidth = skeleton?.bodySkeletonProps?.width || '100%' const bodySkeletonHeight = skeleton?.bodySkeletonProps?.height || 200 // Generate unique IDs for accessibility (WCAG 4.1.2 Name, Role, Value) const baseId = useId() const headingId = heading ? `${baseId}-heading` : undefined const descriptionId = description ? `${baseId}-description` : undefined // Construct aria-describedby to link description if present (WCAG 1.3.1 Info and Relationships) const ariaDescribedBy = descriptionId || undefined return ( { if (onOpenChange) { onOpenChange(isOpen) } if (!isOpen && onClose) { onClose() } }} direction="bottom" modal={true} dismissible={true} > {trigger} {(heading || description || shouldShowSkeleton) && ( {shouldShowSkeleton ? ( ) : ( {heading && ( {heading} )} {description && ( {description} )} {showCloseButton && (