import React from 'react' import { p as P, BottomDialog, Checkbox } from 'web-components' import { trpc } from '@/lib/trpc-client' import { ChevronRight, Eye, Pencil, XCircle, MapPin, Map, MessageCircle, Phone } from 'lucide-react' interface OrderOptionsMenuProps { open: boolean onClose: () => void order: { id: number readableId: number isPackaged: boolean isDelivered: boolean isFlashDelivery?: boolean address: string addressId: number adminNotes?: string | null userNotes?: string | null latitude?: number | null longitude?: number | null status?: string } onViewDetails: () => void onTogglePackaged: () => void onToggleDelivered: () => void onOpenAdminNotes: () => void onCancelOrder: () => void onAttachLocation: () => void onWhatsApp: () => void onDial: () => void } function getCurrentPosition(): Promise { return new Promise((resolve, reject) => { if (!navigator.geolocation) { reject(new Error('Geolocation is not supported by this browser')) return } navigator.geolocation.getCurrentPosition(resolve, reject, { enableHighAccuracy: true }) }) } export function OrderOptionsMenu({ open, onClose, order, onViewDetails, onTogglePackaged, onToggleDelivered, onOpenAdminNotes, onCancelOrder, onAttachLocation, onWhatsApp, onDial, }: OrderOptionsMenuProps) { const updateAddressCoordsMutation = trpc.admin.order.updateAddressCoords.useMutation() const handleAttachLocation = async () => { try { const location = await getCurrentPosition() const { latitude, longitude } = location.coords await updateAddressCoordsMutation.mutateAsync({ addressId: order.addressId, latitude, longitude, }) window.alert('Success: Location attached to address successfully.') onAttachLocation() } catch (error: any) { if (error?.code === 1) { window.alert('Permission Denied: Location permission is required to attach coordinates.') return } window.alert('Error: Failed to attach location. Please try again.') } } const extractPhone = (address: string) => { const phoneMatch = address.match(/Phone: (\d+)/) return phoneMatch ? phoneMatch[1] : null } const handleWhatsApp = () => { const phone = extractPhone(order.address) if (phone) { window.open(`https://wa.me/91${phone}`, '_blank') } else { window.alert('No phone number found') } } const handleDial = () => { const phone = extractPhone(order.address) if (phone) { window.open(`tel:${phone}`, '_blank') } else { window.alert('No phone number found') } } const handleOpenInMaps = () => { if (order.latitude && order.longitude) { const url = `https://www.google.com/maps/search/?api=1&query=${order.latitude},${order.longitude}` window.open(url, '_blank') } else { window.alert('No location coordinates available') } } const hasCoordinates = order.latitude !== null && order.latitude !== undefined && order.longitude !== null && order.longitude !== undefined return (

Order #{order.readableId}

Select an action to perform

{order.status !== 'cancelled' && ( )} {hasCoordinates && ( )}
) }