import React, { useState } from "react"; import { View, Text, StyleSheet, TextInput, TouchableOpacity, ScrollView, Linking, } from "react-native"; import { Ionicons } from "@expo/vector-icons"; import { useNavigation } from "@react-navigation/native"; const tpsData = [ { nama: "TPS SENGKUT", kecamatan: "BERBEK", alamat: "Desa Werungotok, Kec. Nganjuk", jenis: "Depo Kecil", luas: "1,5 x 1,5", volume: "3.375 m3", latitude: -7.6141, longitude: 111.5177, }, { nama: "TPS NGRONGGOT", kecamatan: "BERBEK", alamat: "Desa Werungotok, Kec. Nganjuk", jenis: "Depo Kecil", luas: "1,5 x 1,5", volume: "3.375 m3", }, { nama: "TPS 3R MASTRIP", kecamatan: "NGANJUK", alamat: "Desa Mangundikaran, Kec. Nganjuk", jenis: "TPS 3R", luas: "2 x 2", volume: "5 m3", latitude: -6.6, longitude: 106.8, }, { nama: "TPS 3R KARTOHARJO", kecamatan: "NGANJUK", alamat: "Desa Kartoharjo, Kec. Nganjuk", jenis: "TPS 3R", luas: "2 x 2", volume: "5 m3", latitude: -7.25, longitude: 112.75, }, { nama: "TPS 3R KSM GANUNGKIDUL", kecamatan: "NGANJUK", alamat: "Desa Ganungkidul, Kec. Nganjuk", jenis: "TPS 3R KSM", luas: "3 x 3", volume: "7.5 m3", latitude: -6.175, longitude: 106.8272, }, { nama: "TPS 3R KSM PAYAMAN", kecamatan: "NGANJUK", alamat: "Desa Payaman, Kec. Nganjuk", jenis: "TPS 3R KSM", luas: "3 x 3", volume: "7.5 m3", latitude: -6.175, longitude: 106.8272, }, { nama: "TPS 3R KSM JATIREJO", kecamatan: "NGANJUK", alamat: "Desa Jatirejo, Kec. Nganjuk", jenis: "TPS 3R KSM", luas: "3 x 3", volume: "7.5 m3", latitude: -6.175, longitude: 106.8272, }, ]; const DaftarTPS = () => { const navigation = useNavigation(); const [search, setSearch] = useState(""); const [activeCategory, setActiveCategory] = useState("TPS"); const filteredTPS = tpsData.filter( (tps) => tps.nama.toLowerCase().includes(search.toLowerCase()) && (activeCategory === "TPS" || tps.jenis === activeCategory) ); const openInMaps = (latitude, longitude) => { const url = `https://www.google.com/maps/search/?api=1&query=${latitude},${longitude}`; Linking.openURL(url); }; const handleEdit = (tps) => { console.log("Edit TPS: ", tps); // Implement the edit functionality here // You can navigate to another screen for editing if needed }; const handleDelete = (id) => { console.log("Delete TPS with ID: ", id); // Implement the delete functionality here // Handle the deletion logic, e.g., updating state or making an API call }; return ( navigation.navigate("Home")} > DAFTAR TPS DI NGANJUK {/* Button for categories */} setActiveCategory("TPS")} > TPS setActiveCategory("TPS 3R")} > TPS 3R setActiveCategory("TPS 3R KSM")} > TPS 3R KSM {filteredTPS.map((tps, index) => ( LUAS TPS {tps.luas} {tps.nama} KECAMATAN {tps.kecamatan} VOLUME MAKSIMAL {tps.volume} Alamat openInMaps(tps.latitude, tps.longitude)} > LOKASI {tps.alamat} Jenis {tps.jenis} {/* Edit and Delete Buttons */} handleEdit(tps)} // Pass the tps object here > Edit handleDelete(tps.id)} // You can pass the id if available > Hapus ))} {/* Tambah TPS Button */} navigation.navigate("TambahTPS")} > TAMBAH TPS ); }; const styles = StyleSheet.create({ container: { flex: 1, backgroundColor: "#fff", padding: 16, marginBottom: 0, marginTop: -40, }, header: { flexDirection: "row", alignItems: "center", justifyContent: "space-between", marginBottom: 10, marginTop: 70, }, backButton: { marginBottom: 10 }, title: { fontSize: 22, fontWeight: "bold", color: "#000", textAlign: "left", marginBottom: 12, marginLeft: 20, marginRight: 230, }, categoryButtonsContainer: { flexDirection: "row", marginBottom: 15, }, categoryButton: { flex: 1, paddingVertical: 10, marginRight: 8, borderRadius: 15, backgroundColor: "white", borderWidth: 1, borderColor: "#2D572C", alignItems: "center", justifyContent: "center", }, activeButton: { backgroundColor: "#2D572C", }, buttonText: { color: "#2D572C", fontWeight: "bold", }, actionButtons: { flexDirection: "row", justifyContent: "space-between", padding: 10, marginTop: 12, }, editButton: { backgroundColor: "#4CAF50", paddingVertical: 8, paddingHorizontal: 20, borderRadius: 8, }, deleteButton: { backgroundColor: "#F44336", paddingVertical: 8, paddingHorizontal: 20, borderRadius: 8, }, buttonText: { color: "#fff", fontWeight: "bold", }, buttonTexts: { color: "#000", fontWeight: "bold", }, tambahButton: { backgroundColor: "#f0F0F0", paddingVertical: 12, borderRadius: 25, alignItems: "center", justifyContent: "center", marginTop: 20, marginHorizontal: 50, borderWidth: 0.5, }, tambahButtonText: { color: "#000", fontSize: 18, fontWeight: "bold", }, activeButtonText: { color: "white", // Change text color to white when the button is active }, searchContainer: { flexDirection: "row", alignItems: "center", marginBottom: 10, }, input: { flex: 1, borderWidth: 1, borderColor: "#999", borderRadius: 10, padding: 10, marginBottom: 10, }, searchButton: { backgroundColor: "#E0E0E0", padding: 10, marginLeft: 8, borderRadius: 8, }, card: { borderRadius: 12, marginBottom: 20, borderColor: "#000", borderWidth: 1, overflow: "hidden", shadowColor: "#000", shadowOpacity: 0.1, shadowRadius: 5, backgroundColor: "#fff", elevation: 3, }, cardHeader: { backgroundColor: "#2D572C", padding: 10, flexDirection: "row", alignItems: "center", }, label: { color: "white", fontSize: 11 }, value: { color: "white", fontWeight: "bold" }, tpsName: { color: "white", fontSize: 16, fontWeight: "bold", justifyContent: "center", marginLeft: 40, }, kecamatan: { color: "white", fontSize: 12, marginLeft: 40 }, labelSmall: { fontSize: 10, color: "white", textAlign: "right" }, volume: { fontSize: 14, color: "white", fontWeight: "bold" }, cardContent: { padding: 12 }, infoRow: { flexDirection: "row", alignItems: "center", gap: 4 }, infoText: { fontWeight: "bold", marginLeft: 8 }, subInfo: { marginLeft: 30, fontSize: 13 }, lokasiButton: { backgroundColor: "#F0F0F0", paddingVertical: 8, paddingHorizontal: 14, borderRadius: 8, shadowColor: "#000", shadowOpacity: 0.1, elevation: 2, marginLeft: 220, borderWidth: 1, }, }); export default DaftarTPS;