untitled

Pasted Nov 11, 2026, 7:03 PM1 file154 lines

Scan to open on your phone

Point a camera at the QR code - it opens this exact paste, no app needed.

https://codepastes.com/zzgs7cj2txgqb795
untitled
package com.negocio.desinfectantes.ui.productos

import androidx.compose.foundation.layout.*
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ArrowBack
import androidx.compose.material.icons.filled.Inventory2
import androidx.compose.material3.*
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.ui.unit.dp

private val CardBlueForm = Color(0xFF1B2D4A)
private val AccentBlueForm = Color(0xFF2585F5)
private val SoftBlueForm = Color(0xFFA9BEDB)

@Composable
fun AgregarPresentacionScreen(
    nombreProducto: String,
    nombreAroma: String,
    onVolver: () -> Unit,
    onGuardar: (String, Int, Double) -> Unit
) {
    var nombre by remember { mutableStateOf("") }
    var contenido by remember { mutableStateOf("") }
    var precio by remember { mutableStateOf("") }

    val contenidoValido = contenido.toIntOrNull()?.let { it > 0 } == true
    val precioValido = precio.replace(",", ".").toDoubleOrNull()?.let { it >= 0 } == true

    Column(
        modifier = Modifier
            .fillMaxSize()
            .verticalScroll(rememberScrollState())
            .padding(20.dp)
    ) {
        Row(verticalAlignment = Alignment.CenterVertically) {
            IconButton(onClick = onVolver) {
                Icon(
                    Icons.Default.ArrowBack,
                    contentDescription = "Volver",
                    tint = SoftBlueForm
                )
            }

            Text(
                "Nueva presentación",
                color = Color.White,
                style = MaterialTheme.typography.headlineSmall
            )
        }

        Spacer(Modifier.height(12.dp))

        Text(
            "$nombreProducto · $nombreAroma",
            color = SoftBlueForm,
            style = MaterialTheme.typography.bodyMedium
        )

        Spacer(Modifier.height(24.dp))

        Card(
            modifier = Modifier.fillMaxWidth(),
            shape = RoundedCornerShape(18.dp),
            colors = CardDefaults.cardColors(containerColor = CardBlueForm)
        ) {
            Column(modifier = Modifier.padding(20.dp)) {
                Icon(
                    Icons.Default.Inventory2,
                    contentDescription = null,
                    tint = AccentBlueForm,
                    modifier = Modifier.size(32.dp)
                )

                Spacer(Modifier.height(12.dp))

                Text(
                    "Información de la presentación",
                    color = Color.White,
                    style = MaterialTheme.typography.titleMedium
                )

                Spacer(Modifier.height(20.dp))

                OutlinedTextField(
                    value = nombre,
                    onValueChange = { nombre = it },
                    modifier = Modifier.fillMaxWidth(),
                    label = { Text("Nombre") },
                    placeholder = { Text("Ej. Galón") },
                    singleLine = true,
                    shape = RoundedCornerShape(12.dp)
                )

                Spacer(Modifier.height(14.dp))

                OutlinedTextField(
                    value = contenido,
                    onValueChange = { contenido = it.filter { c -> c.isDigit() } },
                    modifier = Modifier.fillMaxWidth(),
                    label = { Text("Contenido en mililitros") },
                    placeholder = { Text("Ej. 3785") },
                    singleLine = true,
                    keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Number),
                    shape = RoundedCornerShape(12.dp)
                )

                Spacer(Modifier.height(14.dp))

                OutlinedTextField(
                    value = precio,
                    onValueChange = {
                        precio = it.filter { c -> c.isDigit() || c == '.' || c == ',' }
                    },
                    modifier = Modifier.fillMaxWidth(),
                    label = { Text("Precio de venta") },
                    placeholder = { Text("Ej. 18000") },
                    singleLine = true,
                    keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Decimal),
                    shape = RoundedCornerShape(12.dp)
                )
            }
        }

        Spacer(Modifier.height(24.dp))

        Button(
            onClick = {
                val precioNumerico = precio.replace(",", ".").toDoubleOrNull()

                if (nombre.isNotBlank() && contenidoValido && precioNumerico != null) {
                    onGuardar(nombre.trim(), contenido.toInt(), precioNumerico)
                }
            },
            enabled = nombre.isNotBlank() && contenidoValido && precioValido,
            modifier = Modifier
                .fillMaxWidth()
                .height(54.dp),
            shape = RoundedCornerShape(14.dp),
            colors = ButtonDefaults.buttonColors(containerColor = AccentBlueForm)
        ) {
            Text("Guardar presentación")
        }
    }
}

5,411 chars · codepastes.com