struct ContentView: View {
   @State private var appData = ApplicationData.shared
   @State private var selectedItem: MapSelection<MKMapItem>?

   var body: some View {
      Map(position: $appData.cameraPos, selection: $selectedItem) {
         ForEach(appData.listLocations, id: \.self) { place in
            Marker(item: place)
               .tag(MapSelection(place))
         }
      }
      .onMapCameraChange(frequency: .onEnd) { context in
         if selectedItem == nil {
            appData.cameraPos = .region(context.region)
            Task {
               await appData.findPlaces()
            }
         }
      }
      .onChange(of: selectedItem, { old, value in
         if let item = value?.value {
            print(item.name ?? "Undefined")
            print(item.phoneNumber ?? "Undefined")
            print(item.addressRepresentations?.cityName ?? "Undefined")
         }
      })
   }
}