import 'package:connectivity_plus/connectivity_plus.dart';
import 'package:get/get.dart';

class ConnectivityController extends GetxController {
  var isConnected = true.obs;

  @override
  void onInit() {
    super.onInit();
    _checkInitialConnection();

    // Listen to connection changes
    Connectivity().onConnectivityChanged.listen((status) {
      isConnected.value = (status != ConnectivityResult.none);
    });
  }

  Future<void> _checkInitialConnection() async {
    final status = await Connectivity().checkConnectivity();
    isConnected.value = (status != ConnectivityResult.none);
  }

  Future<void> retryConnection() async {
    final status = await Connectivity().checkConnectivity();
    isConnected.value = (status != ConnectivityResult.none);
  }
}
