import 'package:daily_challenge/data/db/entities/entities.dart';
import 'package:daily_challenge/mgr/daily_challenge_manager.dart';
import 'package:flutter/material.dart';
import 'package:guru_utils/datetime/datetime_utils.dart';
import 'package:guru_utils/controller/lifecycle_controller.dart';
import 'package:rxdart/rxdart.dart';
import 'package:guru_utils/extensions/extensions.dart';
import 'package:guru_utils/log/log.dart';
import 'package:get/get.dart' hide Rx;
import 'package:guru_widgets/theme/guru_theme.dart';
import 'package:intl/intl.dart';

/// Created by Haoyi on 2023/10/11

class TrophyExhibitBinding extends Bindings {
  @override
  void dependencies() {
    Get.lazyPut(() => TrophyExhibitController());
  }
}

class TrophyExhibitController extends LifecycleController {
  Stream<Map<String, AwardEntity>> get observableAwards =>
      DailyChallengeManager.instance.observableAwards;

  final DateFormat monthFormat = DateFormat("MMMM");

  final List<String> monthName = [];

  String getTrophyImage(int yearMonth) {
    return DailyChallengeManager.instance.getExhibitedTrophyImage(yearMonth);
  }

  int getAchievedAward(int yearMonth) {
    return DailyChallengeManager.instance.getAchieved(yearMonth);
  }

  @override
  void onInit() {
    super.onInit();
    monthName.clear();
    for (int i = 1; i <= 12; i++) {
      monthName.add(monthFormat.format(DateTime(2023, i)));
    }
  }
}
