import 'package:doctor_app_flutter/core/viewModel/project_view_model.dart';
import 'package:doctor_app_flutter/screens/doctor/doctor_replay/doctor_reply_screen.dart';
import 'package:doctor_app_flutter/screens/doctor/my_schedule_screen.dart';
import 'package:doctor_app_flutter/screens/home/home_screen.dart';
import 'package:doctor_app_flutter/screens/qr_reader/QR_reader_screen.dart';
import 'package:doctor_app_flutter/utils/translations_delegate_base_utils.dart';
import 'package:doctor_app_flutter/widgets/shared/app_drawer_widget.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/bottom_nav_bar.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:hexcolor/hexcolor.dart';
import 'package:provider/provider.dart';

class LandingPage extends StatefulWidget {
  @override
  _LandingPageState createState() => _LandingPageState();
}

class _LandingPageState extends State<LandingPage> {
  int currentTab = 0;
  late PageController pageController;

  _changeCurrentTab(int tab) {
    setState(() {
      currentTab = tab;
      pageController.jumpToPage(tab);
    });
  }

  @override
  void initState() {
    super.initState();
    pageController = new PageController(keepPage: true);
  }

  @override
  Widget build(BuildContext context) {
    ProjectViewModel projectViewModel = Provider.of(context);
    return AppScaffold(
      appBar: currentTab != 0
          ? AppBar(
              toolbarHeight: 95,
              elevation: 0,
              backgroundColor: HexColor('#FFFFFF'),
              //textTheme: TextTheme(headline6: TextStyle(color: Colors.white)),
              title: currentTab != 0
                  ? AppText(
                      getText(currentTab),
                      letterSpacing: -1.44,
                      fontWeight: FontWeight.w700,
                      fontSize: 24.0,
                      color: Color(0xff2B353E),
                    )
                  : SizedBox(),
              leading: Builder(
                builder: (BuildContext context) {
                  return Container(
                    width: 40,
                    margin: EdgeInsets.only(left: projectViewModel.isArabic ? 0 : 20, right: projectViewModel.isArabic ? 20 : 0),
                    child: IconButton(
                        icon: SvgPicture.asset('assets/images/svgs/menu.svg', height: 25, width: 10),
                        iconSize: 15,
                        color: Color(0xff2B353E),
                        onPressed: () {
                          Scaffold.of(context).openDrawer();
                        }),
                  );
                },
              ),
              centerTitle: true,
            )
          : MyAppbar(),
      drawer: SafeArea(child: AppDrawer()),
      extendBody: true,
      body: PageView(
        physics: NeverScrollableScrollPhysics(),
        controller: pageController,
        children: [
          HomeScreen(),
          MyScheduleScreen(),
          QrReaderScreen(),
          DoctorReplyScreen(
            changeCurrentTab: () {
              _changeCurrentTab(0);
            },
          ),
        ],
      ),
      bottomNavigationBar: BottomNavBar(
        changeIndex: _changeCurrentTab,
        index: currentTab,
      ),
    );
  }

  getText(currentTab) {
    switch (currentTab) {
      case 0:
        return TranslationBase.of(context).home;
      case 1:
        return TranslationBase.of(context).mySchedule;
      case 2:
        return TranslationBase.of(context).qr;
      case 3:
        return TranslationBase.of(context).replay2;
    }
  }
}

class MyAppbar extends StatelessWidget implements PreferredSizeWidget {
  @override
  final Size preferredSize;

  MyAppbar({Key? key})
      : preferredSize = Size.fromHeight(0.0),
        super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container();
  }
}
