/*
 * @Author: WuXiangNan
 * @Date: 2021-03-22 17:41:36
 * @LastEditTime : 2021-09-10 11:06:30
 * @LastEditors  : WuWei
 * @Description: 
 */

import 'dart:async';
import 'package:attendance_package/src/models/response_model/clock_status/current_clock_status_vos_model.dart';
import 'package:attendance_package/src/models/response_model/clock_status/rules_model.dart';
import 'package:attendance_package/src/view_models/attendance_store.dart';
import 'package:intl/intl.dart';
import 'package:flutter/material.dart';
import 'package:wisdom_cli/wisdom_cli.dart';

class TimeStore with ChangeNotifier {
  final BuildContext context;

  TimeStore(this.context);

  String _time = DateFormat("HH:mm:ss").format(DateTime.now());

  String get time => _time;

  set time(value) => _time = value;

  // 定时更新时间
  Timer? timer;

  AttendanceStore get attendanceStore =>
      Provider.of<AttendanceStore>(context, listen: false);

  List<CurrentClockStatusVosModel>? timeLine = [];

  List<RulesModel>? rulesList = [];

  String? status;

  void destory() {
    timer?.cancel();
  }

  // 当天日期
  day() {
    var now = DateTime.now();
    DateFormat outputFormat = DateFormat("yyyy-MM-dd");
    return outputFormat.format(now);
  }

  // 当前时间
  getDayTime() {
    timer = Timer.periodic(Duration(seconds: 1), (timer) {
      timeLine = attendanceStore.clockTimeLineList;
      var now = DateTime.now();
      DateFormat outputFormat = DateFormat("HH:mm:ss");
      time = outputFormat.format(now);
      rulesList = attendanceStore.clockStatusData!.rules;
      status = null;
      notifyListeners();
    });
  }
}
