import SwiftUI import MapKit struct RestaurantCallOutBox: View { var restaurant: Restaurant @Binding var isVisible: Bool var position: CGPoint @EnvironmentObject var restaurantManager: RestaurantManager var body: some View { GeometryReader { geo in let maxWidth: CGFloat = 250 let maxHeight: CGFloat = 150 let clampedX = min(max(position.x, maxWidth/2), geo.size.width - maxWidth/2) let clampedY = min(max(position.y, maxHeight/2), geo.size.height - maxHeight/2) ZStack(alignment: .topTrailing) { HStack(spacing: 20) { VStack(alignment: .leading, spacing: 8) { Text(restaurant.name) .font(.headline) .foregroundColor(.black) Button(action: { openInAppleMaps() }) { Text("Open in Apple Maps") .foregroundColor(.blue) .underline() } } VStack(alignment: .leading, spacing: 8) { if let rating = restaurant.rating { Text("Rating: \(String(format: "%.1f", rating))") .font(.subheadline) .foregroundColor(.black) } Button(action: { toggleFavorite() }) { Image(systemName: restaurantManager.isFavorite(restaurant) ? "heart.fill" : "heart") .foregroundColor(.red) } } } .padding() .background(Color.white) .cornerRadius(10) .shadow(radius: 5) .frame(width: maxWidth, height: maxHeight) Button(action: { isVisible = false }) { Image(systemName: "xmark.circle.fill") .resizable() .frame(width: 24, height: 24) .foregroundColor(.black) // x color .background(Circle().fill(Color(red: 0.5, green: 0, blue: 0))) // dark red fill: adjust as needed .clipShape(Circle()) } .offset(x: -10, y: 10) } .position(x: clampedX, y: clampedY) } } private func toggleFavorite() { restaurantManager.toggleFavorite(restaurant) // If favorited, annotation changes to a yellow star (handled in MapViewWithBackButton coordinator). } private func openInAppleMaps() { let coordinate = CLLocationCoordinate2D(latitude: restaurant.latitude, longitude: restaurant.longitude) let placemark = MKPlacemark(coordinate: coordinate) let mapItem = MKMapItem(placemark: placemark) mapItem.name = restaurant.name if let phone = restaurant.telephone1 { mapItem.phoneNumber = phone } mapItem.openInMaps(launchOptions: [MKLaunchOptionsShowsTrafficKey: true]) } }