import 'dart:io';

import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart';
import 'package:diplomaticquarterapp/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;
  }

  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);
  }
}