import 'package:app_settings/app_settings.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../../../extention/context_extention.dart';
import '../../../services/language_services.dart';

class RequestPermissionDialog {
  RequestPermissionDialog._init();
  static RequestPermissionDialog? _instance;
  static RequestPermissionDialog get instance =>
      _instance ??= RequestPermissionDialog._init();

  requestPermissionDialogAndroid(BuildContext context, IconData icon,
      String content, AppSettingsType type) {
    showDialog(
      useRootNavigator: false,
      context: context,
      builder: (dialogContext) {
        return AlertDialog(
          title: Center(
            child: Icon(icon),
          ),
          content: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            crossAxisAlignment: CrossAxisAlignment.center,
            mainAxisSize: MainAxisSize.min,
            children: [
              Padding(
                padding: dialogContext.paddingNormalVertical,
                child: Text(
                  "Alow app to use $content permission",
                  textAlign: TextAlign.center,
                  style: const TextStyle(
                      fontWeight: FontWeight.bold, fontSize: 18),
                ),
              ),
              Divider(height: dialogContext.lowValue),
              GestureDetector(
                onTap: () {
                  AppSettings.openAppSettings(type: type);
                  Navigator.of(dialogContext).pop();
                },
                child: Padding(
                  padding: dialogContext.paddingNormalVertical,
                  child: Text(appLocalization(context).allow_message,
                      style: const TextStyle(fontWeight: FontWeight.bold)),
                ),
              ),
              Divider(height: dialogContext.lowValue),
              GestureDetector(
                onTap: () {
                  Navigator.of(dialogContext).pop();
                },
                child: Padding(
                  padding: dialogContext.paddingNormalVertical,
                  child: Text(
                    appLocalization(dialogContext).decline_message,
                    style: const TextStyle(
                      fontWeight: FontWeight.bold,
                    ),
                  ),
                ),
              ),
            ],
          ),
        );
      },
    );
  }

  requestPermissionDialogIOS(context, AppSettingsType appSettingsType, content,
          AppSettingsType type) =>
      showCupertinoDialog<void>(
        context: context,
        builder: (showCupertinoDialogContext) => CupertinoAlertDialog(
          title: Text(appLocalization(showCupertinoDialogContext)
              .permission_deny_message),
          content: Text("Alow app to use $content permission"),
          actions: <CupertinoDialogAction>[
            CupertinoDialogAction(
              child: Text(appLocalization(showCupertinoDialogContext)
                  .cancel_button_content),
              onPressed: () => Navigator.pop(showCupertinoDialogContext),
            ),
            CupertinoDialogAction(
              isDefaultAction: true,
              child: Text(
                  appLocalization(showCupertinoDialogContext).allow_message),
              onPressed: () {
                Navigator.pop(showCupertinoDialogContext);
                AppSettings.openAppSettings(type: appSettingsType);
              },
            ),
          ],
        ),
      );
}
