import 'package:hmg_patient_app/config/size_config.dart';
import 'package:hmg_patient_app/pages/login/login-type.dart';
import 'package:hmg_patient_app/pages/login/register-info.dart';
import 'package:hmg_patient_app/pages/login/register.dart';
import 'package:hmg_patient_app/services/authentication/auth_provider.dart';
import 'package:hmg_patient_app/theme/colors.dart';
import 'package:hmg_patient_app/uitl/app_shared_preferences.dart';
import 'package:hmg_patient_app/uitl/translations_delegate_base.dart';
import 'package:hmg_patient_app/uitl/utils.dart';
import 'package:hmg_patient_app/uitl/utils_new.dart';
import 'package:hmg_patient_app/widgets/others/app_scaffold_widget.dart';
import 'package:flutter/material.dart';

class RegisterNew extends StatefulWidget {
  @override
  _RegisterNew createState() => _RegisterNew();
}

class _RegisterNew extends State<RegisterNew> {
  final nationalIDorFile = TextEditingController();
  final int loginType = LoginType.loginType;
  late String mobileNo;
  String countryCode = '966';
  var isHijri;
  final util = Utils();
  late DateTime selectedDate;
  late String dob;
  bool isButtonDisabled = true;
  final authService = new AuthProvider();
  final sharedPref = new AppSharedPreferences();
  late PageController _controller;
  late bool isLoading;
  int _currentIndex = 0;

  @override
  void initState() {
    super.initState();
    _controller = new PageController();
  }

  @override
  void dispose() {
    super.dispose();
  }

  changePageViewIndex(pageIndex) {
    _controller.jumpToPage(pageIndex);
  }

  @override
  Widget build(BuildContext context) {
    return AppScaffold(
      appBarTitle: TranslationBase.of(context).register,
      isShowAppBar: true,
      isShowDecPage: false,
      showNewAppBar: true,
      showNewAppBarTitle: true,
      body: SingleChildScrollView(
          child: Container(
        height: SizeConfig.realScreenHeight! * .9,
        width: SizeConfig.realScreenWidth,
        child: Column(children: <Widget>[
          Container(
            width: double.infinity,
            padding: EdgeInsets.only(left: 20, right: 20, top: 12),
            child: Row(
              children: [
                Expanded(
                  child: showProgress(
                    title: TranslationBase.of(context).enterDetails,
                    status: _currentIndex == 0
                        ? TranslationBase.of(context).inPrgress
                        : _currentIndex > 0
                            ? TranslationBase.of(context).completed
                            : TranslationBase.of(context).locked,
                    color: _currentIndex == 0 ? CustomColors.orange : CustomColors.green,
                  ),
                ),
                Expanded(
                  child: showProgress(
                    title: TranslationBase.of(context).patientInfo,
                    status: _currentIndex == 1
                        ? TranslationBase.of(context).inPrgress
                        : _currentIndex > 1
                            ? TranslationBase.of(context).completed
                            : TranslationBase.of(context).locked,
                    color: _currentIndex == 1
                        ? CustomColors.orange
                        : _currentIndex > 1
                            ? CustomColors.green
                            : CustomColors.grey2,
                  ),
                ),
                showProgress(
                  title: TranslationBase.of(context).otherInfo,
                  status: _currentIndex == 2 ? TranslationBase.of(context).inPrgress : TranslationBase.of(context).locked,
                  color: _currentIndex == 2
                      ? CustomColors.orange
                      : _currentIndex > 3
                          ? CustomColors.green
                          : CustomColors.grey2,
                  isNeedBorder: false,
                ),
              ],
            ),
          ),
          Expanded(
            child: PageView(
              physics: NeverScrollableScrollPhysics(),
              controller: _controller,
              onPageChanged: (index) {
                setState(() {
                  _currentIndex = index;
                });
              },
              scrollDirection: Axis.horizontal,
              children: <Widget>[
                Register(
                  changePageViewIndex: changePageViewIndex,
                ),

                RegisterInfo(
                  changePageViewIndex: changePageViewIndex,
                ),
                RegisterInfo(changePageViewIndex: changePageViewIndex, page: 2),
                // NewEReferralStepOnePage(
                //   changePageViewIndex: changePageViewIndex,
                //   createEReferralRequestModel: createEReferralRequestModel,
                // ),
                // NewEReferralStepTowPage(
                //   changePageViewIndex: changePageViewIndex,
                //   createEReferralRequestModel: createEReferralRequestModel,
                // ),
                // NewEReferralStepThreePage(
                //   changePageViewIndex: changePageViewIndex,
                //   createEReferralRequestModel: createEReferralRequestModel,
                // ),
              ],
            ),
          ),
        ]),
      )),
    );
  }

  Widget showProgress({String? title, String? status, Color? color, bool isNeedBorder = true}) {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Row(
              children: [
                Container(
                  width: 26,
                  height: 26,
                  decoration: containerRadius(color!, 200),
                  child: Icon(
                    Icons.done,
                    color: Colors.white,
                    size: 16,
                  ),
                ),
                if (isNeedBorder)
                  Expanded(
                      child: Padding(
                    padding: const EdgeInsets.all(8.0),
                    child: mDivider(Colors.grey),
                  )),
              ],
            ),
            mHeight(8),
            Text(
              title!,
              style: TextStyle(
                fontSize: 11,
                fontWeight: FontWeight.w600,
                letterSpacing: -0.44,
              ),
            ),
            mHeight(2),
            Container(
              padding: EdgeInsets.all(5),
              decoration: containerRadius(color!.withOpacity(0.2), 4),
              child: Text(
                status!,
                style: TextStyle(
                  fontSize: 8,
                  fontWeight: FontWeight.w600,
                  letterSpacing: -0.32,
                  color: color,
                ),
              ),
            ),
          ],
        )
      ],
    );
  }
}
