import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:mohem_flutter_app/api/dashboard_api_client.dart';
import 'package:mohem_flutter_app/classes/utils.dart';
import 'package:mohem_flutter_app/main.dart';
import 'package:mohem_flutter_app/models/dashboard/get_attendance_tracking_list_model.dart';

/// Mix-in [DiagnosticableTreeMixin] to have access to [debugFillProperties] for the devtool
// ignore: prefer_mixin
class DashboardProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
  bool isAttendanceTrackingLoading = true;
  int isTimeRemainingInSeconds = 0;
  GetAttendanceTracking? attendanceTracking;

  fetchAttendanceTracking() async {
    try {
      attendanceTracking = await DashbaordApiClient().getAttendanceTracking();
      isAttendanceTrackingLoading = false;
      isTimeRemainingInSeconds = calculateSeconds("00:00:30");
      notifyListeners();
    } catch (ex) {
      Utils.handleException(ex, null);
    }
  }

  int calculateSeconds(String time) {
    int hour = int.parse(time.split(":")[0]);
    int mints = int.parse(time.split(":")[1]);
    int seconds = int.parse(time.split(":")[2]);
    return ((hour * 60 * 60) + (mints * 60) + seconds);
  }

  update() {
    isAttendanceTrackingLoading = !isAttendanceTrackingLoading;
    attendanceTracking?.pSwipeIn = "a";
    isTimeRemainingInSeconds = calculateSeconds("00:00:30");
    notifyListeners();
  }
}
