import 'package:flutter/material.dart';

/// Seed color option for theme customization
class SeedColorOption {
  const SeedColorOption({
    required this.id,
    required this.name,
    required this.color,
  });

  final String id;
  final String name;
  final Color color;
}

/// App color palette following the Worker app design system.
///
/// Uses Material 3 ColorScheme.fromSeed() for primary/surface colors.
/// Only status colors and tier gradients are defined here as they come from backend.
///
/// ## Usage Guide:
/// - For themed colors, use `Theme.of(context).colorScheme.xxx`
/// - For status colors, use `AppColors.success/warning/danger/info`
/// - For tier gradients, use `AppColors.xxxGradient`
///
/// ## ColorScheme Quick Reference:
/// ```dart
/// final cs = Theme.of(context).colorScheme;
/// cs.primary          // Brand color for buttons, links
/// cs.onPrimary        // Text/icons on primary
/// cs.primaryContainer // Softer brand backgrounds
/// cs.surface          // Card/container backgrounds
/// cs.onSurface        // Primary text color
/// cs.onSurfaceVariant // Secondary text color
/// cs.outline          // Borders
/// cs.error            // Error states
/// ```
class AppColors {
  AppColors._();

  // ==================== Brand Seed Colors ====================
  /// Default brand color - Used as seed for ColorScheme.fromSeed()
  static const Color defaultSeedColor = Color(0xFF005B9A);

  /// Available seed colors for theme customization
  /// User can select one of these to change the app's color scheme
  static const List<SeedColorOption> seedColorOptions = [
    SeedColorOption(
      id: 'blue',
      name: 'Xanh dương',
      color: Color(0xFF005B9A),
    ),
    SeedColorOption(
      id: 'teal',
      name: 'Xanh ngọc',
      color: Color(0xFF009688),
    ),
    SeedColorOption(
      id: 'green',
      name: 'Xanh lá',
      color: Color(0xFF4CAF50),
    ),
    SeedColorOption(
      id: 'purple',
      name: 'Tím',
      color: Color(0xFF673AB7),
    ),
    SeedColorOption(
      id: 'indigo',
      name: 'Chàm',
      color: Color(0xFF3F51B5),
    ),
    SeedColorOption(
      id: 'orange',
      name: 'Cam',
      color: Color(0xFFFF5722),
    ),
    SeedColorOption(
      id: 'red',
      name: 'Đỏ',
      color: Color(0xFFE53935),
    ),
    SeedColorOption(
      id: 'pink',
      name: 'Hồng',
      color: Color(0xFFE91E63),
    ),
  ];

  /// Get seed color by ID, returns default if not found
  static Color getSeedColorById(String? id) {
    if (id == null) return defaultSeedColor;
    return seedColorOptions
        .firstWhere(
          (option) => option.id == id,
          orElse: () => seedColorOptions.first,
        )
        .color;
  }

  // ==================== Convenience Aliases (for backward compatibility) ====================
  // DEPRECATED: Prefer using Theme.of(context).colorScheme instead
  // These are kept for gradual migration

  /// @Deprecated('Use Theme.of(context).colorScheme.primary instead')
  static const Color primaryBlue = defaultSeedColor;

  /// Alias for backward compatibility
  static const Color seedColor = defaultSeedColor;

  /// @Deprecated('Use Theme.of(context).colorScheme.primaryContainer')
  static const Color lightBlue = Color(0xFF38B6FF);

  /// @Deprecated('Use Theme.of(context).colorScheme.tertiary')
  static const Color accentCyan = Color(0xFF35C6F4);

  /// @Deprecated('Use Colors.white or colorScheme.surface instead')
  static const Color white = Colors.white;

  /// @Deprecated('Use Theme.of(context).colorScheme.surfaceContainerLowest')
  static const Color grey50 = Color(0xFFf8f9fa);

  /// @Deprecated('Use Theme.of(context).colorScheme.outline')
  static const Color grey100 = Color(0xFFe9ecef);

  /// @Deprecated('Use Theme.of(context).colorScheme.onSurfaceVariant')
  static const Color grey500 = Color(0xFF6c757d);

  /// @Deprecated('Use Theme.of(context).colorScheme.onSurface')
  static const Color grey900 = Color(0xFF343a40);

  // ==================== Status Colors (from backend) ====================
  /// Success state - Used for completed actions, positive feedback
  static const Color success = Color(0xFF28a745);

  /// Warning state - Used for caution messages, pending states
  static const Color warning = Color(0xFFffc107);

  /// Danger/Error state - Used for errors, destructive actions
  static const Color danger = Color(0xFFdc3545);

  /// Info state - Used for informational messages
  static const Color info = Color(0xFF17a2b8);

  // ==================== Tier Gradients for Membership Cards ====================
  /// Diamond tier gradient (purple-blue)
  static const LinearGradient diamondGradient = LinearGradient(
    colors: [Color(0xFF4A00E0), Color(0xFF8E2DE2)],
    begin: Alignment.topLeft,
    end: Alignment.bottomRight,
  );

  /// Platinum tier gradient (grey-silver)
  static const LinearGradient platinumGradient = LinearGradient(
    colors: [Color(0xFF7F8C8D), Color(0xFFBDC3C7)],
    begin: Alignment.topLeft,
    end: Alignment.bottomRight,
  );

  /// Gold tier gradient (yellow-orange)
  static const LinearGradient goldGradient = LinearGradient(
    colors: [Color(0xFFf7b733), Color(0xFFfc4a1a)],
    begin: Alignment.topLeft,
    end: Alignment.bottomRight,
  );
}
