// Version: 1.0.0 | Created: 2026-04-01
// M8Chat brand theme — dark and light variants.
// Primary brand colour: #5C35C9 (deep purple). Accent: #7B5CF6.

import 'package:flutter/material.dart';

/// M8Chat brand colours.
abstract final class M8Colours {
  static const Color brandPurple = Color(0xFF5C35C9);
  static const Color accentPurple = Color(0xFF7B5CF6);
  static const Color darkBackground = Color(0xFF0F0F1A);
  static const Color darkSurface = Color(0xFF1A1A2E);
  static const Color darkSurfaceVariant = Color(0xFF22223A);
  static const Color onDarkSurface = Color(0xFFE8E8F0);
  static const Color subtleText = Color(0xFF9898B0);
  static const Color errorRed = Color(0xFFCF6679);
  static const Color unreadGreen = Color(0xFF4CAF50);
}

/// Dark theme — default for M8Chat.
ThemeData buildDarkTheme() {
  const seed = M8Colours.brandPurple;

  final scheme =
      ColorScheme.fromSeed(
        seedColor: seed,
        brightness: Brightness.dark,
      ).copyWith(
        surface: M8Colours.darkBackground,
        surfaceContainerHighest: M8Colours.darkSurface,
        primary: M8Colours.accentPurple,
        onSurface: M8Colours.onDarkSurface,
        error: M8Colours.errorRed,
      );

  return ThemeData(
    useMaterial3: true,
    colorScheme: scheme,
    scaffoldBackgroundColor: M8Colours.darkBackground,
    appBarTheme: AppBarTheme(
      backgroundColor: M8Colours.darkSurface,
      foregroundColor: M8Colours.onDarkSurface,
      elevation: 0,
      surfaceTintColor: Colors.transparent,
    ),
    navigationBarTheme: NavigationBarThemeData(
      backgroundColor: M8Colours.darkSurface,
      indicatorColor: M8Colours.accentPurple.withAlpha(51),
      labelTextStyle: WidgetStateProperty.all(
        const TextStyle(fontSize: 12, color: M8Colours.onDarkSurface),
      ),
    ),
    inputDecorationTheme: InputDecorationTheme(
      filled: true,
      fillColor: M8Colours.darkSurfaceVariant,
      border: OutlineInputBorder(
        borderRadius: BorderRadius.circular(12),
        borderSide: BorderSide.none,
      ),
      focusedBorder: OutlineInputBorder(
        borderRadius: BorderRadius.circular(12),
        borderSide: const BorderSide(color: M8Colours.accentPurple, width: 2),
      ),
      labelStyle: const TextStyle(color: M8Colours.subtleText),
      hintStyle: const TextStyle(color: M8Colours.subtleText),
    ),
    elevatedButtonTheme: ElevatedButtonThemeData(
      style: ElevatedButton.styleFrom(
        backgroundColor: M8Colours.accentPurple,
        foregroundColor: Colors.white,
        minimumSize: const Size.fromHeight(52),
        shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
        textStyle: const TextStyle(
          fontSize: 16,
          fontWeight: FontWeight.w600,
          letterSpacing: 0.5,
        ),
      ),
    ),
    cardTheme: CardThemeData(
      color: M8Colours.darkSurface,
      elevation: 0,
      shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
    ),
    dividerTheme: const DividerThemeData(
      color: M8Colours.darkSurfaceVariant,
      thickness: 1,
    ),
    snackBarTheme: SnackBarThemeData(
      backgroundColor: M8Colours.darkSurfaceVariant,
      contentTextStyle: const TextStyle(color: M8Colours.onDarkSurface),
      shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8)),
      behavior: SnackBarBehavior.floating,
    ),
  );
}

/// Light theme — follows system preference if user selects it.
ThemeData buildLightTheme() {
  const seed = M8Colours.brandPurple;

  final scheme = ColorScheme.fromSeed(
    seedColor: seed,
    brightness: Brightness.light,
  );

  return ThemeData(
    useMaterial3: true,
    colorScheme: scheme,
    elevatedButtonTheme: ElevatedButtonThemeData(
      style: ElevatedButton.styleFrom(
        minimumSize: const Size.fromHeight(52),
        shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
        textStyle: const TextStyle(
          fontSize: 16,
          fontWeight: FontWeight.w600,
          letterSpacing: 0.5,
        ),
      ),
    ),
    inputDecorationTheme: InputDecorationTheme(
      filled: true,
      border: OutlineInputBorder(
        borderRadius: BorderRadius.circular(12),
        borderSide: BorderSide.none,
      ),
      focusedBorder: OutlineInputBorder(
        borderRadius: BorderRadius.circular(12),
        borderSide: BorderSide(color: scheme.primary, width: 2),
      ),
    ),
    snackBarTheme: SnackBarThemeData(
      shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8)),
      behavior: SnackBarBehavior.floating,
    ),
  );
}
