import 'package:cpt_community/modules/my_posts/my_posts_newsfeed/newsfeed_itemgroup_state.dart';
import 'package:widgets/load_state_layout.dart';

class MyPostsNewsfeedState {
  //页面 LoadView 状态的展示
  LoadState loadingState;
  String? errorMessage;

  int? activeTabIndex =0;
  List<Map<String, dynamic>>? tabsList;
  List<NewsFeedItemGroupState>? list = [];

  MyPostsNewsfeedState({
    this.loadingState = LoadState.State_Loading,
    String? errorMessage,
    this.activeTabIndex,
    List<Map<String, dynamic>>? tabsList,
    this.list,
  }): tabsList = tabsList ?? [
    {
      'code': 'newsFeed',
      'title': 'News Feed',
      'publish_num': 0,
    },
    {
      'code': 'forSale',
      'title': 'For Sale',
      'publish_num': 0,
    },
    {
      'code': 'forRent',
      'title': 'For Rent',
      'publish_num': 0,
    },
  ];

  MyPostsNewsfeedState copyWith({
    LoadState? loadingState,
    String? errorMessage,
    int? activeTabIndex,
    List<Map<String, dynamic>>? tabsList,
    List<NewsFeedItemGroupState>? list,
  }) {
    return MyPostsNewsfeedState(
      loadingState: loadingState ?? this.loadingState,
      errorMessage: errorMessage ?? this.errorMessage,
      activeTabIndex: activeTabIndex ?? this.activeTabIndex,
      tabsList: tabsList ?? this.tabsList,
      list: list ?? this.list,
    );
  }

  Map<String, dynamic> toMap() {
    return {
      'loadingState': this.loadingState,
      'errorMessage': this.errorMessage,
      'activeTabIndex': this.activeTabIndex,
      'tabsList': this.tabsList,
      'list': this.list,
    };
  }

  factory MyPostsNewsfeedState.fromMap(Map<String, dynamic> map) {
    return MyPostsNewsfeedState(
      loadingState: map['loadingState'] as LoadState,
      errorMessage: map['errorMessage'] as String,
      activeTabIndex: map['activeTabIndex'] as int,
      tabsList: map['tabsList'] as List<Map<String, dynamic>>,
      list: map['list'] as List<NewsFeedItemGroupState>,
    );
  }
}