import React, { useRef } from 'react'; import { useAnimatedPresence } from '../../hooks/use-animated-presence'; import { useHardwareBackHandler } from '../../hooks/use-hardware-back-handler'; import { tr } from '../../lib/cookies'; import type { ApiShipment } from '../../lib/shopApi'; import { copyToClipboard } from '../../lib/webview-actions'; interface ShipmentTrackingSheetProps { shipment: ApiShipment | null; onClose: () => void; onCopied?: () => void; } export const ShipmentTrackingSheet: React.FC = ({ shipment, onClose, onCopied, }) => { const isOpen = Boolean(shipment); const { shouldRender, isClosing } = useAnimatedPresence(isOpen, 200); const lastShipmentRef = useRef(shipment); if (shipment) { lastShipmentRef.current = shipment; } const activeShipment = shipment || lastShipmentRef.current; useHardwareBackHandler(() => { onClose(); return true; }, isOpen); if (!shouldRender || !activeShipment) return null; const handleCopyTracking = async () => { if (!activeShipment.tracking_code) return; const ok = await copyToClipboard(activeShipment.tracking_code); if (ok && onCopied) onCopied(); }; return (
e.stopPropagation()} style={{ padding: '22px var(--page-px) calc(24px + var(--safe-bottom, 0px))', display: 'flex', flexDirection: 'column', gap: '16px', maxHeight: '85dvh', overflowY: 'auto', }} >
{tr('Shipment Tracking')} • {activeShipment.booth_name}
{tr('Carrier')} {activeShipment.carrier_name || 'Habib Global Post'}
{activeShipment.tracking_code && (
{tr('Tracking code')}
)}
{tr('Estimated Delivery')} {tr(activeShipment.estimated_delivery_label || '2-3 business day')}
{(activeShipment.events || []).map((ev, idx) => (
{tr(ev.title)} {ev.location ? `${ev.location} • ` : ''} {ev.formatted_time}
))}
); };