import 'dart:io';

import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:mohem_flutter_app/classes/colors.dart';
import 'package:mohem_flutter_app/extensions/int_extensions.dart';
import 'package:mohem_flutter_app/extensions/string_extensions.dart';
import 'package:mohem_flutter_app/extensions/widget_extensions.dart';
import 'package:mohem_flutter_app/generated/locale_keys.g.dart';
import 'package:mohem_flutter_app/widgets/button/default_button.dart';

class UnsafeDeviceScreen extends StatefulWidget {
  const UnsafeDeviceScreen({Key? key}) : super(key: key);

  @override
  State<UnsafeDeviceScreen> createState() => _UnsafeDeviceScreenState();
}

class _UnsafeDeviceScreenState extends State<UnsafeDeviceScreen> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SafeArea(
        child: Column(
          mainAxisSize: MainAxisSize.min,
          crossAxisAlignment: CrossAxisAlignment.center,
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            21.height,
            Center(child: Image.asset("assets/images/logos/main_mohemm_logo.png", width: 200, height: 50)),
            50.height,
            "Sorry".toText24(isBold: true),
            21.height,
            "You are using Mohemm app on an unsafe device. To be able to use the app with all it's features, Please make sure that the below points are considered: "
                .toText14(isCenter: true)
                .paddingOnly(left: 20.0, right: 20.0),
            48.height,
            passwordConstraintsUI("The device is not jailbroken or rooted.", true).paddingOnly(left: 24.0, right: 5.0),
            8.height,
            passwordConstraintsUI("The app is not installed on external storage.", true).paddingOnly(left: 24.0, right: 5.0),
            8.height,
            passwordConstraintsUI("Development mode is disabled.", true).paddingOnly(left: 24.0, right: 5.0),
            21.height,
            DefaultButton(LocaleKeys.ok.tr(), () async {
              if (Platform.isAndroid) {
                SystemChannels.platform.invokeMethod('SystemNavigator.pop');
              } else {
                // MinimizeApp.minimizeApp();
              }
            }).paddingAll(24)
          ],
        ),
      ),
    );
  }

  Widget passwordConstraintsUI(String description, bool check) {
    return Row(
      children: [
        4.width,
        SizedBox(
          width: 12,
          height: 12,
          child: Checkbox(fillColor: MaterialStateProperty.all(MyColors.gradiantEndColor), shape: const CircleBorder(), value: check, onChanged: null),
        ),
        8.width,
        description.toText14()
      ],
    );
  }
}
