package com.optix.android.ui.screens.disclaimer

import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.*
import androidx.compose.runtime.*
import androidx.compose.ui.*
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import com.optix.android.ui.theme.*

@Composable
fun DisclaimerScreen(onAccept: () -> Unit) {
    Box(
        modifier = Modifier
            .fillMaxSize()
            .background(T.background),
        contentAlignment = Alignment.Center,
    ) {
        Column(
            modifier = Modifier
                .fillMaxWidth(0.92f)
                .border(1.dp, T.accent.copy(alpha = 0.5f), RoundedCornerShape(12.dp))
                .background(
                    Brush.verticalGradient(listOf(T.surface, T.background)),
                    RoundedCornerShape(12.dp),
                )
                .padding(24.dp),
            horizontalAlignment = Alignment.CenterHorizontally,
            verticalArrangement = Arrangement.spacedBy(16.dp),
        ) {
            Text("⚠  LEGAL DISCLAIMER", color = T.accent, style = MaterialTheme.typography.titleMedium,
                fontWeight = FontWeight.Bold, textAlign = TextAlign.Center)

            HorizontalDivider(color = T.accent.copy(alpha = 0.3f))

            Column(
                modifier = Modifier.verticalScroll(rememberScrollState()).heightIn(max = 380.dp),
                verticalArrangement = Arrangement.spacedBy(12.dp),
            ) {
                DisclaimerSection("Authorized Use Only",
                    "This application is intended exclusively for use on networks and devices you own or have explicit written authorization to test. Unauthorized scanning, probing, or exploitation of networks or systems is illegal and may result in criminal prosecution under the Computer Fraud and Abuse Act (CFAA), the Computer Misuse Act, and equivalent laws worldwide.")

                DisclaimerSection("Requirements",
                    "• Rooted Android device — many tools require root access to function.\n• Termux installed (from F-Droid) — shell-based tools (Nmap, Hydra, Metasploit, etc.) execute via Termux. Without it, these tools will not run.\n• Active network connection — most scanning tools require WiFi or mobile data.")

                DisclaimerSection("No Liability",
                    "The developers of Optix accept no responsibility for misuse, damage, or legal consequences arising from the use of this application. You are solely responsible for ensuring your use complies with all applicable laws and regulations.")

                DisclaimerSection("Ethical Use",
                    "Use this tool responsibly. Only test systems you own or have written permission to test. Respect privacy. Do not use against critical infrastructure, healthcare systems, or any system where disruption could cause harm.")
            }

            HorizontalDivider(color = T.accent.copy(alpha = 0.3f))

            Text(
                "By tapping ACCEPT, you confirm you understand and agree to these terms.",
                color = T.onSurfaceMid,
                style = MaterialTheme.typography.bodySmall,
                textAlign = TextAlign.Center,
            )

            Button(
                onClick = onAccept,
                modifier = Modifier.fillMaxWidth(),
                colors = ButtonDefaults.buttonColors(
                    containerColor = T.accent,
                    contentColor = if (T.isDark) Color.Black else Color.White
                ),
                shape = RoundedCornerShape(6.dp),
            ) {
                Text("I UNDERSTAND — ACCEPT & CONTINUE", fontWeight = FontWeight.Bold)
            }
        }
    }
}

@Composable
private fun DisclaimerSection(title: String, body: String) {
    Column(verticalArrangement = Arrangement.spacedBy(4.dp)) {
        Text(title, color = T.accentGlow, style = MaterialTheme.typography.labelMedium, fontWeight = FontWeight.SemiBold)
        Text(body, color = T.onSurface, style = MaterialTheme.typography.bodySmall)
    }
}
