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

import '../../constant/box_name.dart';
import '../../main.dart';
import '../../print.dart';
import '../../views/widgets/mydialoug.dart';
import '../auth/captin/login_captin_controller.dart';

class LocationPermissions {
  // late Location location;

  // Future locationPermissions() async {
  //   location = Location();
  //   var permissionStatus = await location.requestPermission();
  //   if (permissionStatus == PermissionStatus.denied) {
  //     // The user denied the location permission.
  //     Get.defaultDialog(title: 'GPS Required Allow !.'.tr, middleText: '');
  //     return null;
  //   }
  // }
}

Future<void> getPermissionLocation() async {
  final PermissionStatus status = await Permission.locationAlways.status;
  if (!await Permission.locationAlways.serviceStatus.isEnabled) {
    Log.print('status.isGranted: ${status.isGranted}');
    // box.write(BoxName.locationPermission, 'true');
    await Permission.locationAlways.request();
    Get.put(LoginDriverController()).update();
    MyDialog().getDialog(
      'Enable Location Permission'.tr, // {en:ar}
      'Allowing location access will help us display orders near you. Please enable it now.'
          .tr, // {en:ar}
      () async {
        Get.back();
        box.write(BoxName.locationPermission, 'true');
        await Permission.locationAlways.request();
      },
    );
  }
}

Future<void> getPermissionLocation1() async {
  PermissionStatus status = await Permission.locationWhenInUse.request();

  if (status.isGranted) {
    // After granting when in use, request "always" location permission
    status = await Permission.locationAlways.request();

    if (status.isGranted) {
      print("Background location permission granted");
    } else {
      print("Background location permission denied");
    }
  } else {
    print("Location permission denied");
    await openAppSettings();
  }
}
