package app.voltplan.cable.ui

import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.outlined.AcUnit
import androidx.compose.material.icons.outlined.Air
import androidx.compose.material.icons.outlined.Apartment
import androidx.compose.material.icons.outlined.Bolt
import androidx.compose.material.icons.outlined.Battery0Bar
import androidx.compose.material.icons.outlined.Battery3Bar
import androidx.compose.material.icons.outlined.Battery5Bar
import androidx.compose.material.icons.outlined.BatteryChargingFull
import androidx.compose.material.icons.outlined.BatteryFull
import androidx.compose.material.icons.outlined.Build
import androidx.compose.material.icons.outlined.Cabin
import androidx.compose.material.icons.outlined.CameraAlt
import androidx.compose.material.icons.outlined.Computer
import androidx.compose.material.icons.outlined.Construction
import androidx.compose.material.icons.outlined.DirectionsBoat
import androidx.compose.material.icons.outlined.DirectionsBus
import androidx.compose.material.icons.outlined.DirectionsCar
import androidx.compose.material.icons.outlined.Dns
import androidx.compose.material.icons.outlined.ElectricCar
import androidx.compose.material.icons.outlined.Flight
import androidx.compose.material.icons.outlined.Hardware
import androidx.compose.material.icons.outlined.Headphones
import androidx.compose.material.icons.outlined.Home
import androidx.compose.material.icons.outlined.Kitchen
import androidx.compose.material.icons.outlined.Laptop
import androidx.compose.material.icons.outlined.Lightbulb
import androidx.compose.material.icons.outlined.LocalFireDepartment
import androidx.compose.material.icons.outlined.LocalGasStation
import androidx.compose.material.icons.outlined.LocalLaundryService
import androidx.compose.material.icons.outlined.LocalShipping
import androidx.compose.material.icons.outlined.Memory
import androidx.compose.material.icons.outlined.Microwave
import androidx.compose.material.icons.outlined.PhoneIphone
import androidx.compose.material.icons.outlined.Power
import androidx.compose.material.icons.outlined.Print
import androidx.compose.material.icons.outlined.Sailing
import androidx.compose.material.icons.outlined.Settings
import androidx.compose.material.icons.outlined.SettingsInputAntenna
import androidx.compose.material.icons.outlined.Speaker
import androidx.compose.material.icons.outlined.SportsEsports
import androidx.compose.material.icons.outlined.Storage
import androidx.compose.material.icons.outlined.Thermostat
import androidx.compose.material.icons.outlined.Tv
import androidx.compose.material.icons.outlined.WaterDrop
import androidx.compose.material.icons.outlined.WbSunny
import androidx.compose.material.icons.outlined.Wifi
import androidx.compose.ui.graphics.vector.ImageVector

/**
 * Maps the SF Symbol names persisted by the iOS app to the closest Material Icon.
 * Storing the original symbol strings keeps the two platforms' data models identical;
 * this translation happens only at render time.
 */
fun sfSymbol(name: String?): ImageVector = when (name) {
    // Lighting / loads
    "lightbulb", "lamp.desk" -> Icons.Outlined.Lightbulb
    "fan", "wind" -> Icons.Outlined.Air
    "tv" -> Icons.Outlined.Tv
    "poweroutlet.strip", "poweroutlet.type.c", "powerplug" -> Icons.Outlined.Power
    "speaker.wave.2" -> Icons.Outlined.Speaker
    "refrigerator" -> Icons.Outlined.Kitchen
    "washer", "dishwasher", "dryer" -> Icons.Outlined.LocalLaundryService
    "stove", "cooktop", "microwave" -> Icons.Outlined.Microwave
    "car" -> Icons.Outlined.DirectionsCar
    "bolt.car", "bolt.car.fill" -> Icons.Outlined.ElectricCar
    "cpu" -> Icons.Outlined.Memory
    "desktopcomputer" -> Icons.Outlined.Computer
    "laptopcomputer" -> Icons.Outlined.Laptop
    "iphone" -> Icons.Outlined.PhoneIphone
    "camera" -> Icons.Outlined.CameraAlt
    "gamecontroller", "xbox.logo", "playstation.logo" -> Icons.Outlined.SportsEsports
    "headphones" -> Icons.Outlined.Headphones
    "printer" -> Icons.Outlined.Print
    "wifi" -> Icons.Outlined.Wifi
    "antenna.radiowaves.left.and.right" -> Icons.Outlined.SettingsInputAntenna

    // Bolts / power / chargers
    "bolt", "bolt.fill", "bolt.circle", "bolt.circle.fill", "bolt.horizontal.circle",
    "bolt.square", "bolt.square.fill", "bolt.badge.clock", "bolt.badge.a",
    "bolt.horizontal", "flashlight.on.fill" -> Icons.Outlined.Bolt

    // Batteries
    "battery.100", "batteryblock", "car.battery" -> Icons.Outlined.BatteryFull
    "battery.100.bolt" -> Icons.Outlined.BatteryChargingFull
    "battery.75" -> Icons.Outlined.Battery5Bar
    "battery.25" -> Icons.Outlined.Battery3Bar
    "battery.0" -> Icons.Outlined.Battery0Bar

    // Systems / places
    "building.2", "building" -> Icons.Outlined.Apartment
    "house" -> Icons.Outlined.Home
    "tent" -> Icons.Outlined.Cabin
    "sailboat" -> Icons.Outlined.Sailing
    "ferry" -> Icons.Outlined.DirectionsBoat
    "airplane" -> Icons.Outlined.Flight
    "bus" -> Icons.Outlined.DirectionsBus
    "truck.box" -> Icons.Outlined.LocalShipping
    "server.rack" -> Icons.Outlined.Dns
    "externaldrive" -> Icons.Outlined.Storage
    "gear" -> Icons.Outlined.Settings
    "wrench.adjustable" -> Icons.Outlined.Build
    "hammer" -> Icons.Outlined.Hardware
    "sun.max", "sun.max.fill" -> Icons.Outlined.WbSunny
    "engine.combustion", "engine.combustion.fill" -> Icons.Outlined.Construction
    "fuelpump" -> Icons.Outlined.LocalGasStation
    "drop" -> Icons.Outlined.WaterDrop
    "flame" -> Icons.Outlined.LocalFireDepartment
    "snowflake" -> Icons.Outlined.AcUnit
    "thermometer" -> Icons.Outlined.Thermostat

    else -> Icons.Outlined.Bolt
}

/** Icon options offered in the Load appearance editor (mirrors LoadEditorView). */
val loadIconOptions = listOf(
    "lightbulb", "lamp.desk", "fan", "tv", "poweroutlet.strip", "poweroutlet.type.c",
    "bolt", "xbox.logo", "playstation.logo", "batteryblock", "speaker.wave.2",
    "refrigerator", "washer", "dishwasher", "stove", "microwave", "dryer", "cooktop",
    "car", "bolt.car", "engine.combustion", "wrench.adjustable", "cpu", "desktopcomputer",
    "laptopcomputer", "iphone", "camera", "gamecontroller", "headphones", "printer",
    "wifi", "antenna.radiowaves.left.and.right",
)

/** Icon options offered in the System appearance editor (mirrors SystemEditorView). */
val systemIconOptions = listOf(
    "building.2", "house", "building", "tent", "sailboat", "airplane", "ferry", "bus",
    "truck.box", "server.rack", "externaldrive", "cpu", "gear", "wrench.adjustable",
    "hammer", "lightbulb", "bolt", "powerplug", "battery.100", "sun.max",
    "engine.combustion", "fuelpump", "drop", "flame", "snowflake", "thermometer",
)

/** Icon options offered in the Battery appearance editor. */
val batteryIconOptions = listOf(
    "battery.100", "battery.100.bolt", "battery.75", "battery.25", "battery.0",
    "bolt", "bolt.fill", "bolt.circle", "bolt.horizontal.circle", "powerplug",
    "car.battery", "bolt.square", "lightbulb",
)

/** Icon options offered in the Charger appearance editor. */
val chargerIconOptions = listOf(
    "bolt.fill", "bolt", "bolt.circle", "bolt.circle.fill", "bolt.horizontal.circle",
    "bolt.square", "bolt.square.fill", "bolt.badge.clock", "bolt.badge.a", "powerplug",
    "flashlight.on.fill", "battery.100.bolt",
)
