import 'package:doctor_app_flutter/config/size_config.dart';
import 'package:doctor_app_flutter/core/enum/view_state.dart';
import 'package:doctor_app_flutter/core/model/patient/patiant_info_model.dart';
import 'package:doctor_app_flutter/core/viewModel/SOAP_view_model.dart';
import 'package:doctor_app_flutter/screens/base/base_view.dart';
import 'package:doctor_app_flutter/screens/patients/patient_search/patient_search_header.dart';
import 'package:doctor_app_flutter/screens/patients/profile/soap_update_vida_plus/assessment/widget/enter_diagnosis.dart';
import 'package:doctor_app_flutter/screens/patients/profile/soap_update_vida_plus/assessment/widget/favotite_diagnosis.dart';
import 'package:doctor_app_flutter/utils/translations_delegate_base_utils.dart';
import 'package:doctor_app_flutter/widgets/shared/app_scaffold_widget.dart';
import 'package:doctor_app_flutter/widgets/shared/app_texts_widget.dart';
import 'package:doctor_app_flutter/widgets/shared/buttons/app_buttons_widget.dart';
import 'package:flutter/material.dart';
import 'package:hexcolor/hexcolor.dart';

class AddDiagnosis extends StatefulWidget {
  final PatiantInformtion patientInfo;

  const AddDiagnosis({super.key, required this.patientInfo});

  @override
  State<AddDiagnosis> createState() => _AddDiagnosisState();
}

class _AddDiagnosisState extends State<AddDiagnosis>
    with SingleTickerProviderStateMixin {
  TabController? _tabController;
  bool isLoading = true;

  @override
  void initState() {
    _tabController = new TabController(length: 2, vsync: this);
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return BaseView<SOAPViewModel>(
        onModelReady: (model) {
          WidgetsBinding.instance.addPostFrameCallback((_) {
            model.getConditionAndType(widget.patientInfo);
            model.favoriteDiagnosis(widget.patientInfo);
            setState(() {
              isLoading = false;
            });
          });
        },
        builder: (_, model, w) => AppScaffold(
          isLoading: model.state == ViewState.BusyLocal ,
              isShowAppBar: true,
              appBar: PatientSearchHeader(
                  title: TranslationBase.of(context).addDiagnosis),
              backgroundColor: Colors.white,
              body: Column(
                children: [
                  SizedBox(
                    height: 56,
                    child: TabBar(
                      indicatorColor: Color(0xFFD02127),
                      unselectedLabelColor: Color(0xFF6D6D6D),
                      labelColor: Color(0xFF2B353E),
                      controller: _tabController,
                      tabs: [
                        Tab(
                          child: Text(
                            TranslationBase.of(context).mappedDiagnosis,
                            style:TextStyle(
                                    color: Color(0xFF6D6D6D),
                                    fontSize: 14,
                                    fontWeight: FontWeight.w600,
                                    letterSpacing: -0.56,
                                  )
                          ),
                        ),
                        Tab(
                          child: Text(
                            TranslationBase.of(context).favoriteDiagnosis,
                            style: TextStyle(color: Color(0xFF6D6D6D),
                            fontSize: 14,
                            fontWeight: FontWeight.w600,
                            letterSpacing: -0.56,)
                          ),
                        ),
                      ],
                    ),
                  ),
                  Expanded(
                    child: TabBarView(
                      controller: _tabController,
                      children: [
                        EnterDiagnosis(
                          patientInfo: widget.patientInfo,
                        ),
                        FavoriteDiagnosis(
                          patientInfo: widget.patientInfo,
                        ),
                      ],
                    ),
                  ),
                ],
              ),
            ));
  }
}
