import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';

import 'package:get/get.dart';
import 'package:IQ/app/global/static_informs.dart';
import 'package:IQ/app/global/text_widget.dart';

import '../controllers/autologin_controller.dart';

class AutologinView extends GetView<AutologinController> {
  const AutologinView({Key? key}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: brandColor,
      appBar: AppBar(
        backgroundColor: brandColor,
        elevation: 0,
        leading: Container(),
      ),
      body: WillPopScope(
        onWillPop: () async {
          return false;
        },
        child: GetBuilder(
            init: AutologinController(),
            builder: (AutologinController c) {
              return Stack(
                alignment: Alignment.topCenter,
                children: [
                  if (c.errorText != '')
                    SvgPicture.asset(
                      'assets/2/icon.svg',
                      height: 80,
                      width: 80,
                    ),
                  SizedBox(
                    width: widthSize(context),
                    child: Column(
                      mainAxisAlignment: MainAxisAlignment.start,
                      crossAxisAlignment: CrossAxisAlignment.center,
                      children: [
                        if (c.errorText != '')
                          SizedBox(
                            height: 120 +
                                MediaQuery.of(context).viewPadding.top +
                                AppBar().preferredSize.height,
                          ),
                        if (c.errorText == '') const Spacer(flex: 2),
                        c.errorText == ''
                            ? SvgPicture.asset("assets/autologin_loading.svg")
                            : Column(
                                children: [
                                  SvgPicture.asset(
                                    'assets/autologin_fail.svg',
                                    height: 220,
                                    width: 220,
                                  ),
                                  const SizedBox(height: 20),
                                  TextWidget(
                                    color: Colors.white,
                                    fontSize: 20,
                                    fontWeight: FontWeight.w300,
                                    text: "autoLogin_failed".tr,
                                  ),
                                  const SizedBox(height: 20),
                                ],
                              ),
                        const Spacer(),
                        if (c.errorText == '')
                          Visibility(
                            visible: c.errorText == '',
                            child: Column(
                              children: [
                                const SizedBox(height: 30),
                                TextWidget(
                                  color: Colors.white,
                                  fontSize: 18,
                                  text: "auto_login".tr,
                                ),
                              ],
                            ),
                          ),
                        const Spacer(),
                        Container(),
                        const SizedBox(height: 30),
                      ],
                    ),
                  ),
                ],
              );
            }),
      ),
    );
  }
}
