import 'package:shared/utils/date_time_utils.dart';
import 'package:widgets/load_state_layout.dart';

import 'visitTimeType.dart';

class ChooseVisitTimeContentState{
  // 当前所选中的所有时间段集合
  List<VisitTimeContentItem> get allSelectedTimeList => visitTimeList.where((item) => item.isChecked??false).toList()??[];

  // extraTotalCost 总预约费用
  double get extraTotalCost {
    if(extraCostList?.isNotEmpty == true){
      return extraCostList?.fold(0.0, (previousValue, current) => previousValue! + current??0.0)??0.0;
    }else {
      return 0.0;
    }
  }

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

  // 是否可多选
  bool? isMultiSelect;
  List<VisitTimeContentItem> visitTimeList = [];
  List<double>? extraCostList = [];  // 预约费用（节假日/加急/夜间 费用的集合）
  String currentDate = DateTimeUtils.formatDate(DateTime.now(), format: "yyyy-MM-dd");


  ChooseVisitTimeContentState({
    this.loadingState = LoadState.State_Loading,
    this.errorMessage,
    this.isMultiSelect = false,
    required this.currentDate,
    this.extraCostList,
    List<VisitTimeContentItem>? visitTimeList,
  }) {
    this.visitTimeList = visitTimeList ?? [];
  }

  ChooseVisitTimeContentState copyWith({
    LoadState? loadingState,
    String? errorMessage,
    bool? isMultiSelect,
    List<VisitTimeContentItem>? visitTimeList,
    List<double>? extraCostList,
    String? currentDate,
  }) {
    return ChooseVisitTimeContentState(
      loadingState: loadingState ?? this.loadingState,
      errorMessage: errorMessage ?? this.errorMessage,
      isMultiSelect: isMultiSelect ?? this.isMultiSelect,
      visitTimeList: visitTimeList ?? this.visitTimeList,
      extraCostList: extraCostList ?? this.extraCostList,
      currentDate: currentDate ?? this.currentDate,
    );
  }
}


class VisitTimeContentItem{
  int? id;
  String? timeText;
  String? time;
  bool? urgent;
  bool? holiday;
  bool? night;
  bool? isChecked;
  bool? enable;
  VisitTimeContentItem({
    this.id,
    this.timeText,
    this.time,
    this.urgent,
    this.holiday,
    this.night,
    this.isChecked = false,
    this.enable = false,
  });

  VisitTimeContentItem copyWith({
    String? name,
    int? id,
    Map<String, dynamic>? type,
    bool? isChecked,
    bool? enable,
  }){
    return VisitTimeContentItem(
        id: id??this.id,
        timeText: timeText??this.timeText,
        time: time??this.time,
        urgent: urgent??this.urgent,
        holiday: holiday??this.holiday,
        night: night??this.night,
        isChecked: isChecked??this.isChecked,
        enable: enable??this.enable,
    );
  }
}
