package com.isidroid.c23.ui.screen.map._components

import androidx.compose.runtime.Composable
import androidx.compose.runtime.State
import androidx.compose.ui.Modifier
import com.isidroid.c23.ui.screen.map.MapContract
import com.isidroid.ui.maps.model.MapMarker
import com.isidroid.ui.maps.MapsComponent
import kotlinx.coroutines.flow.StateFlow

@Composable
fun TPMapComponent(
    onEventSent: (event: MapContract.Event) -> Unit,
    state: State<MapContract.State>,
    mapMarkersStateFlow: StateFlow<List<MapMarker>>,
    modifier: Modifier = Modifier
) {
    val lat = state.value.lat
    val lng = state.value.lng

    if (lat == null || lng == null)
        return

    MapsComponent(
        lat = lat,
        lng = lng,
        mapMarkersStateFlow = mapMarkersStateFlow,
        onCameraMove = { lat1, lng1, radius -> onEventSent(MapContract.Event.CameraMove(lat1, lng1, radius)) },
        clickOnMarker = { onEventSent(MapContract.Event.ClickOnMarker(it)) },
        moveCameraToMyLocation = { onEventSent(MapContract.Event.MoveCameraToMyLocation) },
        modifier = modifier
    )
}