import 'dart:async';

import 'package:zhiying_comm/util/base_bloc.dart';
import 'package:zhiying_comm/zhiying_comm.dart';

class HotRankingPageBloc extends BlocBase {
  List<Map<String, dynamic>> _pageData = List();

  StreamController<List<Map<String, dynamic>>> _dataController =
      StreamController<List<Map<String, dynamic>>>();

  Stream<List<Map<String, dynamic>>> get outData => _dataController.stream;

  StreamController<Map<String, dynamic>> _eventController =
      StreamController.broadcast();

  Stream<Map<String, dynamic>> get event => _eventController.stream;

  String backgroundImage;

  @override
  void dispose() {
    _dataController.close();
    _eventController.close();
    _dataController = null;
    _eventController.close();
  }

  loadData(String skipIdentifier) {
    NetUtil.request('/api/v1/mod/${skipIdentifier}', method: NetMethod.GET,
        onCache: (data) {
      _loadData(data);
    }, onSuccess: (data) {
      print(data);
      _loadData(data);
    });
  }

  void _loadData(dynamic data) {
    print(data["mod_lis"]);
    _pageData = List.from(data["mod_list"]).map((v) {
      return Map<String, dynamic>.from(v);
    }).toList();
    _dataController.add(_pageData);
  }

  void sendEvent(Map<String,dynamic> event){
    _eventController.add(event);
  }

}
