import 'package:doctor_app_flutter/config/config.dart';
import 'package:doctor_app_flutter/config/size_config.dart';
import 'package:doctor_app_flutter/core/viewModel/project_view_model.dart';
import 'package:doctor_app_flutter/core/model/patient/patiant_info_model.dart';
import 'package:doctor_app_flutter/screens/patients/profile/soap_update/shared_soap_widgets/steper/status_Label.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:provider/provider.dart';

import 'Step_details_widget.dart';

class StepsWidget extends StatelessWidget {
  final int index;
  final Function? changeCurrentTab;
  final double height;
  final PatiantInformtion? patientInfo;

  StepsWidget({Key? key, this.index = 0, this.changeCurrentTab, this.height = 0.0, this.patientInfo});

  @override
  Widget build(BuildContext context) {
    ProjectViewModel projectViewModel = Provider.of(context);
    double circleHeight = (SizeConfig.isHeightVeryShort
        ? 30
        : SizeConfig.isHeightShort
            ? 38
            : 38);
    double circleTop = (SizeConfig.isHeightVeryShort
        ? 12
        : SizeConfig.isHeightShort
            ? 10
            : 10);
    double containerHeight = SizeConfig.heightMultiplier! * (SizeConfig.isHeightVeryShort ? 16 : 15);

    return !projectViewModel.isArabic
        ? Stack(
            children: [
              Container(
                height: height == 0 ? containerHeight : height,
                width: MediaQuery.of(context).size.width * 0.9,
                color: Colors.transparent,
              ),
              Positioned(
                top: 30,
                child: Center(
                  child: Container(
                    width: MediaQuery.of(context).size.width * (patientInfo!.admissionNo == null || patientInfo!.admissionNo!.isEmpty ? 0.9 : 0.85),
                    child: Divider(
                      color: Colors.grey,
                      height: 0.75,
                      thickness: 0.75,
                    ),
                  ),
                ),
              ),
              Positioned(
                top: circleTop,
                left: 0,
                child: InkWell(
                  onTap: () => changeCurrentTab!(0),
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Container(
                        width: circleHeight,
                        height: circleHeight,
                        decoration: BoxDecoration(
                          border: index == 0
                              ? Border.all(color: Color(0xFFCC9B14), width: 2)
                              : index > 0
                                  ? null
                                  : Border.all(color: Colors.black, width: 0.75),
                          shape: BoxShape.circle,
                          color: index == 0
                              ? Color(0xFFCC9B14)
                              : index > 0
                                  ? AppGlobal.appGreenColor
                                  : Color(0xFFCCCCCC),
                        ),
                        child: Center(
                            child: Icon(
                          FontAwesomeIcons.check.data,
                          size: 20,
                          color: Colors.white,
                        )),
                      ),
                      SizedBox(height: 5),
                      Column(
                        mainAxisAlignment: MainAxisAlignment.start,
                        children: [
                          StepDetailsWidget(
                            stepLabel: "Subjective",
                          ),
                          StatusLabel(
                            selectedStepId: index,
                            stepId: 0,
                          ),
                        ],
                      ),
                    ],
                  ),
                ),
              ),
              Positioned(
                top: circleTop,
                left: patientInfo!.admissionNo == null || patientInfo!.admissionNo!.isEmpty ? MediaQuery.of(context).size.width * 0.25 : MediaQuery.of(context).size.width * 0.71,
                child: InkWell(
                  onTap: () => index >= 1 ? changeCurrentTab!(1) : null,
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.center,
                    children: [
                      Container(
                        width: circleHeight,
                        height: circleHeight,
                        decoration: BoxDecoration(
                          border: index == 1
                              ? Border.all(color: Color(0xFFCC9B14), width: 2)
                              : index > 2
                                  ? null
                                  : Border.all(color: Color(0xFFCCCCCC), width: 0.75),
                          shape: BoxShape.circle,
                          color: index == 1
                              ? Color(0xFFCC9B14)
                              : index > 1
                                  ? AppGlobal.appGreenColor
                                  : Color(0xFFCCCCCC),
                        ),
                        child: Center(
                            child: Icon(
                          FontAwesomeIcons.check.data,
                          size: 20,
                          color: Colors.white,
                        )),
                      ),
                      SizedBox(
                        height: 5,
                      ),
                      Column(
                        mainAxisAlignment: MainAxisAlignment.start,
                        children: [
                          StepDetailsWidget(
                            stepLabel: "Objective",
                          ),
                          StatusLabel(
                            selectedStepId: index,
                            stepId: 1,
                          ),
                        ],
                      ),
                    ],
                  ),
                ),
              ),
              if (patientInfo!.admissionNo == null || patientInfo!.admissionNo!.isEmpty)
                Positioned(
                  top: circleTop,
                  left: MediaQuery.of(context).size.width * 0.47,
                  child: InkWell(
                    onTap: () {
                      if (index >= 3) changeCurrentTab!(2);
                    },
                    child: Column(
                      crossAxisAlignment: CrossAxisAlignment.center,
                      children: [
                        Container(
                          width: circleHeight,
                          height: circleHeight,
                          decoration: BoxDecoration(
                            border: index == 2
                                ? Border.all(color: Color(0xFFCC9B14), width: 2)
                                : index > 2
                                    ? null
                                    : Border.all(color: Color(0xFFCCCCCC), width: 0.75),
                            shape: BoxShape.circle,
                            color: index == 2
                                ? Color(0xFFCC9B14)
                                : index > 2
                                    ? AppGlobal.appGreenColor
                                    : Color(0xFFCCCCCC),
                          ),
                        child: Center(
                            child: Icon(
                          FontAwesomeIcons.check.data,
                          size: 20,
                          color: Colors.white,
                        )),
                      ),
                      SizedBox(
                        height: 5,
                      ),
                      Column(
                        mainAxisAlignment: MainAxisAlignment.start,
                        children: [
                          StepDetailsWidget(
                            stepLabel: "Assessment",
                          ),
                            StatusLabel(
                              selectedStepId: index,
                              stepId: 2,
                            ),
                          ],
                        ),
                      ],
                    ),
                  ),
                ),
              if (patientInfo!.admissionNo == null || patientInfo!.admissionNo!.isEmpty)
                Positioned(
                  top: circleTop,
                  right: 0,
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.end,
                    children: [
                      Container(
                        width: circleHeight,
                        height: circleHeight,
                        decoration: BoxDecoration(
                          border: index == 3
                              ? Border.all(color: Color(0xFFCC9B14), width: 2)
                              : index > 3
                                  ? null
                                  : Border.all(color: Color(0xFFCCCCCC), width: 0.75),
                          shape: BoxShape.circle,
                          color: index == 3
                              ? Color(0xFFCC9B14)
                              : index > 3
                                  ? AppGlobal.appGreenColor
                                  : Color(0xFFCCCCCC),
                        ),
                        child: Center(
                            child: Icon(
                          FontAwesomeIcons.check.data,
                          size: 20,
                          color: Colors.white,
                        )),
                      ),
                      SizedBox(
                        height: 5,
                      ),
                      Column(
                        crossAxisAlignment: CrossAxisAlignment.center,
                        children: [
                          StepDetailsWidget(
                            stepLabel: "Plan",
                            marginLeft: 30,
                          ),
                          StatusLabel(
                            selectedStepId: index,
                            stepId: 3,
                          ),
                        ],
                      ),
                    ],
                  ),
                ),
            ],
          )
        : Stack(
            children: [
              Container(
                height: height == 0 ? 100 : height,
                width: MediaQuery.of(context).size.width * 0.9,
                color: Colors.transparent,
              ),
              Positioned(
                top: 30,
                child: Center(
                  child: Container(
                    width: MediaQuery.of(context).size.width * (patientInfo!.admissionNo == null || patientInfo!.admissionNo!.isEmpty ? 0.9 : 0.85),
                    child: Divider(
                      color: Colors.grey,
                      height: 0.75,
                      thickness: 0.75,
                    ),
                  ),
                ),
              ),
              Positioned(
                top: circleTop,
                right: 0,
                child: InkWell(
                  onTap: () => changeCurrentTab!(0),
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Container(
                        width: circleHeight,
                        height: circleHeight,
                        decoration: BoxDecoration(
                          border: index == 0
                              ? Border.all(color: Color(0xFFCC9B14), width: 2)
                              : index > 0
                                  ? null
                                  : Border.all(color: Colors.black, width: 0.75),
                          shape: BoxShape.circle,
                          color: index == 0
                              ? Color(0xFFCC9B14)
                              : index > 0
                                  ? AppGlobal.appGreenColor
                                  : Color(0xFFCCCCCC),
                        ),
                        child: Center(
                            child: Icon(
                          FontAwesomeIcons.check.data,
                          size: 20,
                          color: Colors.white,
                        )),
                      ),
                      SizedBox(height: 3),
                      Column(
                        children: [
                          StepDetailsWidget(
                            stepLabel: "شخصي",
                          ),
                          StatusLabel(
                            selectedStepId: index,
                            stepId: 0,
                          ),
                        ],
                      ),
                    ],
                  ),
                ),
              ),
              Positioned(
                top: circleTop,
                right: MediaQuery.of(context).size.width * (patientInfo!.admissionNo == null || patientInfo!.admissionNo!.isEmpty ? 0.25 : 0.71),
                child: InkWell(
                  onTap: () => index >= 2 ? changeCurrentTab!(1) : null,
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.center,
                    children: [
                      Container(
                        width: circleHeight,
                        height: circleHeight,
                        decoration: BoxDecoration(
                          border: index == 1
                              ? Border.all(color: Color(0xFFCC9B14), width: 2)
                              : index > 2
                                  ? null
                                  : Border.all(color: Color(0xFFCCCCCC), width: 0.75),
                          shape: BoxShape.circle,
                          color: index == 1
                              ? Color(0xFFCC9B14)
                              : index > 1
                                  ? AppGlobal.appGreenColor
                                  : Color(0xFFCCCCCC),
                        ),
                        child: Center(
                            child: Icon(
                          FontAwesomeIcons.check.data,
                          size: 20,
                          color: Colors.white,
                        )),
                      ),
                      SizedBox(height: 5),
                      Column(
                        children: [
                          StepDetailsWidget(
                            stepLabel: "هدف",
                          ),
                          StatusLabel(
                            selectedStepId: index,
                            stepId: 1,
                          ),
                        ],
                      ),
                    ],
                  ),
                ),
              ),
              if (patientInfo!.admissionNo == null || patientInfo!.admissionNo!.isEmpty)
                Positioned(
                  top: circleTop,
                  right: MediaQuery.of(context).size.width * 0.50,
                  child: InkWell(
                    onTap: () => index >= 3 ? changeCurrentTab!(2) : null,
                    child: Column(
                      crossAxisAlignment: CrossAxisAlignment.center,
                      children: [
                        Container(
                          width: circleHeight,
                          height: circleHeight,
                          decoration: BoxDecoration(
                            border: index == 2
                                ? Border.all(color: Color(0xFFCC9B14), width: 2)
                                : index > 2
                                    ? null
                                    : Border.all(color: Color(0xFFCCCCCC), width: 0.75),
                            shape: BoxShape.circle,
                            color: index == 2
                                ? Color(0xFFCC9B14)
                                : index > 2
                                    ? Color(0xFFCC9B14)
                                    : Color(0xFFCCCCCC),
                          ),
                           child: Center(
                               child: Icon(
                             FontAwesomeIcons.check.data,
                             size: 20,
                             color: Colors.white,
                           )),
                         ),
                         SizedBox(
                           height: 5,
                         ),
                         Padding(
                           padding: const EdgeInsets.only(right: 2),
                           child: Column(
                             children: [
                               StepDetailsWidget(
                                 stepLabel: "تقدير",
                               ),
                              StatusLabel(
                                selectedStepId: index,
                                stepId: 2,
                              ),
                            ],
                          ),
                        ),
                      ],
                    ),
                  ),
                ),
              if (patientInfo!.admissionNo == null || patientInfo!.admissionNo!.isEmpty)
                Positioned(
                  top: circleTop,
                  left: 0,
                  child: InkWell(
                    onTap: () => index >= 3 ? changeCurrentTab!(4) : null,
                    child: Column(
                      crossAxisAlignment: CrossAxisAlignment.end,
                      children: [
                        Container(
                          width: circleHeight,
                          height: circleHeight,
                          decoration: BoxDecoration(
                            border: index == 3
                                ? Border.all(color: Color(0xFFCC9B14), width: 2)
                                : index > 3
                                    ? null
                                    : Border.all(color: Color(0xFFCCCCCC), width: 0.75),
                            shape: BoxShape.circle,
                            color: index == 3
                                ? Color(0xFFCC9B14)
                                : index > 3
                                    ? Color(0xFFCC9B14)
                                    : Color(0xFFCCCCCC),
                          ),
                          child: Center(
                              child: Icon(
                            FontAwesomeIcons.check.data,
                            size: 20,
                            color: Colors.white,
                          )),
                        ),
                        SizedBox(
                          height: 5,
                        ),
                        Container(
                          margin: EdgeInsets.only(right: index == 3 ? 15 : 0),
                          child: Column(
                            children: [
                              StepDetailsWidget(
                                stepLabel: "خطة",
                              ),
                              StatusLabel(
                                selectedStepId: index,
                                stepId: 3,
                              ),
                            ],
                          ),
                        ),
                      ],
                    ),
                  ),
                ),
            ],
          );
  }
}
