package com.aegir.demo.ui

import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateListOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import com.aegir.vmms.vmd.model.BaseMapBuildingFloor
import com.aegir.vmms.wayfinding.model.MapDirectionStep
import com.aegir.vmms.wayfinding.model.Waypoint

/**
 * Backing state for the Compose overlays on top of MapActivity.
 * Mutated from Java (MapActivity) on the main thread.
 */
class MapOverlayState {
    var navTitle by mutableStateOf("")
    val floors = mutableStateListOf<BaseMapBuildingFloor>()
    val floorGroups = mutableStateListOf<FloorGroup>()
    var currentFloor by mutableStateOf<BaseMapBuildingFloor?>(null)
    var bearing by mutableStateOf(0.0)
    var selectedUnitInfo by mutableStateOf<UnitInfo?>(null)
    var basemapMode by mutableStateOf(BasemapMode.MAPLIBRE)
    var floorListSheetShown by mutableStateOf(false)

    var wayfindingActive by mutableStateOf(false)
    var startWaypoint by mutableStateOf<Waypoint?>(null)
    var endWaypoint by mutableStateOf<Waypoint?>(null)
    var routeAvailable by mutableStateOf(false)
    val directions = mutableStateListOf<MapDirectionStep>()
    var directionsSheetShown by mutableStateOf(false)

    fun setDirections(list: List<MapDirectionStep>) {
        directions.clear()
        directions.addAll(list)
    }

    fun setFloors(list: List<BaseMapBuildingFloor>) {
        floors.clear()
        floors.addAll(list)
    }

    fun setFloorGroups(list: List<FloorGroup>) {
        floorGroups.clear()
        floorGroups.addAll(list)
    }

    fun reset() {
        startWaypoint = null
        endWaypoint = null
        routeAvailable = false
        directions.clear()
        directionsSheetShown = false
        wayfindingActive = false
    }
}

data class UnitInfo(
    val uid: String,
    val name: String,
    val category: String,
    val floorId: String,
    val areaSqFt: Int? = null,
)

data class FloorGroup(
    val buildingId: String,
    val buildingName: String,
    val floors: List<BaseMapBuildingFloor>,
)
