import 'package:flutter/material.dart';

/// App-wide light/dark theme. The MPOB ripeness palette
/// (lib/constants/mpob_colors.dart) and the live-scan camera overlay
/// colors are intentionally NOT sourced from here — those are fixed
/// semantic/functional colors, not brand chrome.
class AppTheme {
  AppTheme._();

  // Teal-green brand family.
  static const _primaryLight = Color(0xFF0F6E56);
  static const _primaryDark = Color(0xFF5DCAA5);
  static const _primaryContainerLight = Color(0xFF9FE1CB);
  static const _primaryContainerDark = Color(0xFF085041);

  // Amber accent family.
  static const _secondaryLight = Color(0xFFBA7517);
  static const _secondaryDark = Color(0xFFFAC775);
  static const _secondaryContainerLight = Color(0xFFFAEEDA);
  static const _secondaryContainerDark = Color(0xFF633806);

  // Surfaces.
  static const _surfaceLight = Color(0xFFFAEEDA);
  static const _surfaceDark = Color(0xFF101913);
  static const _surfaceContainerLight = Color(0xFFFFFFFF);
  static const _surfaceContainerDark = Color(0xFF1B241D);

  static const List<Color> chartAccents = [
    Color(0xFF378ADD), // blue
    Color(0xFF1D9E75), // teal
    Color(0xFFEF9F27), // amber
    Color(0xFF7F77DD), // purple
    Color(0xFF888780), // neutral
  ];

  static ThemeData get light {
    final colorScheme = ColorScheme.light(
      primary: _primaryLight,
      onPrimary: Colors.white,
      primaryContainer: _primaryContainerLight,
      onPrimaryContainer: const Color(0xFF04342C),
      secondary: _secondaryLight,
      onSecondary: Colors.white,
      secondaryContainer: _secondaryContainerLight,
      onSecondaryContainer: const Color(0xFF412402),
      surface: _surfaceLight,
      onSurface: const Color(0xFF04342C),
      surfaceContainerHighest: _surfaceContainerLight,
      error: const Color(0xFFE24B4A),
      onError: Colors.white,
    );
    return _themeFrom(colorScheme);
  }

  static ThemeData get dark {
    final colorScheme = ColorScheme.dark(
      primary: _primaryDark,
      onPrimary: const Color(0xFF04342C),
      primaryContainer: _primaryContainerDark,
      onPrimaryContainer: const Color(0xFFE1F5EE),
      secondary: _secondaryDark,
      onSecondary: const Color(0xFF412402),
      secondaryContainer: _secondaryContainerDark,
      onSecondaryContainer: const Color(0xFFFAEEDA),
      surface: _surfaceDark,
      onSurface: const Color(0xFFE1F5EE),
      surfaceContainerHighest: _surfaceContainerDark,
      error: const Color(0xFFF09595),
      onError: const Color(0xFF501313),
    );
    return _themeFrom(colorScheme);
  }

  static ThemeData _themeFrom(ColorScheme colorScheme) {
    return ThemeData(
      useMaterial3: true,
      colorScheme: colorScheme,
      scaffoldBackgroundColor: colorScheme.surface,
      appBarTheme: AppBarTheme(
        backgroundColor: colorScheme.primary,
        foregroundColor: colorScheme.onPrimary,
        elevation: 2,
      ),
      cardTheme: CardThemeData(
        color: colorScheme.surfaceContainerHighest,
        elevation: 3,
        shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(15)),
      ),
    );
  }
}
