import 'package:flutter/material.dart'; import '../l10n/gen/app_localizations.dart'; import '../modelos/preset_ecualizador.dart'; import '../tema/pluriwave_theme.dart'; import 'pluri_glass_surface.dart'; class EcualizadorWidget extends StatefulWidget { final PresetEcualizador preset; final void Function(PresetEcualizador) onCambio; const EcualizadorWidget({super.key, required this.preset, required this.onCambio}); @override State createState() => _EcualizadorWidgetState(); } class _EcualizadorWidgetState extends State { late List _bandas; final List _etiquetas = ['60Hz', '250Hz', '1kHz', '4kHz', '16kHz']; @override void initState() { super.initState(); _bandas = List.from(widget.preset.bandas); } @override void didUpdateWidget(EcualizadorWidget old) { super.didUpdateWidget(old); if (old.preset.nombre != widget.preset.nombre) { setState(() => _bandas = List.from(widget.preset.bandas)); } } void _actualizarBanda(int index, double valor) { setState(() => _bandas[index] = valor); widget.onCambio(PresetEcualizador(nombre: 'Personalizado', bandas: List.from(_bandas))); } @override Widget build(BuildContext context) { final theme = Theme.of(context); final tokens = context.pluriTokens; final l10n = AppLocalizations.of(context); return PluriGlassSurface( borderRadius: BorderRadius.circular(tokens.radiusLg), padding: const EdgeInsets.all(16), child: Column( crossAxisAlignment: CrossAxisAlignment.stretch, children: [ Row( children: [ Text(l10n.equalizerTitle, style: theme.textTheme.titleMedium?.copyWith(fontWeight: FontWeight.w700)), const Spacer(), Chip( label: Text(_nombrePreset(l10n, widget.preset.nombre), style: theme.textTheme.labelMedium), backgroundColor: theme.colorScheme.secondaryContainer.withValues(alpha: 0.75), ), ], ), const SizedBox(height: 14), Row( crossAxisAlignment: CrossAxisAlignment.end, mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ for (int i = 0; i < 5; i++) Expanded( child: Card( color: theme.colorScheme.surfaceContainerHighest.withValues(alpha: 0.35), margin: const EdgeInsets.symmetric(horizontal: 4), shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(14)), child: Padding( padding: const EdgeInsets.symmetric(vertical: 8, horizontal: 4), child: Column( children: [ SizedBox( height: 152, child: Semantics( slider: true, label: l10n.equalizerBandLabel(_etiquetas[i]), value: l10n.equalizerBandValue(_bandas[i].toStringAsFixed(1)), child: RotatedBox( quarterTurns: 3, child: Slider( value: _bandas[i], min: -12.0, max: 12.0, divisions: 24, onChanged: (v) => _actualizarBanda(i, v), ), ), ), ), Text('${_bandas[i].toStringAsFixed(1)}dB', style: theme.textTheme.labelSmall), Text( _etiquetas[i], style: theme.textTheme.bodySmall?.copyWith(color: theme.colorScheme.onSurfaceVariant), textAlign: TextAlign.center, ), ], ), ), ), ), ], ), ], ), ); } } String _nombrePreset(AppLocalizations l10n, String nombre) { return switch (nombre) { 'Flat' => l10n.equalizerPresetFlat, 'Rock' => l10n.equalizerPresetRock, 'Pop' => l10n.equalizerPresetPop, 'Bass Boost' => l10n.equalizerPresetBassBoost, 'Jazz' => l10n.equalizerPresetJazz, 'Voz' => l10n.equalizerPresetVoice, 'Personalizado' => l10n.equalizerPresetCustom, _ => nombre, }; } class PresetsEcualizadorWidget extends StatelessWidget { final PresetEcualizador presetActual; final void Function(PresetEcualizador) onSeleccionar; const PresetsEcualizadorWidget({ super.key, required this.presetActual, required this.onSeleccionar, }); @override Widget build(BuildContext context) { final theme = Theme.of(context); final l10n = AppLocalizations.of(context); return Wrap( spacing: 8, runSpacing: 6, children: PresetEcualizador.presets.map((p) { final selected = p.nombre == presetActual.nombre; return ChoiceChip( label: Text(_nombrePreset(l10n, p.nombre)), selected: selected, showCheckmark: false, selectedColor: theme.colorScheme.primaryContainer, backgroundColor: theme.colorScheme.surfaceContainerHighest.withValues(alpha: 0.32), onSelected: (_) => onSeleccionar(p), ); }).toList(), ); } }