import 'dart:async';

import 'package:flyinsono/views/desktop/real_time_consultation/live_consultation/controller.dart';
import 'package:flyinsono/views/desktop/real_time_consultation/live_consultation/state.dart';

class LoadingController {
  LiveConsultationController controller;
  LiveConsulationState get state => controller.state;
  Timer? _timer;

  LoadingController(this.controller);

  void startLoading() {
    state.isLoading = true;
    state.showRetryButton = false;
    _timer = Timer(Duration(seconds: 15), () {
      state.isLoading = false;
      state.showRetryButton = true;
      _timer?.cancel();
    });
  }

  void stopLoading() {
    state.isLoading = false;
    state.showRetryButton = false;
    _timer?.cancel();
  }

  void retry() {
    state.isLoading = true;
    state.showRetryButton = false;
    startLoading();
  }

  void showRetryButton() {
    state.isLoading = false;
    state.showRetryButton = true;
  }
}
