import 'dart:ffi';

import 'package:flutter/material.dart';

import 'package:get/get.dart';
import 'package:naiyouwl/app/component/sys_app_bar.dart';
import 'package:url_launcher/url_launcher.dart';

import '../../../controller/controllers.dart';
import '../controllers/welcome_controller.dart';

class WelcomeView extends GetView<WelcomeController> {
  const WelcomeView({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      decoration: const BoxDecoration(
        image: DecorationImage(
          image: AssetImage("assets/images/main/qidong.png"),
          fit: BoxFit.fill,
        ),
      ),
      child: Scaffold(
        backgroundColor: Colors.transparent,
        appBar: const SysAppBar(title: Text("启动"),),
        body: Obx(() {
          if(controller.error.value.isNotEmpty) {
            String mess = controller.error.value;
            controller.error.value = '';
            Future.delayed(Duration.zero, () async {
              bool? result = await controllers.dialog.showNormalDialog(
                title: "提示",
                content: mess,
                cancelText: "取消",
                enterText: "确认",
              );
              if (result != null && result) {
                // User pressed "确认"
                await controller.fetchSysConfig();
              } else {

              }
            });
          }
          if(controller.isUPdateVerion.value == true){
            controller.isUPdateVerion.value = false;
            Future.delayed(Duration.zero, () async {
              bool? result = await controllers.dialog.showNormalDialog(
                title: "提示",
                content: controller.verModes.value.appmsg ?? "有更新",
                cancelText: "不更新",
                enterText: "更新",
              );
              if (result != null && result) {
                // User pressed "确认"
                if(controller.verModes.value.appdownload != null){
                  await launchUrl(Uri.parse(controller.verModes.value.appdownload ?? ""));
                }

              } else {
                await controller.fetchSysConfig();
              }
            });
          }
          return Center(
            child: Column(

              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                const SizedBox(height: 500 - 24 ),
               controller.isLoading.value == true ? const CircularProgressIndicator() : Container(), // 菊花加载指示器
                const SizedBox(height: 10),// 用于给加载指示器和文字之间增加一些空间
                Text(
                  controller.msgStatus.value,
                  style: const TextStyle(
                    fontSize: 16,
                    fontWeight: FontWeight.w600,
                  ),
                ),
              ],
            ), // 当不在加载时，你可能想要显示其他的 Widget
          );

        }),
      ),
    );
  }
}




