import 'package:hmg_patient_app/analytics/google-analytics.dart';
import 'package:hmg_patient_app/config/config.dart';
import 'package:hmg_patient_app/core/viewModels/project_view_model.dart';
import 'package:hmg_patient_app/pages/BookAppointment/components/SearchByClinic.dart';
import 'package:hmg_patient_app/pages/BookAppointment/components/SearchByDoctor.dart';
import 'package:hmg_patient_app/pages/BookAppointment/components/search_by_hospital_name.dart';
import 'package:hmg_patient_app/uitl/translations_delegate_base.dart';
import 'package:hmg_patient_app/widgets/others/app_scaffold_widget.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

class Search extends StatefulWidget {
  final int type;
  final List? clnicIds;
  Function()? onBackClick;

  Search({this.type = 0, this.clnicIds, this.onBackClick});

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

class _SearchState extends State<Search> with TickerProviderStateMixin {
  late TabController _tabController;

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

  @override
  Widget build(BuildContext context) {
    AppGlobal.context = context;
    //  ProjectViewModel projectViewModel = Provider.of(context);
    GAnalytics.TREATMENT_TYPE =
        null; // reset treatment type on start new booking

    return AppScaffold(
      isShowAppBar: false,
      isShowDecPage: false,
      showNewAppBarTitle: true,
      showNewAppBar: true,
      appBarTitle: TranslationBase.of(context).bookAppo,
      backgroundColor: Color(0xFFF7F7F7),
      onTap: widget.onBackClick,
      body: Column(
        children: [
          TabBar(
            controller: _tabController,
            indicatorWeight: 3.0,
            indicatorSize: TabBarIndicatorSize.tab,
            labelColor: Color(0xff2B353E),
            unselectedLabelColor: Color(0xff575757),
            labelPadding:
                EdgeInsets.only(top: 15, bottom: 13, left: 20, right: 20),
            labelStyle: TextStyle(
              fontFamily: context.read<ProjectViewModel>().isArabic
                  ? 'Cairo'
                  : 'Poppins',
              fontSize: 16,
              fontWeight: FontWeight.w600,
              letterSpacing: -0.48,
            ),
            unselectedLabelStyle: TextStyle(
              fontFamily: context.read<ProjectViewModel>().isArabic
                  ? 'Cairo'
                  : 'Poppins',
              fontSize: 16,
              fontWeight: FontWeight.w600,
              letterSpacing: -0.48,
            ),
            tabs: [
              Text(
                TranslationBase.of(context).hospitalName,
                style: TextStyle(fontSize: 12),
              ),
              Text(
                TranslationBase.of(context).clinicName,
                style: TextStyle(fontSize: 12),
              ),
              Text(
                TranslationBase.of(context).doctorName,
                style: TextStyle(fontSize: 12),
              )
            ],
            onTap: (idx) {
              if (idx == 0)
                context
                    .read<ProjectViewModel>()
                    .analytics
                    .appointment
                    .book_appointment_by_clinic();
              else
                context
                    .read<ProjectViewModel>()
                    .analytics
                    .appointment
                    .book_appointment_by_doctor();
            },
          ),
          Expanded(
            child: TabBarView(
              physics: NeverScrollableScrollPhysics(),
              children: [
                SearchByHospital(),
                SearchByClinic(clnicIds: widget.clnicIds),
                SearchByDoctor(),
              ],
              controller: _tabController,
            ),
          )
        ],
      ),
    );
  }
}
