import 'package:flutter_bloc/flutter_bloc.dart';
import '../../domain/repositories/dashboard_repository.dart';
import 'dashboard_state.dart';

class DashboardCubit extends Cubit<DashboardState> {
  final DashboardRepository _repo;

  DashboardCubit(this._repo) : super(const DashboardInitial());

  Future<void> loadStats() async {
    emit(const DashboardLoading());
    try {
      final stats = await _repo.getStats();
      emit(DashboardLoaded(stats));
    } catch (e) {
      emit(DashboardError(e.toString()));
    }
  }

  Future<void> refresh() async => loadStats();
}