package com.onthelevel.feature.tools

import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.onthelevel.core.design.LevelColors

@Composable
fun ToolsScreen(onOpenRuler: () -> Unit, onOpenSettings: () -> Unit) {
    Column(
        modifier = Modifier
            .fillMaxSize()
            .padding(24.dp),
        verticalArrangement = Arrangement.spacedBy(14.dp),
    ) {
        Text("TOOLS", style = MaterialTheme.typography.labelSmall, color = LevelColors.TextDim)

        ToolCard(
            title = "Screen Ruler",
            subtitle = "Rough on-screen measuring",
            badge = "PRO",
            onClick = onOpenRuler,
        )
        ToolCard(
            title = "Settings",
            subtitle = "Calibration, units, feedback, and motion",
            onClick = onOpenSettings,
        )
    }
}

@Composable
private fun ToolCard(
    title: String,
    subtitle: String,
    badge: String? = null,
    onClick: () -> Unit,
) {
    Surface(
        modifier = Modifier
            .fillMaxWidth()
            .clickable(onClick = onClick),
        color = LevelColors.Panel,
        contentColor = LevelColors.TextPrimary,
        shape = MaterialTheme.shapes.large,
    ) {
        Column(modifier = Modifier.padding(18.dp)) {
            Row(verticalAlignment = Alignment.CenterVertically) {
                Text(title, style = MaterialTheme.typography.headlineMedium)
                if (badge != null) {
                    Text(
                        text = "  $badge",
                        style = MaterialTheme.typography.labelSmall,
                        color = LevelColors.Amber,
                    )
                }
            }
            Text(
                text = subtitle,
                style = MaterialTheme.typography.labelSmall,
                color = LevelColors.TextDim,
                modifier = Modifier.padding(top = 6.dp),
            )
        }
    }
}
