// SPDX-FileCopyrightText: © 2025 Nøkken.io <nokken.io@proton.me>
// SPDX-License-Identifier: AGPL-3.0
//
//  mood_field_chips.dart
//
import 'package:flutter/material.dart';
import 'package:nokken/src/features/mood_tracker/utils/mood_utils.dart';
import 'package:nokken/src/features/mood_tracker/models/mood_entry.dart';
import 'package:nokken/src/core/ui/theme/app_theme.dart';
import 'package:nokken/src/core/ui/theme/app_text_styles.dart';

class MoodFieldChips {
  // Helper method to build a consistent field chip
  static Widget buildFieldChip(
      MoodRating mood, String emoji, String text, Color color) {
    return Container(
      padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 2),
      decoration: BoxDecoration(
        color: color.withAlpha(40),
        borderRadius: BorderRadius.circular(12),
      ),
      child: Text(
        '$emoji\u202F$text',
        style: AppTextStyles.bodySmall.copyWith(
          color: MoodUtils.getMoodColor(mood),
          fontFamily: AppTheme.emojiStyle,
        ),
      ),
    );
  }

  // Helper method to build field chips
  static List<Widget> buildMoodFieldChips(MoodEntry entry) {
    List<Widget> chips = [];

    // Add emotions if present
    if (entry.emotions.isNotEmpty) {
      for (var e in entry.emotions) {
        chips.add(
          Container(
            padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 2),
            decoration: BoxDecoration(
              color: MoodUtils.getEmotionColor(e).withAlpha(40),
              borderRadius: BorderRadius.circular(12),
            ),
            child: Text(
              '${e.emoji}\u202F${e.displayName}',
              style: AppTextStyles.bodySmall.copyWith(
                color: MoodUtils.getMoodColor(entry.mood),
                fontFamily: AppTheme.emojiStyle,
              ),
            ),
          ),
        );
      }
    }

    // Add sleep quality if present
    if (entry.sleepQuality != null) {
      chips.add(buildFieldChip(
        entry.mood,
        entry.sleepQuality!.emoji,
        '${entry.sleepQuality!.displayName}\u202Fsleep',
        MoodUtils.getSleepQualityColor(entry.sleepQuality!),
      ));
    }

    // Add energy level if present
    if (entry.energyLevel != null) {
      chips.add(buildFieldChip(
        entry.mood,
        entry.energyLevel!.emoji,
        '${entry.energyLevel!.displayName}\u202Fenergy',
        MoodUtils.getEnergyLevelColor(entry.energyLevel!),
      ));
    }

    // Add libido level if present
    if (entry.libidoLevel != null) {
      chips.add(buildFieldChip(
        entry.mood,
        entry.libidoLevel!.emoji,
        '${entry.libidoLevel!.displayName}\u202Flibido',
        MoodUtils.getLibidoLevelColor(entry.libidoLevel!),
      ));
    }

    // Add appetite level if present
    if (entry.appetiteLevel != null) {
      chips.add(buildFieldChip(
        entry.mood,
        entry.appetiteLevel!.emoji,
        '${entry.appetiteLevel!.displayName}\u202Fappetite',
        MoodUtils.getAppetiteLevelColor(entry.appetiteLevel!),
      ));
    }

    // Add focus level if present
    if (entry.focusLevel != null) {
      chips.add(buildFieldChip(
        entry.mood,
        entry.focusLevel!.emoji,
        '${entry.focusLevel!.displayName}\u202Ffocus',
        MoodUtils.getFocusLevelColor(entry.focusLevel!),
      ));
    }

    // Add dysphoria level if present
    if (entry.dysphoriaLevel != null) {
      chips.add(buildFieldChip(
        entry.mood,
        entry.dysphoriaLevel!.emoji,
        '${entry.dysphoriaLevel!.displayName}\u202Fdysphoria',
        MoodUtils.getDysphoriaLevelColor(entry.dysphoriaLevel!),
      ));
    }

    // Add exercise level if present
    if (entry.exerciseLevel != null) {
      chips.add(buildFieldChip(
        entry.mood,
        entry.exerciseLevel!.emoji,
        '${entry.exerciseLevel!.displayName}\u202Fexercise',
        MoodUtils.getExerciseLevelColor(entry.exerciseLevel!),
      ));
    }

    return chips;
  }
}
