import 'package:diplomaticquarterapp/analytics/flows/login_registration.dart';
import 'package:diplomaticquarterapp/analytics/google-analytics.dart';
import 'package:diplomaticquarterapp/locator.dart';
import 'package:diplomaticquarterapp/pages/login/forgot-password.dart';
import 'package:diplomaticquarterapp/pages/login/login.dart';
import 'package:diplomaticquarterapp/pages/login/register_new.dart';
import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart';
import 'package:diplomaticquarterapp/widgets/habib_logo_widget.dart';
import 'package:diplomaticquarterapp/widgets/transitions/fade_page.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/svg.dart';

class LoginType extends StatelessWidget {
  static int loginType = 0;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Color(0xfff8f8f8),
      resizeToAvoidBottomInset: false,
      appBar: AppBar(
        backgroundColor: Colors.transparent,
        leading: IconButton(
          icon: Icon(Icons.arrow_back_ios),
          color: Color(0xff2B353E),
          onPressed: () => Navigator.pop(context),
        ),
      ),
      body: Padding(
        padding: EdgeInsets.only(bottom: 20, left: 21, right: 21),
        child: Column(children: [
          Expanded(
            child: ListView(
              padding: EdgeInsets.zero,
              physics: BouncingScrollPhysics(),
              children: [
                SizedBox(height: 12),
                HabibLogoWidget(),
                SizedBox(height: 50),
                Text(
                  TranslationBase.of(context).logintypeRadio,
                  style: TextStyle(fontSize: 16, fontWeight: FontWeight.w600, color: Color(0xff2B353E), letterSpacing: -0.64, height: 23 / 16),
                ),
                GridView(
                  gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 2, crossAxisSpacing: 13, mainAxisSpacing: 9),
                  physics: NeverScrollableScrollPhysics(),
                  padding: EdgeInsets.only(top: 25),
                  shrinkWrap: true,
                  children: [
                    getButton(context, TranslationBase.of(context).nationalIdNumber, 'assets/images/new/national_id.svg', 1),
                    getButton(context, TranslationBase.of(context).medicalFileNumber, 'assets/images/new/medical_file.svg', 2),
                  ],
                ),
                SizedBox(height: 20),
                RichText(
                  text: TextSpan(
                    text: TranslationBase.of(context).forgotPassword,
                    style: TextStyle(decoration: TextDecoration.underline, fontSize: 12, fontWeight: FontWeight.w600, color: Color(0xffC9272B), letterSpacing: -0.48, height: 18 / 12),
                    recognizer: TapGestureRecognizer()
                      ..onTap = () {
                        Navigator.of(context).push(FadePage(page: ForgotPassword()));
                        locator<GAnalytics>().loginRegistration.forget_file_number();
                      },
                  ),
                ),
              ],
            ),
          ),
          SizedBox(
            height: 43,
            width: double.infinity,
            child: TextButton(
              onPressed: () {
                Navigator.of(context).push(FadePage(page: RegisterNew()));
                locator<GAnalytics>().loginRegistration.register_now();
              },
              child: Text(
                TranslationBase.of(context).registerNow,
                style: TextStyle(fontSize: 16, fontWeight: FontWeight.w600, color: Colors.white, letterSpacing: -0.48),
              ),
              style: TextButton.styleFrom(
                backgroundColor: Color(0xffD02127),
                shape: RoundedRectangleBorder(
                  borderRadius: BorderRadius.circular(6),
                ),
              ),
            ),
          ),
        ]),
      ),
    );

    // AppScaffold(
    //     appBarTitle: TranslationBase.of(context).login,
    //     isShowAppBar: true,
    //     isShowDecPage: false,
    //     body: SingleChildScrollView(
    //         child: Container(
    //             padding: EdgeInsets.only(top: 10, left: 20, right: 20, bottom: 30),
    //             height: SizeConfig.realScreenHeight * .9,
    //             width: SizeConfig.realScreenWidth,
    //             child: Column(
    //               children: <Widget>[
    //                 Expanded(
    //                   flex: 4,
    //                   child: Column(
    //                       // mainAxisAlignment: MainAxisAlignment.spaceEvenly,
    //                       crossAxisAlignment: CrossAxisAlignment.start,
    //                       children: <Widget>[
    //                         Image.asset(
    //                           'assets/images/DQ/logo.png',
    //                           height: 90,
    //                           width: 90,
    //                         ),
    //                         AppText(
    //                           TranslationBase.of(context).logintypeRadio,
    //                           fontSize: SizeConfig.textMultiplier * 3.5,
    //                           textAlign: TextAlign.start,
    //                           marginBottom: 20.0,
    //                           marginTop: 20.0,
    //                         ),
    //                         Row(
    //                           mainAxisAlignment: MainAxisAlignment.center,
    //                           children: <Widget>[
    //                             Expanded(
    //                                 child: InkWell(
    //                                     onTap: () => {
    //                                           LoginType.loginType = 1,
    //                                           Navigator.of(context).push(FadePage(page: Login())),
    //                                         },
    //                                     child: RoundedContainer(
    //                                         borderColor: Colors.grey,
    //                                         showBorder: true,
    //                                         child: Padding(
    //                                           padding: EdgeInsets.fromLTRB(20, 10, 20, 10),
    //                                           child: Column(
    //                                             mainAxisAlignment: MainAxisAlignment.center,
    //                                             children: <Widget>[
    //                                               Image.asset(
    //                                                 'assets/images/id_card_icon.png',
    //                                                 height: SizeConfig.imageSizeMultiplier * 12,
    //                                                 width: SizeConfig.imageSizeMultiplier * 15,
    //                                               ),
    //                                               SizedBox(
    //                                                 height: 20,
    //                                               ),
    //                                               AppText(
    //                                                 TranslationBase.of(context).idNo,
    //                                                 fontSize: SizeConfig.textMultiplier * 2,
    //                                                 fontWeight: FontWeight.bold,
    //                                               )
    //                                             ],
    //                                           ),
    //                                         )))),
    //                             Expanded(
    //                                 child: InkWell(
    //                                     onTap: () => {
    //                                           LoginType.loginType = 2,
    //                                           Navigator.of(context).push(FadePage(page: Login())),
    //                                         },
    //                                     child: RoundedContainer(
    //                                         borderColor: Colors.grey,
    //                                         showBorder: true,
    //                                         child: Padding(
    //                                           padding: EdgeInsets.fromLTRB(25, 10, 25, 10),
    //                                           child: Column(
    //                                             children: <Widget>[
    //                                               Image.asset(
    //                                                 'assets/images/my_file_white_icon.png',
    //                                                 height: SizeConfig.imageSizeMultiplier * 12,
    //                                                 width: SizeConfig.imageSizeMultiplier * 15,
    //                                               ),
    //                                               SizedBox(
    //                                                 height: 20,
    //                                               ),
    //                                               AppText(
    //                                                 TranslationBase.of(context).fileNo,
    //                                                 fontSize: SizeConfig.textMultiplier * 2,
    //                                                 fontWeight: FontWeight.bold,
    //                                               )
    //                                             ],
    //                                           ),
    //                                         ))))
    //                           ],
    //                         ),
    //                         SizedBox(
    //                           height: 25,
    //                         ),
    //                         Divider(
    //                           color: Colors.grey,
    //                           height: 2,
    //                         ),
    //                         Center(
    //                             child: InkWell(
    //                                 onTap: () => {
    //                                       Navigator.of(context).push(FadePage(page: ForgotPassword())),
    //                                     },
    //                                 child: AppText(TranslationBase.of(context).forgotPassword, fontSize: SizeConfig.textMultiplier * 2.5, marginTop: 20.0, underline: true)))
    //                       ]),
    //                 ),
    //                 Expanded(
    //                     flex: 1,
    //                     child: Column(
    //                       mainAxisAlignment: MainAxisAlignment.end,
    //                       children: <Widget>[
    //                         Divider(
    //                           color: Colors.grey,
    //                           height: 2,
    //                         ),
    //                         SizedBox(
    //                           height: 10,
    //                         ),
    //                         Row(
    //                           children: <Widget>[
    //                             Expanded(
    //                                 child: DefaultButton(
    //                               TranslationBase.of(context).registerNow,
    //                               () => {
    //                                 Navigator.of(context).push(FadePage(page: Register())),
    //                               },
    //                             )),
    //                           ],
    //                         ),
    //                       ],
    //                     ))
    //               ],
    //             ))));
  }

  Widget getButton(BuildContext _context, String _title, String _icon, int _flag) {
    var type = '';
    if (_flag == 1) type = 'national id';
    if (_flag == 2) type = 'file number';

    return InkWell(
      onTap: () {
        LoginType.loginType = _flag;
        LoginRegistration.loginMethod = _flag;
        Navigator.of(_context).push(FadePage(page: Login()));
        locator<GAnalytics>().loginRegistration.login_start(method: type);
      },
      child: Container(
        padding: EdgeInsets.only(left: 20, right: 20, bottom: 15, top: 28),
        decoration: BoxDecoration(
          borderRadius: BorderRadius.circular(15),
          color: Colors.white,
          border: Border.all(
            color: Color(0xffefefef),
            width: 1,
          ),
        ),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: <Widget>[
            SvgPicture.asset(
              _icon,
              height: 38,
              width: 38,
            ),
            Text(
              _title,
              style: TextStyle(fontSize: 16, fontWeight: FontWeight.w600, color: Color(0xff2B353E), letterSpacing: -0.48, height: 20 / 16),
            ),
          ],
        ),
      ),
    );
  }
}
