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

import 'components/SearchByClinic.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 {
  TabController _tabController;

  @override
  void initState() {
    _tabController = new TabController(length: 2, 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: projectViewModel.isArabic ? 'Cairo' : 'Poppins',
              fontSize: 16,
              fontWeight: FontWeight.w600,
              letterSpacing: -0.48,
            ),
            unselectedLabelStyle: TextStyle(
              fontFamily: projectViewModel.isArabic ? 'Cairo' : 'Poppins',
              fontSize: 16,
              fontWeight: FontWeight.w600,
              letterSpacing: -0.48,
            ),
            tabs: [Text(TranslationBase.of(context).clinicName), Text(TranslationBase.of(context).doctorName)],
            onTap: (idx){
              if(idx == 0)
                projectViewModel.analytics.appointment.book_appointment_by_clinic();
              else
                projectViewModel.analytics.appointment.book_appointment_by_doctor();
            },
          ),
          Expanded(
            child: TabBarView(
              physics: NeverScrollableScrollPhysics(),
              children: [
                SearchByClinic(clnicIds: widget.clnicIds),
                SearchByDoctor(),
              ],
              controller: _tabController,
            ),
          )
        ],
      ),
    );
  }
}
