import 'dart:io';

import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.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';
import 'package:url_launcher/url_launcher.dart';

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

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

class _UnsafeDeviceScreenState extends State<AppUpdateScreen> {
  String? dynamicParams;

  @override
  Widget build(BuildContext context) {
    dynamicParams ??= ModalRoute.of(context)!.settings.arguments as String;
    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,
            "Please Update Your App".toText24(isBold: true),
            48.height,
            dynamicParams.toString().toText14(isCenter: true).paddingOnly(left: 20.0, right: 20.0),
            21.height,
            DefaultButton(LocaleKeys.ok.tr(), () async {
              if (Platform.isAndroid || Platform.isIOS) {
                var appId = Platform.isAndroid ? 'hmg.cloudSolutions.mohem' : '1468856602';
                var url = Uri.parse(
                  Platform.isAndroid ? "market://details?id=$appId" : "https://apps.apple.com/app/id$appId",
                );
                launchUrl(
                  url,
                  mode: LaunchMode.externalApplication,
                );
              }
            }).paddingAll(24)
          ],
        ),
      ),
    );
  }
}
