import 'package:hmg_patient_app/core/model/AlHabibMedicalService/EReferral/create_e_referral_request_model.dart';
import 'package:hmg_patient_app/pages/AlHabibMedicalService/E-Referral/New_E_Referral/new_e_referral_step_one_page.dart';
import 'package:hmg_patient_app/theme/colors.dart';
import 'package:hmg_patient_app/uitl/translations_delegate_base.dart';
import 'package:hmg_patient_app/uitl/utils_new.dart';
import 'package:flutter/material.dart';

import 'new_e_referral_step_three_page.dart';
import 'new_e_referral_step_two_page.dart';

class StartIndexForNewEReferral extends StatefulWidget {
  StartIndexForNewEReferral();

  @override
  _StartIndexForNewEReferralState createState() => _StartIndexForNewEReferralState();
}

class _StartIndexForNewEReferralState extends State<StartIndexForNewEReferral> with TickerProviderStateMixin {
  late PageController _controller;
  int _currentIndex = 0;
  int pageSelected = 2;

  CreateEReferralRequestModel createEReferralRequestModel = new CreateEReferralRequestModel();

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

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

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

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Container(
        height: double.infinity,
        child: Column(
          children: [
            Container(
              width: double.infinity,
              padding: EdgeInsets.only(left: 12,right: 12,top: 12),
              child: Row(
                children: [
                  Expanded(
                    child: showProgress(
                      title: TranslationBase.of(context).RequesterInfo,
                      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>[
                  NewEReferralStepOnePage(
                    changePageViewIndex: changePageViewIndex,
                    createEReferralRequestModel: createEReferralRequestModel,
                  ),
                  NewEReferralStepTowPage(
                    changePageViewIndex: changePageViewIndex,
                    createEReferralRequestModel: createEReferralRequestModel,
                  ),
                  NewEReferralStepThreePage(
                    changePageViewIndex: changePageViewIndex,
                    createEReferralRequestModel: createEReferralRequestModel,
                  ),
                ],
              ),
            ),
          ],
        ),
      ),
    );
  }

  Widget showProgress({required String title, required String status, required 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,
                ),
              ),
            ),
          ],
        )
      ],
    );
  }
}
