import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:proxibuy/data/storage/shared_preferences_helper.dart';

class ThemModeCubit extends Cubit<ThemeMode> {
  ThemModeCubit() : super(_getInitialThemeMode());

  static ThemeMode _getInitialThemeMode() {
    final lastThemeMode = ThemeModeStorage.getMode();
    if (lastThemeMode.contains('dark')) {
      return ThemeMode.dark;
    } else if (lastThemeMode.contains('light')) {
      return ThemeMode.light;
    }
    return ThemeMode.system;
  }

  void changeTheme() {
    if (state == ThemeMode.dark) {
      ThemeModeStorage.setMode('light');
      emit(ThemeMode.light);
    } else {
      ThemeModeStorage.setMode('dark');
      emit(ThemeMode.dark);
    }
  }
}
