import 'dart:io';

import 'package:hmg_patient_app/uitl/translations_delegate_base.dart';
import 'package:hmg_patient_app/widgets/dialogs/confirm_dialog.dart';
import 'package:flutter/cupertino.dart';
import 'package:permission_handler/permission_handler.dart';

import 'PlatformBridge.dart';

class AppPermission {
  static Future<bool> askVideoCallPermission(BuildContext context) async {
    if (!(await Permission.camera.request().isGranted) || !(await Permission.microphone.request().isGranted)) {
      return false;
    }
    // if (Platform.isAndroid && !(await PlatformBridge.shared().isDrawOverAppsPermissionAllowed())) {
    //   await _drawOverAppsMessageDialog(context);
    //   return false;
    // }
    return true;
  }

//

  // Manifest.permission.INTERNET,
  // Manifest.permission.ACCESS_FINE_LOCATION,
  // Manifest.permission.ACCESS_COARSE_LOCATION,
  // Manifest.permission.ACCESS_NETWORK_STATE,
  // Manifest.permission.BLUETOOTH,
  // Manifest.permission.BLUETOOTH_ADMIN,
  // Manifest.permission.BLUETOOTH_SCAN,
  // Manifest.permission.BLUETOOTH_CONNECT,
  // Manifest.permission.HIGH_SAMPLING_RATE_SENSORS,
  // Manifest.permission.ACTIVITY_RECOGNITION

  static Future<bool> askPenguinPermissions() async {
    if (!(await Permission.location.request().isGranted) ||
        !(await Permission.bluetooth.request().isGranted) ||
        !(await Permission.bluetoothScan.request().isGranted) ||
        !(await Permission.bluetoothConnect.request().isGranted) ||
        !(await Permission.activityRecognition.request().isGranted)) {
      return false;
    }
    return true;
  }

  static Future _drawOverAppsMessageDialog(BuildContext context) async {
    ConfirmDialog dialog = new ConfirmDialog(
        context: context,
        confirmMessage: TranslationBase.of(context).drawOverAppsPermission,
        okText: TranslationBase.of(context).confirm,
        cancelText: TranslationBase.of(context).cancel_nocaps,
        okFunction: () async {
          await PlatformBridge.shared().askDrawOverAppsPermission();
          Navigator.pop(context);
        },
        cancelFunction: () => {});
    dialog.showAlertDialog(context);
  }
}
