import 'dart:ui';
import 'package:doctor_app_flutter/core/viewModel/project_view_model.dart';
import 'package:doctor_app_flutter/screens/patients/ReferralDischargedPatientPage.dart';
import 'package:doctor_app_flutter/screens/patients/patient_search/patient_search_header.dart';
import 'package:doctor_app_flutter/screens/patients/profile/referral/refer_details/referred-patient-screen.dart';
import 'package:doctor_app_flutter/utils/tab_utils.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:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'my-referral-inpatient-screen.dart';

class PatientReferralScreen extends StatefulWidget {
  @override
  _PatientReferralScreen createState() => _PatientReferralScreen();
}

class _PatientReferralScreen extends State<PatientReferralScreen>
    with SingleTickerProviderStateMixin {
  TabController? _tabController;
  int index = 0;

  @override
  void initState() {
    super.initState();
    _tabController = TabController(length: 3, vsync: this);
    _tabController!.addListener(_handleTabSelection);
  }

  _handleTabSelection() {
    setState(() {
      index = _tabController!.index;
    });
  }

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

  @override
  Widget build(BuildContext context) {
    ProjectViewModel projectsProvider = Provider.of<ProjectViewModel>(context);

    return AppScaffold(
        isShowAppBar: true,
        appBar: PatientSearchHeader(
          title: TranslationBase.of(context).patientsreferral,
        ),
        appBarTitle: TranslationBase.of(context).patientsreferral,
        body: Scaffold(
          extendBodyBehindAppBar: true,
          // backgroundColor: Colors.white,
          appBar: PreferredSize(
            preferredSize:
                Size.fromHeight(MediaQuery.of(context).size.height * 0.070),
            child: Center(
              child: Container(
                height: TabUtils.getTabHeight(context),
                color: TabUtils.getBgTabColor(),
                child: Center(
                  child: TabBar(
                    isScrollable: false,
                    controller: _tabController,
                    indicatorColor: Colors.transparent,
                    indicatorWeight: 1.0,
                    indicatorSize: TabBarIndicatorSize.tab,
                    labelColor: Theme.of(context).primaryColor,
                    labelPadding:
                        EdgeInsets.only(top: 0, left: 0, right: 0, bottom: 0),
                    unselectedLabelColor: Colors.grey[800],
                    tabs: [
                      Container(
                        decoration: TabUtils.getBoxTabsBoxDecoration(
                            isActive: index == 0,
                            isFirst: true,
                            projectViewModel: projectsProvider),
                        child: Center(
                            child: TabUtils.getTabText(
                                title: TranslationBase.of(context)
                                    .myReferredPatient,
                                isActive: index == 0)),
                      ),
                      Center(
                        child: Container(
                          decoration: TabUtils.getBoxTabsBoxDecoration(
                              isActive: index == 1,
                              isMiddle: true,
                              projectViewModel: projectsProvider),
                          child: Center(
                              child: TabUtils.getTabText(
                                  title: TranslationBase.of(context).referral,
                                  isActive: index == 1)),
                        ),
                      ),
                      Center(
                        child: Container(
                          decoration: TabUtils.getBoxTabsBoxDecoration(
                              isActive: index == 2,
                              isLast: true,
                              projectViewModel: projectsProvider),
                          child: Center(
                            child: TabUtils.getTabText(
                                title: TranslationBase.of(context).discharged,
                                isActive: index == 2),
                          ),
                        ),
                      ),
                    ],
                  ),
                ),
              ),
            ),
          ),
          body: Column(
            children: <Widget>[
              Expanded(
                child: TabBarView(
                  physics: BouncingScrollPhysics(),
                  controller: _tabController,
                  children: <Widget>[
                    ReferredPatientScreen(),
                    MyReferralInPatientScreen(),
                    ReferralDischargedPatientPage()
                    // MyReferredPatient(),
                  ],
                ),
              )
            ],
          ),
        ));
  }
}
