import React, { useState, useRef, useCallback, useEffect } from "react"; import { View, Text, StyleSheet, TouchableOpacity, Alert, Dimensions, Platform, StatusBar as RNStatusBar, ScrollView, Image, } from "react-native"; import { CameraView, CameraType, useCameraPermissions } from "expo-camera"; import { StatusBar } from "expo-status-bar"; import { Ionicons } from "@expo/vector-icons"; import { LinearGradient } from "expo-linear-gradient"; import * as ImageManipulator from "expo-image-manipulator"; import * as ImagePicker from "expo-image-picker"; import { WebView } from "react-native-webview"; import { useTheme } from "@/contexts/ThemeContext"; const CAMERA_SIZE = Dimensions.get("window").width * 0.85; const OVAL_WIDTH = CAMERA_SIZE * 0.55; const OVAL_HEIGHT = CAMERA_SIZE * 0.75; const OVAL_TOP = (CAMERA_SIZE - OVAL_HEIGHT) / 2; const OVAL_LEFT = (CAMERA_SIZE - OVAL_WIDTH) / 2; export type ScanStatus = "idle" | "scanning" | "detected" | "success" | "failed"; export interface FaceScanResult { success: boolean; message: string; nama_mahasiswa?: string; nim?: string; status_presensi?: string; confidence?: number; lbph_score?: number; cnn_score?: number; is_known?: boolean; waktu_presensi?: string; inference_time_ms?: number; } export interface FaceRecognitionProps { token: string; idPertemuan: number; namaMatakuliah: string; pertemuanKe: number; modeLokasi: "bebas" | "wajib"; userLocation: { latitude: number; longitude: number } | null; geolokasiData: { latitude: number; longitude: number; radius_meter: number; nama_lokasi: string; } | null; isMockLocation: boolean; locationLoading: boolean; API_BASE: string; onBack: () => void; onPresensiSuccess: () => void; scanStatus: ScanStatus; setScanStatus: React.Dispatch>; capturedImage: string | null; setCapturedImage: React.Dispatch>; showPreview: boolean; setShowPreview: React.Dispatch>; cameraRef: React.RefObject; facing: CameraType; setFacing: React.Dispatch>; isCapturing: boolean; setIsCapturing: React.Dispatch>; faceScanResult: FaceScanResult | null; setFaceScanResult: React.Dispatch>; isGalleryImage: boolean; setIsGalleryImage: React.Dispatch>; galleryBase64: string | null; setGalleryBase64: React.Dispatch>; } const THEME = { bg: "#FFFFFF", bgSecondary: "#F8FAFC", bgCard: "#FFFFFF", bgInput: "#F1F5F9", border: "#E2E8F0", borderLight: "#F1F5F9", textPrimary: "#1E293B", textSecondary: "#64748B", textMuted: "#94A3B8", primary: "#2563EB", primaryLight: "#3B82F6", primaryDark: "#1D4ED8", primaryBg: "#EFF6FF", success: "#10B981", successBg: "#ECFDF5", warning: "#F59E0B", warningBg: "#FFFBEB", danger: "#EF4444", dangerBg: "#FEF2F2", shadow: "rgba(0, 0, 0, 0.06)", }; interface LeafletMapProps { userLocation: { latitude: number; longitude: number } | null; geolokasiData: { latitude: number; longitude: number; radius_meter: number; nama_lokasi: string; } | null; distanceToCenter: number | null; } function LeafletMap({ userLocation, geolokasiData, distanceToCenter }: LeafletMapProps) { const mapWebViewRef = useRef(null); const getMapHTML = useCallback(() => { const centerLat = geolokasiData?.latitude ?? userLocation?.latitude ?? -6.2088; const centerLng = geolokasiData?.longitude ?? userLocation?.longitude ?? 106.8456; let geoMarker = ''; let circles = ''; let userMarkerInit = ''; if (userLocation) { userMarkerInit = `var userMarker = L.marker([${userLocation.latitude}, ${userLocation.longitude}], { icon: L.divIcon({ className: 'custom-marker', html: '
', iconSize: [14, 14], iconAnchor: [7, 7] }) }).addTo(map).bindPopup('Posisi Anda'); var userAccuracyCircle = L.circle([${userLocation.latitude}, ${userLocation.longitude}], { radius: 8, color: '#2563EB', fillColor: '#2563EB', fillOpacity: 0.15, weight: 1 }).addTo(map);`; } else { userMarkerInit = `var userMarker = null; var userAccuracyCircle = null;`; } if (geolokasiData) { geoMarker = `L.marker([${geolokasiData.latitude}, ${geolokasiData.longitude}], { icon: L.divIcon({ className: 'custom-marker', html: '
', iconSize: [16, 16], iconAnchor: [8, 8] }) }).addTo(map).bindPopup('${geolokasiData.nama_lokasi}');`; circles = `L.circle([${geolokasiData.latitude}, ${geolokasiData.longitude}], { radius: ${geolokasiData.radius_meter}, color: '#EF4444', fillColor: '#EF4444', fillOpacity: 0.12, weight: 2 }).addTo(map);`; } return `
`; }, [geolokasiData, userLocation]); // FIX: added userLocation to deps // Send real-time location updates to WebView without re-rendering HTML useEffect(() => { if (userLocation && mapWebViewRef.current) { mapWebViewRef.current.postMessage(JSON.stringify({ type: 'updateUserLocation', lat: userLocation.latitude, lng: userLocation.longitude, })); } }, [userLocation]); return ( {distanceToCenter !== null && geolokasiData ? ( distanceToCenter <= geolokasiData.radius_meter ? ( ✅ Dalam Radius ({Math.round(distanceToCenter)}m dari pusat) ) : ( ⚠️ Di Luar Radius – Tidak bisa presensi ) ) : ( Memuat data lokasi... )} ); } // ─── Oval Mask Overlay Component ───────────────────────────────────────────── // ─── Oval Mask Overlay Component ───────────────────────────────────────────── function OvalMaskOverlay() { return ; } // ─── Main Component ────────────────────────────────────────────────────────────── export default function FaceRecognition(props: FaceRecognitionProps) { const [permission, requestPermission] = useCameraPermissions(); const { isDarkMode, theme: themeContext } = useTheme(); // ── State tambahan untuk low-light handling ───────────────────────────── const [isTorchOn, setIsTorchOn] = useState(false); const [lowLightWarning, setLowLightWarning] = useState(false); const retryCountRef = useRef(0); // Jumlah auto-retry yang sudah dilakukan const colors = { bg: themeContext.bg, bgCard: themeContext.cardBg, bgInput: isDarkMode ? "#1E293B" : "#F1F5F9", border: themeContext.border, borderLight: themeContext.divider, textPrimary: themeContext.textPrimary, textSecondary: themeContext.textSecondary, textMuted: themeContext.textMuted, primary: themeContext.accent, primaryLight: isDarkMode ? "#60A5FA" : "#3B82F6", primaryBg: themeContext.accentLight, success: isDarkMode ? "#34D399" : "#10B981", warning: isDarkMode ? "#FBBF24" : "#F59E0B", danger: isDarkMode ? "#F87171" : "#EF4444", }; const { token, idPertemuan, namaMatakuliah, pertemuanKe, modeLokasi, userLocation, geolokasiData, isMockLocation, locationLoading, API_BASE, onBack, onPresensiSuccess, scanStatus, setScanStatus, capturedImage, setCapturedImage, showPreview, setShowPreview, cameraRef, facing, isCapturing, setIsCapturing, faceScanResult, setFaceScanResult, isGalleryImage, setIsGalleryImage, galleryBase64, setGalleryBase64, } = props; const getScanStatusColor = (): string => { switch (scanStatus) { case "scanning": return colors.primary; case "detected": return "#10B981"; case "success": return colors.success; case "failed": return colors.danger; default: return colors.primary; } }; const getScanStatusText = (): string => { switch (scanStatus) { case "scanning": return "Memindai wajah..."; case "detected": return "Wajah terdeteksi!"; case "success": return "✓ Presensi Berhasil!"; case "failed": return "✗ Wajah tidak dikenali"; default: return "Posisikan wajah dalam oval"; } }; const haversineDistance = (lat1: number, lon1: number, lat2: number, lon2: number): number => { const R = 6_371_000; const phi1 = (lat1 * Math.PI) / 180; const phi2 = (lat2 * Math.PI) / 180; const dPhi = ((lat2 - lat1) * Math.PI) / 180; const dLambda = ((lon2 - lon1) * Math.PI) / 180; const a = Math.sin(dPhi / 2) ** 2 + Math.cos(phi1) * Math.cos(phi2) * Math.sin(dLambda / 2) ** 2; return R * 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); }; const muteShutterSound = async () => { if (Platform.OS === "ios") { try { const AudioSession = require("expo-av").Audio; await AudioSession.setAudioModeAsync({ playsInSilentModeIOS: true, staysActiveInBackground: false }); } catch { } } }; const blobToBase64 = (blob: Blob): Promise => { return new Promise((resolve, reject) => { const reader = new FileReader(); reader.onloadend = () => { const base64 = (reader.result as string).split(",")[1]; resolve(base64); }; reader.onerror = reject; reader.readAsDataURL(blob); }); }; const cropToOvalRegion = async (photoUri: string, photoWidth: number, photoHeight: number, isFront: boolean): Promise => { try { // CameraView uses a cover-style preview: the source image is scaled // uniformly until it fills the square camera window, then the excess // pixels are clipped from the centre. Mapping with independent scaleX / // scaleY made the crop drift away from the oval on portrait/landscape // photos, even when the user's face was positioned correctly. const coverScale = Math.max(CAMERA_SIZE / photoWidth, CAMERA_SIZE / photoHeight); const renderedWidth = photoWidth * coverScale; const renderedHeight = photoHeight * coverScale; const renderedOffsetX = (CAMERA_SIZE - renderedWidth) / 2; const renderedOffsetY = (CAMERA_SIZE - renderedHeight) / 2; const ovalLeft = (CAMERA_SIZE - OVAL_WIDTH) / 2; const ovalTop = (CAMERA_SIZE - OVAL_HEIGHT) / 2; // Keep useful context around the face for YuNet landmark alignment. const cropPadding = CAMERA_SIZE * 0.16; const previewLeft = Math.max(0, ovalLeft - cropPadding); const previewTop = Math.max(0, ovalTop - cropPadding); const previewRight = Math.min(CAMERA_SIZE, ovalLeft + OVAL_WIDTH + cropPadding); const previewBottom = Math.min(CAMERA_SIZE, ovalTop + OVAL_HEIGHT + cropPadding); const toPhotoX = (x: number) => (x - renderedOffsetX) / coverScale; const toPhotoY = (y: number) => (y - renderedOffsetY) / coverScale; let scaledCropLeft = Math.floor(toPhotoX(previewLeft)); let scaledCropTop = Math.floor(toPhotoY(previewTop)); let scaledCropRight = Math.ceil(toPhotoX(previewRight)); let scaledCropBottom = Math.ceil(toPhotoY(previewBottom)); // Clamp after mapping because the preview may extend beyond the source // image on one axis. scaledCropLeft = Math.max(0, Math.min(photoWidth - 1, scaledCropLeft)); scaledCropTop = Math.max(0, Math.min(photoHeight - 1, scaledCropTop)); scaledCropRight = Math.max(scaledCropLeft + 1, Math.min(photoWidth, scaledCropRight)); scaledCropBottom = Math.max(scaledCropTop + 1, Math.min(photoHeight, scaledCropBottom)); const scaledCropWidth = scaledCropRight - scaledCropLeft; const scaledCropHeight = scaledCropBottom - scaledCropTop; const actions: ImageManipulator.Action[] = []; actions.push({ crop: { originX: scaledCropLeft, originY: scaledCropTop, width: scaledCropWidth, height: scaledCropHeight } }); // Mirror only after cropping. Mirroring first changes the crop origin // and can select the opposite side of the source photo. if (isFront) { actions.push({ flip: ImageManipulator.FlipType.Horizontal }); } actions.push({ resize: { width: 800 } }); const manipResult = await ImageManipulator.manipulateAsync( photoUri, actions, { compress: 0.95, format: ImageManipulator.SaveFormat.JPEG } ); return manipResult.uri; } catch (error) { console.warn("Crop failed, using original:", error); return photoUri; } }; const handleCapture = async (isAutoRetry: boolean = false) => { if (isCapturing && !isAutoRetry) return; if (!token) { Alert.alert("Error", "Sesi login tidak valid. Silahkan login ulang."); return; } setIsCapturing(true); setScanStatus("scanning"); if (!isAutoRetry) { setFaceScanResult(null); retryCountRef.current = 0; } try { let finalBase64: string; if (isGalleryImage && galleryBase64) { // ── Gambar dari Galeri ────────────────────────────────────────── // FIX: Resize gambar galeri agar konsisten dengan gambar kamera. // Sebelumnya gambar galeri langsung dikirim tanpa preprocessing, // menyebabkan ukuran tidak konsisten dengan foto kamera (resize 800px). try { const galleryUri = capturedImage; if (galleryUri) { const resizedGallery = await ImageManipulator.manipulateAsync( galleryUri, [{ resize: { width: 800 } }], { compress: 0.95, format: ImageManipulator.SaveFormat.JPEG } ); const resizedBlob = await (await fetch(resizedGallery.uri)).blob(); finalBase64 = await blobToBase64(resizedBlob); } else { finalBase64 = galleryBase64; } } catch { // Fallback ke base64 galeri asli jika resize gagal finalBase64 = galleryBase64; } } else { // ── Foto dari Kamera ──────────────────────────────────────────── if (!cameraRef.current) { throw new Error("Kamera tidak tersedia"); } await muteShutterSound(); const photo = await cameraRef.current.takePictureAsync({ quality: 1, base64: true, imageType: "jpg" as any, shutterSound: false, ...(Platform.OS === "ios" && { mute: true }), }); if (!photo?.base64) { throw new Error("Gagal mengambil foto dari kamera"); } setCapturedImage(photo.uri); setShowPreview(true); setScanStatus("detected"); await new Promise((r) => setTimeout(r, 300)); // Jangan crop di Android. Lakukan resize + re-encode saja untuk // menormalkan EXIF orientation. cv2.imdecode di backend membaca // piksel JPEG tanpa menerapkan EXIF orientation; mengirim base64 asli // dapat membuat foto terlihat tegak di Android tetapi terbaca miring // oleh YuNet. try { const normalized = await ImageManipulator.manipulateAsync( photo.uri, [{ resize: { width: 1200 } }], { compress: 0.95, format: ImageManipulator.SaveFormat.JPEG } ); const normalizedBlob = await (await fetch(normalized.uri)).blob(); finalBase64 = await blobToBase64(normalizedBlob); } catch { // Fallback only if the platform cannot re-encode the photo. finalBase64 = photo.base64; } } const res = await fetch(`${API_BASE}/presensi/face-scan`, { method: "POST", headers: { "Content-Type": "application/json", Authorization: `Bearer ${token}` }, body: JSON.stringify({ id_pertemuan: idPertemuan, foto_base64: finalBase64, latitude: userLocation?.latitude ?? null, longitude: userLocation?.longitude ?? null }), }); let result: FaceScanResult; try { result = await res.json(); } catch { throw new Error(`Server error: HTTP ${res.status}`); } if (res.ok && result.success) { setScanStatus("success"); setFaceScanResult(result); setLowLightWarning(false); retryCountRef.current = 0; const confPct = result.confidence ? `${(result.confidence * 100).toFixed(1)}%` : ""; const statusLabel = result.status_presensi === "terlambat" ? "Terlambat" : "Hadir"; Alert.alert( `Berhasil ${statusLabel}!`, `${result.nama_mahasiswa ?? ""} (${result.nim ?? ""})\n\nPresensi tercatat sebagai ${statusLabel}\nSkor kepercayaan: ${confPct}\nWaktu deteksi: ${result.inference_time_ms?.toFixed(0) ?? 0}ms`, [{ text: "OK", onPress: () => { setScanStatus("idle"); setFaceScanResult(null); setCapturedImage(null); setShowPreview(false); setIsGalleryImage(false); setGalleryBase64(null); onPresensiSuccess(); } }], ); } else if ( res.ok && !result.success && result.is_known === true && result.message?.toLowerCase().includes("sudah melakukan presensi") ) { // Backend: presensi sudah tercatat sebelumnya. // Treat sebagai success — redirect ke students view & disable tombol scan. setScanStatus("success"); setLowLightWarning(false); retryCountRef.current = 0; Alert.alert( "Sudah Tercatat", "Presensi Anda untuk sesi ini sudah tercatat sebelumnya.", [{ text: "OK", onPress: () => { setScanStatus("idle"); setFaceScanResult(null); setCapturedImage(null); setShowPreview(false); setIsGalleryImage(false); setGalleryBase64(null); onPresensiSuccess(); } }], ); } else { // Gagal — tampilkan error normal setScanStatus("failed"); setLowLightWarning(false); retryCountRef.current = 0; const msg = result.message ?? (res.ok ? "Wajah tidak dikenali" : `HTTP ${res.status}`); // Tampilkan skor similarity agar mudah di-debug const confPct = result.confidence != null ? `\nSkor kesamaan: ${(result.confidence * 100).toFixed(1)}% (threshold ~45%)` : ""; Alert.alert("Gagal", `${msg}${confPct}`, [{ text: "Coba Lagi", onPress: () => { setScanStatus("idle"); setCapturedImage(null); setShowPreview(false); setIsGalleryImage(false); setGalleryBase64(null); } }]); } } catch (err: unknown) { setScanStatus("failed"); retryCountRef.current = 0; const errMsg = err instanceof Error ? err.message : "Terjadi kesalahan tidak diketahui"; Alert.alert("Error", errMsg.includes("face-scan") ? "ML service tidak tersedia. Pastikan server ML berjalan di port 8001." : errMsg, [{ text: "Coba Lagi", onPress: () => { setScanStatus("idle"); setCapturedImage(null); setShowPreview(false); setIsGalleryImage(false); setGalleryBase64(null); } }]); } finally { setIsCapturing(false); } }; // ─── Handle Manual Input (NIM-based) ────────────────────────────────────── const handleManualInput = async (nim: string) => { if (!token) { Alert.alert("Error", "Sesi login tidak valid. Silahkan login ulang."); return; } setIsCapturing(true); setScanStatus("scanning"); try { const res = await fetch(`${API_BASE}/presensi/manual`, { method: "POST", headers: { "Content-Type": "application/json", Authorization: `Bearer ${token}`, }, body: JSON.stringify({ id_pertemuan: idPertemuan, nim: nim, latitude: userLocation?.latitude ?? null, longitude: userLocation?.longitude ?? null, }), }); const result = await res.json(); if (res.ok && result.success) { setScanStatus("success"); const statusLabel = result.status_presensi === "terlambat" ? "Terlambat" : "Hadir"; Alert.alert( `Berhasil ${statusLabel}!`, `${result.nama_mahasiswa ?? ""} (${result.nim ?? ""})\n\nPresensi tercatat sebagai ${statusLabel}`, [{ text: "OK", onPress: () => { setScanStatus("idle"); onPresensiSuccess(); } }], ); } else { setScanStatus("failed"); Alert.alert("Gagal", result.message ?? "Gagal melakukan presensi manual", [ { text: "Coba Lagi", onPress: () => { setScanStatus("idle"); } }, ]); } } catch (err) { setScanStatus("failed"); Alert.alert("Error", "Terjadi kesalahan koneksi", [ { text: "OK", onPress: () => { setScanStatus("idle"); } }, ]); } finally { setIsCapturing(false); } }; // ─── Calculate distance & radius status for scan view ── const scanDistanceToCenter = userLocation && geolokasiData ? haversineDistance( userLocation.latitude, userLocation.longitude, geolokasiData.latitude, geolokasiData.longitude, ) : null; const scanIsInRadius = !isMockLocation && (modeLokasi === "bebas" || locationLoading || (userLocation !== null && geolokasiData !== null && scanDistanceToCenter !== null && scanDistanceToCenter <= geolokasiData.radius_meter)); // Tombol scan aktif jika: ada gambar galeri siap kirim, atau kamera siap & dalam radius const captureDisabled = isCapturing || isMockLocation || (!isGalleryImage && (showPreview || !scanIsInRadius)); // ─── Permission check ── if (!permission) { return ( Memuat Kamera... ); } if (!permission.granted) { return ( Izin Kamera Diperlukan Aplikasi membutuhkan akses kamera untuk mengenali wajah Anda dalam proses presensi. Izinkan Kamera ); } const frameColor = getScanStatusColor(); return ( { setScanStatus("idle"); setCapturedImage(null); setShowPreview(false); onBack(); }} > Scan Wajah {namaMatakuliah} · ke-{pertemuanKe} {/* Torch / Flash Button — untuk kondisi low-light indoor */} setIsTorchOn((v) => !v)} > {/* Gallery Button */} { try { const result = await ImagePicker.launchImageLibraryAsync({ mediaTypes: ["images"], allowsEditing: true, aspect: [OVAL_WIDTH, OVAL_HEIGHT], quality: 1, base64: true, }); if (!result.canceled && result.assets[0]) { const asset = result.assets[0]; setCapturedImage(asset.uri); setShowPreview(true); setScanStatus("detected"); // Tandai bahwa gambar berasal dari galeri & simpan base64-nya setIsGalleryImage(true); setGalleryBase64(asset.base64 ?? null); } } catch (err) { Alert.alert("Error", "Gagal memilih gambar dari galeri"); } }} > {/* Manual Input Button */} { Alert.prompt( "Input Manual", "Masukkan NIM untuk presensi manual:", async (nim) => { if (!nim || nim.trim() === "") { Alert.alert("Error", "NIM tidak boleh kosong"); return; } await handleManualInput(nim.trim()); }, "plain-text", "", "number-pad" ); }} > {/* Camera Area clipped to the oval */} {showPreview && capturedImage ? ( ) : ( )} {/* Oval border ring */} {showPreview && ( {capturedImage?.startsWith("file://") || capturedImage?.startsWith("/") ? "Dari Galeri" : "Tertangkap"} )} {/* Status Badge */} {getScanStatusText()} {/* Mock GPS Warning in Scan View */} {isMockLocation && ( ⛔ GPS Palsu Terdeteksi! Matikan aplikasi fake GPS dan gunakan GPS bawaan HP. Tombol scan dinonaktifkan. )} {/* Low-Light Warning Banner */} {lowLightWarning && !isTorchOn && ( 💡 Pencahayaan Kurang Nyalakan senter (⚡) di header atau cari area lebih terang setIsTorchOn(true)} style={styles.torchQuickBtn} > Nyalakan )} {/* Torch Active Banner */} {isTorchOn && ( Senter aktif — mode pencahayaan rendah )} {/* ── Peta Lokasi ── */} {modeLokasi === "bebas" && ( 🔓 Presensi Bebas – Dapat presensi dari mana saja )} {/* Info Panel */} Pastikan wajah terlihat jelas dan pencahayaan cukup Di ruangan gelap? Nyalakan ⚡ senter di kanan atas Lepas kacamata atau masker jika ada Pilih dari Galeri atau Input Manual {/* Capture Button – dinonaktifkan jika di luar radius (mode wajib) */} {modeLokasi === "wajib" && !scanIsInRadius && !locationLoading && ( ⚠️ Anda di luar radius – Tidak dapat presensi )} handleCapture()} disabled={captureDisabled} activeOpacity={0.8} > {isCapturing ? ( ) : isMockLocation ? ( ) : isGalleryImage ? ( ) : showPreview ? ( ) : !scanIsInRadius ? ( ) : ( )} {isCapturing ? "Memproses..." : isMockLocation ? "GPS Palsu" : isGalleryImage ? "Scan Gambar Galeri" : showPreview ? "Tercapture" : !scanIsInRadius ? "Di Luar Radius" : "Scan Wajah"} ); } // ─── Styles ───────────────────────────────────────────────────────────────── // ─── Styles ───────────────────────────────────────────────────────────────── const styles = StyleSheet.create({ container: { flex: 1, backgroundColor: THEME.bg, }, header: { flexDirection: "row", alignItems: "center", paddingTop: Platform.OS === "android" ? (RNStatusBar.currentHeight ?? 40) : 55, paddingHorizontal: 20, paddingBottom: 14, backgroundColor: THEME.bg, }, headerCenter: { flex: 1, marginLeft: 12, }, headerTitle: { fontSize: 22, fontWeight: "800", color: THEME.textPrimary, letterSpacing: 0.3, }, headerSubtitle: { fontSize: 12, color: THEME.primary, fontWeight: "500", marginTop: 2, }, backButton: { width: 40, height: 40, borderRadius: 10, backgroundColor: THEME.bgInput, alignItems: "center", justifyContent: "center", borderWidth: 1, borderColor: THEME.border, }, iconButton: { width: 40, height: 40, borderRadius: 10, backgroundColor: THEME.bgInput, alignItems: "center", justifyContent: "center", borderWidth: 1, borderColor: THEME.border, }, headerRightButtons: { flexDirection: "row", alignItems: "center", gap: 8, }, manualInputButton: { marginLeft: 4, }, demoBanner: { flexDirection: "row", alignItems: "center", gap: 6, marginHorizontal: 20, marginBottom: 8, paddingHorizontal: 12, paddingVertical: 6, backgroundColor: THEME.warningBg, borderRadius: 8, borderWidth: 1, borderColor: "#FDE68A", }, demoBannerText: { fontSize: 12, color: THEME.warning, fontWeight: "500", }, scrollView: { flex: 1, }, scrollContent: { paddingHorizontal: 20, paddingBottom: 32, gap: 14, }, centerFill: { flex: 1, alignItems: "center", justifyContent: "center", gap: 12, }, loadingText: { fontSize: 14, color: THEME.textSecondary, marginTop: 8, }, emptyTitle: { fontSize: 16, fontWeight: "600", color: THEME.textSecondary, textAlign: "center", }, emptySubtitle: { fontSize: 13, color: THEME.textMuted, textAlign: "center", paddingHorizontal: 32, }, sessionCard: { backgroundColor: THEME.bgCard, borderRadius: 16, padding: 16, borderWidth: 1, borderColor: THEME.border, gap: 12, shadowColor: THEME.shadow, shadowOffset: { width: 0, height: 2 }, shadowOpacity: 1, shadowRadius: 8, elevation: 2, }, sessionChip: { flexDirection: "row", alignItems: "center", alignSelf: "flex-start", paddingHorizontal: 10, paddingVertical: 4, borderRadius: 20, gap: 6, }, sessionChipDot: { width: 7, height: 7, borderRadius: 4, }, sessionChipText: { fontSize: 11, fontWeight: "700", letterSpacing: 0.3, }, sessionCardBody: { flexDirection: "row", alignItems: "center", }, sessionName: { fontSize: 16, fontWeight: "700", color: THEME.textPrimary, marginBottom: 4, }, sessionMeta: { fontSize: 12, color: THEME.textSecondary, marginBottom: 4, }, sessionDateRow: { flexDirection: "row", alignItems: "center", gap: 4, }, sessionDate: { fontSize: 12, color: THEME.textMuted, }, statsRow: { flexDirection: "row", gap: 8, }, statsPill: { paddingHorizontal: 10, paddingVertical: 5, borderRadius: 20, }, statsPillText: { fontSize: 12, fontWeight: "600", }, summaryBar: { flexDirection: "row", alignItems: "center", gap: 8, marginHorizontal: 20, marginBottom: 12, paddingHorizontal: 14, paddingVertical: 10, backgroundColor: THEME.bgCard, borderRadius: 12, borderWidth: 1, borderColor: THEME.border, }, summaryText: { fontSize: 13, color: THEME.textSecondary, }, progressTrack: { flex: 1, height: 4, backgroundColor: THEME.borderLight, borderRadius: 2, overflow: "hidden", }, progressFill: { height: 4, backgroundColor: THEME.success, borderRadius: 2, }, summaryPct: { fontSize: 12, color: THEME.success, fontWeight: "700", minWidth: 34, textAlign: "right", }, studentList: { flex: 1, }, studentListContent: { paddingHorizontal: 20, paddingBottom: 96, gap: 8, }, studentRow: { flexDirection: "row", alignItems: "center", backgroundColor: THEME.bgCard, borderRadius: 12, padding: 12, borderWidth: 1, borderColor: THEME.borderLight, gap: 12, }, avatarCircle: { width: 42, height: 42, borderRadius: 21, alignItems: "center", justifyContent: "center", borderWidth: 1, }, avatarInitials: { fontSize: 14, fontWeight: "700", }, studentInfo: { flex: 1, }, studentNim: { fontSize: 11, color: THEME.textMuted, marginBottom: 2, }, studentName: { fontSize: 14, fontWeight: "600", color: THEME.textPrimary, }, attendanceBadge: { paddingHorizontal: 10, paddingVertical: 4, borderRadius: 20, borderWidth: 1, }, attendanceBadgeText: { fontSize: 11, fontWeight: "600", }, bottomBar: { position: "absolute", bottom: 0, left: 0, right: 0, flexDirection: "row", alignItems: "center", paddingHorizontal: 20, paddingVertical: 14, paddingBottom: Platform.OS === "android" ? 14 : 28, backgroundColor: THEME.bg, borderTopWidth: 1, borderTopColor: THEME.border, gap: 12, }, scanButton: { flex: 1, borderRadius: 12, overflow: "hidden", }, scanButtonGradient: { flexDirection: "row", alignItems: "center", justifyContent: "center", gap: 8, paddingVertical: 14, borderRadius: 12, }, scanButtonText: { fontSize: 15, fontWeight: "700", color: "#fff", }, permissionContainer: { flex: 1, backgroundColor: THEME.bg, alignItems: "center", justifyContent: "center", padding: 24, }, permissionCard: { alignItems: "center", backgroundColor: THEME.bgCard, borderRadius: 24, padding: 32, borderWidth: 1, borderColor: THEME.border, width: "100%", shadowColor: THEME.shadow, shadowOffset: { width: 0, height: 4 }, shadowOpacity: 1, shadowRadius: 16, elevation: 4, }, permissionTitle: { fontSize: 22, fontWeight: "700", color: THEME.textPrimary, marginTop: 16, marginBottom: 10, textAlign: "center", }, permissionDesc: { fontSize: 14, color: THEME.textSecondary, textAlign: "center", lineHeight: 22, marginBottom: 28, }, permissionButton: { backgroundColor: THEME.primary, paddingHorizontal: 32, paddingVertical: 14, borderRadius: 12, }, permissionButtonText: { color: "#fff", fontSize: 16, fontWeight: "700", }, // Camera area — clipped to the oval shape cameraWrapper: { alignSelf: "center", width: CAMERA_SIZE, height: CAMERA_SIZE, marginTop: 4, position: "relative", borderRadius: 24, backgroundColor: "#FFFFFF", }, ovalClip: { position: "absolute", top: OVAL_TOP, left: OVAL_LEFT, width: OVAL_WIDTH, height: OVAL_HEIGHT, borderRadius: OVAL_WIDTH / 2, overflow: "hidden", backgroundColor: THEME.bgSecondary, }, cameraInner: { position: "absolute", top: -OVAL_TOP, left: -OVAL_LEFT, width: CAMERA_SIZE, height: CAMERA_SIZE, }, ovalRing: { position: "absolute", top: OVAL_TOP, left: OVAL_LEFT, width: OVAL_WIDTH, height: OVAL_HEIGHT, borderRadius: OVAL_WIDTH / 2, borderWidth: 3, borderColor: "#FFFFFF", zIndex: 10, }, scanLine: { position: "absolute", left: 0, right: 0, height: 2, backgroundColor: "rgba(37, 99, 235, 0.8)", shadowColor: THEME.primary, shadowOffset: { width: 0, height: 0 }, shadowOpacity: 1, shadowRadius: 8, elevation: 5, zIndex: 20, }, glowOverlay: { position: "absolute", top: (CAMERA_SIZE - OVAL_HEIGHT) / 2 - 6, left: (CAMERA_SIZE - OVAL_WIDTH) / 2 - 6, width: OVAL_WIDTH + 12, height: OVAL_HEIGHT + 12, borderRadius: (OVAL_WIDTH + 12) / 2, borderWidth: 3, zIndex: 5, }, freezeFrameOverlay: { position: "absolute", top: 12, right: 12, zIndex: 30, }, freezeFrameLabel: { flexDirection: "row", alignItems: "center", gap: 6, backgroundColor: "rgba(255, 255, 255, 0.95)", paddingHorizontal: 10, paddingVertical: 5, borderRadius: 20, borderWidth: 1, borderColor: THEME.border, }, freezeFrameLabelText: { fontSize: 11, color: THEME.primary, fontWeight: "600", }, statusWrapper: { alignItems: "center", marginTop: 18, paddingHorizontal: 24, }, statusBadge: { flexDirection: "row", alignItems: "center", paddingHorizontal: 20, paddingVertical: 10, borderRadius: 50, borderWidth: 1, gap: 8, }, statusDot: { width: 8, height: 8, borderRadius: 4, }, statusText: { fontSize: 14, fontWeight: "600", }, infoPanel: { marginHorizontal: 20, marginTop: 14, backgroundColor: THEME.bgCard, borderRadius: 16, padding: 14, borderWidth: 1, borderColor: THEME.border, gap: 10, }, infoPanelRow: { flexDirection: "row", alignItems: "center", gap: 8, }, infoPanelText: { fontSize: 13, color: THEME.textSecondary, flex: 1, lineHeight: 18, }, scanScrollView: { flex: 1, }, scanScrollContent: { paddingBottom: 140, }, captureSection: { position: "absolute", bottom: 0, left: 0, right: 0, alignItems: "center", paddingTop: 16, paddingBottom: Platform.OS === "android" ? 20 : 32, backgroundColor: THEME.bg, borderTopWidth: 1, borderTopColor: THEME.border, }, captureButton: { alignItems: "center", gap: 8, }, captureButtonDisabled: { opacity: 0.6, }, captureGradient: { width: 72, height: 72, borderRadius: 36, alignItems: "center", justifyContent: "center", shadowColor: THEME.primary, shadowOffset: { width: 0, height: 4 }, shadowOpacity: 0.3, shadowRadius: 12, elevation: 8, }, captureText: { fontSize: 13, fontWeight: "600", color: THEME.textPrimary, }, leafletMapContainer: { marginHorizontal: 16, marginBottom: 8, borderRadius: 12, overflow: "hidden", borderWidth: 1, borderColor: THEME.border, height: 200, backgroundColor: THEME.bgSecondary, }, locationStatus: { paddingHorizontal: 12, paddingVertical: 8, backgroundColor: THEME.bgCard, borderTopWidth: 1, borderTopColor: THEME.border, }, locationStatusText: { fontSize: 13, color: THEME.textSecondary, fontWeight: "500", }, locationFreeBanner: { marginHorizontal: 16, marginBottom: 8, paddingHorizontal: 12, paddingVertical: 8, backgroundColor: THEME.successBg, borderRadius: 8, borderWidth: 1, borderColor: "#A7F3D0", }, locationFreeText: { fontSize: 13, color: THEME.success, fontWeight: "500", }, scanButtonDisabled: { opacity: 0.6, }, outsideRadiusHint: { fontSize: 12, color: THEME.danger, fontWeight: "600", marginBottom: 8, textAlign: "center", }, mockGpsBanner: { flexDirection: "row" as const, alignItems: "center" as const, gap: 10, marginHorizontal: 16, marginBottom: 8, padding: 14, backgroundColor: "#DC2626", borderRadius: 12, }, mockGpsBannerTitle: { fontSize: 14, fontWeight: "700" as const, color: "#fff", }, mockGpsBannerDesc: { fontSize: 12, color: "rgba(255,255,255,0.85)", marginTop: 2, }, // ── Low-Light Banner Styles ─────────────────────────────────────────────── lowLightBanner: { flexDirection: "row" as const, alignItems: "center" as const, gap: 10, marginHorizontal: 16, marginBottom: 8, padding: 12, backgroundColor: "#FEF3C7", borderRadius: 12, borderWidth: 1, borderColor: "#FDE68A", }, lowLightBannerTitle: { fontSize: 13, fontWeight: "700" as const, color: "#92400E", marginBottom: 2, }, lowLightBannerDesc: { fontSize: 12, color: "#78350F", }, torchActiveBanner: { flexDirection: "row" as const, alignItems: "center" as const, gap: 8, marginHorizontal: 16, marginBottom: 6, paddingHorizontal: 12, paddingVertical: 7, backgroundColor: "#FFFBEB", borderRadius: 8, borderWidth: 1, borderColor: "#FDE68A", }, torchActiveBannerText: { fontSize: 12, color: "#92400E", fontWeight: "500" as const, }, torchQuickBtn: { flexDirection: "row" as const, alignItems: "center" as const, gap: 4, paddingHorizontal: 10, paddingVertical: 6, backgroundColor: "#FDE68A", borderRadius: 8, }, torchQuickBtnText: { fontSize: 12, fontWeight: "700" as const, color: "#92400E", }, });