import 'package:cs_resources/generated/l10n.dart';
import 'package:domain/entity/newsfeed_detail_entity.dart';
import 'package:flutter/cupertino.dart';
import 'package:widgets/load_state_layout.dart';


class NewsfeedDetailState {
  //页面 LoadView 状态的展示
  LoadState loadingState;
  String? errorMessage;
  // 评论框信息
  Map<String, dynamic>? commentFieldInfo;

  // 详情页信息
  // DetailInfoData? detailInfo;
  NewsfeedDetailEntity? detailInfo;

  NewsfeedDetailState({
    this.loadingState = LoadState.State_Loading,
    String? errorMessage,
    Map<String, dynamic>? commentFieldInfo,
    NewsfeedDetailEntity? detailInfo,
  }): detailInfo = detailInfo ?? NewsfeedDetailEntity(),
        commentFieldInfo = commentFieldInfo ?? {
    'value': '',
    'controller': TextEditingController(),
    'hintText': S.current.enter_comment,
    'focusNode': FocusNode(),
    'obsecure': false,
  },
      errorMessage = errorMessage?? '';

  NewsfeedDetailState copyWith({
    LoadState? loadingState,
    String? errorMessage,
    int? page,
    int? limit,
    int? count,
    NewsfeedDetailEntity? detailInfo,
    Map<String, dynamic>? commentFieldInfo,
    List<Map<String, dynamic>>? list,
  }) {
    return NewsfeedDetailState(
      loadingState: loadingState ?? this.loadingState,
      errorMessage: errorMessage ?? this.errorMessage,
      commentFieldInfo: commentFieldInfo ?? this.commentFieldInfo,
      detailInfo: detailInfo ?? this.detailInfo,
    );
  }

  Map<String, dynamic> toMap() {
    return {
      'loadingState': this.loadingState,
      'errorMessage': this.errorMessage,
      'commentFieldInfo': this.commentFieldInfo,
      'detailInfo': this.detailInfo,
    };
  }

  factory NewsfeedDetailState.fromMap(Map<String, dynamic> map) {
    return NewsfeedDetailState(
      loadingState: map['loadingState'] as LoadState,
      errorMessage: map['errorMessage'] as String,
      commentFieldInfo: map['commentFieldInfo'] as Map<String, dynamic>,
      detailInfo: map['detailInfo'] as NewsfeedDetailEntity,
    );
  }
}