// ignore_for_file: unnecessary_overrides

import 'dart:io';

import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:IQ/app/global/static_informs.dart';
import 'package:IQ/app/modules/home/models/support_model.dart';
import 'package:IQ/app/modules/home/providers/support.dart';

class SupportController extends GetxController with WidgetsBindingObserver {
  bool fetchSupportData = false;
  // ignore: prefer_typing_uninitialized_variables
  var fetchLoadingSupportTicketsDataVar;

  Future<void> onRefresh() async {
    fetchSupportData = false;
    supportTickets = null;
    fetchLoadingSupportTicketsDataVar = fetchLoadingSupportTicketsData();
    update();
  }

  fetchLoadingSupportTicketsData() async {
    await getUserSupportInforms();
    if (getUserSupportInformsLoads) {
      fetchSupportData = true;
      listOfSupportTickets = supportTickets?.data ?? [];
      update();
    } else {
      fetchSupportData = false;
      listOfSupportTickets = [];
      update();
      Get.snackbar('Error', 'Please try again later');
    }
  }

  List<Data>? listOfSupportTickets = supportTickets?.data ?? [];

  @override
  void didChangeAppLifecycleState(AppLifecycleState state) {
    super.didChangeAppLifecycleState(state);
    if (state == AppLifecycleState.inactive ||
        state == AppLifecycleState.detached ||
        state == AppLifecycleState.paused) return;
    if (state == AppLifecycleState.resumed) {
      defaultLocale = Platform.localeName.split('_')[0];
      snackBarText = 'back_twice'.tr;
    }
  }

  @override
  void onInit() {
    fetchLoadingSupportTicketsDataVar = fetchLoadingSupportTicketsData();
    WidgetsBinding.instance.addObserver(this);

    super.onInit();
  }

  @override
  void onReady() {
    super.onReady();
  }

  @override
  void onClose() {
    WidgetsBinding.instance.removeObserver(this);
  }
}
