import 'package:flutter/material.dart';

/// 应用主题配置 - 明亮工业控制风格
/// 主色 #2196F3，圆角 4px，明亮背景，适配 1920x1080 横屏
class AppTheme {
  // ========== 主色 ==========
  static const Color primaryColor = Color(0xFF2196F3);
  static const Color primaryDark = Color(0xFF1976D2);
  static const Color primaryLight = Color(0xFFBBDEFB);

  // ========== 功能色 ==========
  static const Color successColor = Color(0xFF4CAF50);
  static const Color warningColor = Color(0xFFFF9800);
  static const Color errorColor = Color(0xFFF44336);
  static const Color infoColor = Color(0xFF00BCD4);

  // ========== 背景色（明亮） ==========
  static const Color bgPage = Color(0xFFF5F7FA);
  static const Color bgDeep = Color(0xFFE8ECF0);
  static const Color bgSurface = Color(0xFFFFFFFF);
  static const Color bgCard = Color(0xFFFFFFFF);
  static const Color bgCardHover = Color(0xFFF0F7FF);
  static const Color bgSidebar = Color(0xFFF0F2F5);

  // ========== 文本色 ==========
  static const Color textHeading = Color(0xFF1A1A2E);
  static const Color textPrimary = Color(0xFF333344);
  static const Color textSecondary = Color(0xFF6B7280);
  static const Color textTertiary = Color(0xFF9CA3AF);
  static const Color textOnPrimary = Colors.white;

  // ========== 状态色 ==========
  static const Color statusRunning = Color(0xFF4CAF50);
  static const Color statusStopped = Color(0xFF9CA3AF);
  static const Color statusPaused = Color(0xFFFF9800);
  static const Color statusError = Color(0xFFF44336);

  // ========== 卡片背景 ==========
  static const Color cardBg = Color(0xFFFFFFFF);
  static const Color cardSelectedBg = Color(0xFFE3F2FD);

  // ========== 功能色（accent） ==========
  static const Color accentPrimary = primaryColor;
  static const Color accentInfo = infoColor;
  static const Color accentWarning = warningColor;
  static const Color accentCritical = errorColor;

  // ========== 边框色 ==========
  static const Color borderLight = Color(0xFFE5E7EB);
  static const Color borderMedium = Color(0xFFD1D5DB);
  static const Color borderSubtle = borderLight;
  static const Color borderFocus = primaryColor;

  // ========== 圆角 ==========
  static const double radiusSm = 4.0;
  static const double radiusMd = 8.0;
  static const double radiusLg = 12.0;

  // ========== 阴影 ==========
  static const List<BoxShadow> shadowCard = [
    BoxShadow(
      color: Color(0x0A000000),
      blurRadius: 8,
      offset: Offset(0, 2),
    ),
  ];

  static const List<BoxShadow> shadowCardHover = [
    BoxShadow(
      color: Color(0x14000000),
      blurRadius: 12,
      offset: Offset(0, 4),
    ),
  ];

  // ========== 兼容旧代码的颜色别名 ==========
  static const Color runningColor = statusRunning;
  static const Color idleColor = statusStopped;
  static const Color backgroundColor = bgPage;
  static const Color cardColor = bgCard;

  /// 亮色主题 - 明亮工业风格
  static ThemeData lightTheme() {
    return ThemeData(
      useMaterial3: true,
      colorScheme: ColorScheme.fromSeed(
        seedColor: primaryColor,
        brightness: Brightness.light,
      ),
      scaffoldBackgroundColor: bgPage,
      fontFamily: 'Inter',
      cardTheme: CardThemeData(
        color: bgCard,
        elevation: 0,
        shape: RoundedRectangleBorder(
          borderRadius: BorderRadius.circular(radiusMd),
          side: const BorderSide(color: borderLight, width: 1),
        ),
        margin: EdgeInsets.zero,
      ),
      appBarTheme: const AppBarTheme(
        backgroundColor: bgSurface,
        foregroundColor: textHeading,
        elevation: 0,
        centerTitle: false,
        scrolledUnderElevation: 1,
      ),
      elevatedButtonTheme: ElevatedButtonThemeData(
        style: ElevatedButton.styleFrom(
          backgroundColor: primaryColor,
          foregroundColor: textOnPrimary,
          padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 12),
          elevation: 0,
          shape: RoundedRectangleBorder(
            borderRadius: BorderRadius.circular(radiusSm),
          ),
        ),
      ),
      inputDecorationTheme: InputDecorationTheme(
        border: OutlineInputBorder(
          borderRadius: BorderRadius.circular(radiusSm),
          borderSide: const BorderSide(color: borderMedium),
        ),
        enabledBorder: OutlineInputBorder(
          borderRadius: BorderRadius.circular(radiusSm),
          borderSide: const BorderSide(color: borderMedium),
        ),
        focusedBorder: OutlineInputBorder(
          borderRadius: BorderRadius.circular(radiusSm),
          borderSide: const BorderSide(color: primaryColor, width: 2),
        ),
        filled: true,
        fillColor: bgSurface,
        contentPadding: const EdgeInsets.symmetric(horizontal: 12, vertical: 12),
      ),
      dialogTheme: DialogThemeData(
        backgroundColor: bgSurface,
        elevation: 4,
        shape: RoundedRectangleBorder(
          borderRadius: BorderRadius.circular(radiusMd),
        ),
      ),
      snackBarTheme: SnackBarThemeData(
        backgroundColor: textHeading,
        contentTextStyle: const TextStyle(color: Colors.white, fontSize: 14),
        shape: RoundedRectangleBorder(
          borderRadius: BorderRadius.circular(radiusSm),
        ),
        behavior: SnackBarBehavior.floating,
      ),
      listTileTheme: const ListTileThemeData(
        contentPadding: EdgeInsets.symmetric(horizontal: 16, vertical: 4),
        shape: RoundedRectangleBorder(
          borderRadius: BorderRadius.all(Radius.circular(radiusSm)),
        ),
      ),
      dataTableTheme: DataTableThemeData(
        headingRowColor: WidgetStateProperty.all(bgSidebar),
        dividerThickness: 1,
      ),
      dividerTheme: const DividerThemeData(
        color: borderLight,
        thickness: 1,
      ),
    );
  }

  /// 暗色主题（与亮色主题风格一致的暗色模式）
  static ThemeData darkTheme() {
    return ThemeData(
      useMaterial3: true,
      colorScheme: ColorScheme.fromSeed(
        seedColor: primaryColor,
        brightness: Brightness.dark,
      ),
      scaffoldBackgroundColor: const Color(0xFF121212),
    );
  }
}
