package id.ac.ubharajaya.panicbutton

import android.content.Intent
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.Image
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Card
import androidx.compose.material3.CardDefaults
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp

class EvacuationMapsActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            MaterialTheme {
                EvacuationMapsContent(onSelect = { which ->
                    val intent = Intent(this, EvacuationMapDetailActivity::class.java)
                    intent.putExtra("which", which)
                    startActivity(intent)
                })
            }
        }
    }
}

@Composable
fun EvacuationMapsContent(onSelect: (String) -> Unit) {
    Column(modifier = Modifier.fillMaxSize().padding(16.dp)) {
        Text(text = "Peta Jalur Evakuasi", style = MaterialTheme.typography.titleLarge, modifier = Modifier.padding(bottom = 12.dp))

        // Selatan
        Card(modifier = Modifier.fillMaxWidth().padding(bottom = 12.dp).clickable { onSelect("selatan") }, shape = RoundedCornerShape(12.dp), elevation = CardDefaults.cardElevation(defaultElevation = 6.dp)) {
            Row(verticalAlignment = Alignment.CenterVertically, modifier = Modifier.padding(12.dp)) {
                Image(painter = painterResource(id = R.drawable.lantai_1_selatan), contentDescription = "Selatan", modifier = Modifier.size(120.dp))
                Spacer(modifier = Modifier.width(12.dp))
                Column {
                    Text(text = "Jalur Evakuasi Selatan", fontSize = 18.sp)
                    Spacer(modifier = Modifier.height(6.dp))
                    Text(text = "Lihat detail jalur evakuasi lantai selatan.")
                }
            }
        }

        // Utara
        Card(modifier = Modifier.fillMaxWidth().padding(bottom = 12.dp).clickable { onSelect("utara") }, shape = RoundedCornerShape(12.dp), elevation = CardDefaults.cardElevation(defaultElevation = 6.dp)) {
            Row(verticalAlignment = Alignment.CenterVertically, modifier = Modifier.padding(12.dp)) {
                Image(painter = painterResource(id = R.drawable.lantai_1_utara), contentDescription = "Utara", modifier = Modifier.size(120.dp))
                Spacer(modifier = Modifier.width(12.dp))
                Column {
                    Text(text = "Jalur Evakuasi Utara", fontSize = 18.sp)
                    Spacer(modifier = Modifier.height(6.dp))
                    Text(text = "Lihat detail jalur evakuasi lantai utara.")
                }
            }
        }
    }
}
