mirrored_repositories/lifeclass/lib/pages/content
import 'package:flutter/material.dart';
import 'package:lifeclass/classes/clsApp.dart';
import 'package:lifeclass/pages/content/lessons/week01/Lesson00.dart';
import 'package:lifeclass/pages/content/lessons/week01/Lesson01.dart';
import 'package:lifeclass/pages/content/lessons/week01/Lesson02.dart';
import 'package:lifeclass/pages/content/lessons/week01/Lesson03.dart';
import 'package:lifeclass/pages/content/lessons/week01/Lesson04.dart';
import 'package:lifeclass/pages/content/lessons/week01/Lesson05.dart';
import 'package:lifeclass/pages/content/lessons/week01/Lesson06.dart';
import 'package:lifeclass/pages/content/lessons/week01/Lesson07.dart';
import 'package:lifeclass/pages/content/lessons/week02/Lesson08.dart';
import 'package:lifeclass/pages/content/lessons/week02/Lesson09.dart';
import 'package:lifeclass/pages/content/lessons/week02/Lesson10.dart';
import 'package:lifeclass/pages/content/lessons/week02/Lesson11.dart';
import 'package:lifeclass/pages/content/lessons/week02/Lesson12.dart';
import 'package:lifeclass/pages/content/lessons/week02/Lesson13.dart';
import 'package:lifeclass/pages/content/lessons/week02/Lesson14.dart';
import 'package:lifeclass/pages/content/lessons/week03/Lesson15.dart';
import 'package:lifeclass/pages/content/lessons/week03/Lesson16.dart';
import 'package:lifeclass/pages/content/lessons/week03/Lesson17.dart';
import 'package:lifeclass/pages/content/lessons/week03/Lesson18.dart';
import 'package:lifeclass/pages/content/lessons/week03/Lesson19.dart';
import 'package:lifeclass/pages/content/lessons/week03/Lesson20.dart';
import 'package:lifeclass/pages/content/lessons/week03/Lesson21.dart';
import 'package:lifeclass/pages/content/lessons/week04/Lesson22.dart';
import 'package:lifeclass/pages/content/lessons/week04/Lesson23.dart';
import 'package:lifeclass/pages/content/lessons/week04/Lesson24.dart';
import 'package:lifeclass/pages/content/lessons/week04/Lesson25.dart';
import 'package:lifeclass/pages/content/lessons/week04/Lesson26.dart';
import 'package:lifeclass/pages/content/lessons/week04/Lesson27.dart';
import 'package:lifeclass/pages/content/lessons/week04/Lesson28.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'classes/clsLanguageSelector.dart';
import 'package:lifeclass/classes/Themes.dart';

class LessonDetails extends StatefulWidget {
  const LessonDetails({super.key});

  @override
  State<LessonDetails> createState() => _LessonDetailsState();
}

class _LessonDetailsState extends State<LessonDetails> with SingleTickerProviderStateMixin{
  int _currentFontSize = 1;
  bool _fontDecrease = true;
  bool _fontIncrease = true;
  late TabController _controller = TabController(length: 2, vsync: this);
  late String colorTheme = clsApp.defaultColorThemes;
  late String appTitle = 'Lesson 1';
  late String language = clsApp.defaultLanguage;

  @override
  void initState() {
    reloadTheme();
    super.initState();
    _controller = TabController(length: 2, vsync: this);
    _controller.addListener(() {
      setState(() {
      });
    });
  }
  void reloadTheme() async{
    final SharedPreferences prefs = await SharedPreferences.getInstance();
    _currentFontSize = prefs.getInt('fontSize') ?? 1;
    if(_currentFontSize==0) _fontDecrease=false;
    else if(_currentFontSize==7) _fontIncrease=false;
    colorTheme = prefs.getString('colorThemes') ?? clsApp.defaultColorThemes;
    language = prefs.getString('language') ?? clsApp.defaultLanguage;
    //print('select lang->'+language);
    setState(() {});
  }
  void updateFontSize() async{
    final SharedPreferences prefs = await SharedPreferences.getInstance();
    await prefs.setInt('fontSize', _currentFontSize);
  }
  List<double> availableFontSize = [10,12,16,18,20,24,28,32];
  Widget getLessonFile(String lessonNo){
    print(lessonNo);
    late Widget page;
      switch(lessonNo) {
        case '0':
          page = Lesson00(colorTheme: colorTheme,fontSize: availableFontSize[_currentFontSize],language: language);
          break;
        case '1':
          page = Lesson01(colorTheme: colorTheme,fontSize: availableFontSize[_currentFontSize],language: language);
          break;
        case '2':
          page = Lesson02(colorTheme: colorTheme,fontSize: availableFontSize[_currentFontSize],language: language);
          break;
        case '3':
          page = Lesson03(colorTheme: colorTheme,fontSize: availableFontSize[_currentFontSize],language: language);
          break;
        case '4':
          page = Lesson04(colorTheme: colorTheme,fontSize: availableFontSize[_currentFontSize],language: language);
          break;
        case '5':
          page = Lesson05(colorTheme: colorTheme,fontSize: availableFontSize[_currentFontSize],language: language);
          break;
        case '6':
          page = Lesson06(colorTheme: colorTheme,fontSize: availableFontSize[_currentFontSize],language: language);
          break;
        case '7':
          page = Lesson07(colorTheme: colorTheme,fontSize: availableFontSize[_currentFontSize],language: language);
          break;
        case '8':
          page = Lesson08(colorTheme: colorTheme,fontSize: availableFontSize[_currentFontSize],language: language);
          break;
        case '9':
          page = Lesson09(colorTheme: colorTheme,fontSize: availableFontSize[_currentFontSize],language: language);
          break;
        case '10':
          page = Lesson10(colorTheme: colorTheme,fontSize: availableFontSize[_currentFontSize],language: language);
          break;
        case '11':
          page = Lesson11(colorTheme: colorTheme,fontSize: availableFontSize[_currentFontSize],language: language);
          break;
        case '12':
          page = Lesson12(colorTheme: colorTheme,fontSize: availableFontSize[_currentFontSize],language: language);
          break;
        case '13':
          page = Lesson13(colorTheme: colorTheme,fontSize: availableFontSize[_currentFontSize],language: language);
          break;
        case '14':
          page = Lesson14(colorTheme: colorTheme,fontSize: availableFontSize[_currentFontSize],language: language);
          break;
        case '15':
          page = Lesson15(colorTheme: colorTheme,fontSize: availableFontSize[_currentFontSize],language: language);
          break;
        case '16':
          page = Lesson16(colorTheme: colorTheme,fontSize: availableFontSize[_currentFontSize],language: language);
          break;
        case '17':
          page = Lesson17(colorTheme: colorTheme,fontSize: availableFontSize[_currentFontSize],language: language);
          break;
        case '18':
          page = Lesson18(colorTheme: colorTheme,fontSize: availableFontSize[_currentFontSize],language: language);
          break;
        case '19':
          page = Lesson19(colorTheme: colorTheme,fontSize: availableFontSize[_currentFontSize],language: language);
          break;
        case '20':
          page = Lesson20(colorTheme: colorTheme,fontSize: availableFontSize[_currentFontSize],language: language);
          break;
        case '21':
          page = Lesson21(colorTheme: colorTheme,fontSize: availableFontSize[_currentFontSize],language: language);
          break;
        case '22':
          page = Lesson22(colorTheme: colorTheme,fontSize: availableFontSize[_currentFontSize],language: language);
          break;
        case '23':
          page = Lesson23(colorTheme: colorTheme,fontSize: availableFontSize[_currentFontSize],language: language);
          break;
        case '24':
          page = Lesson24(colorTheme: colorTheme,fontSize: availableFontSize[_currentFontSize],language: language);
          break;
        case '25':
          page = Lesson25(colorTheme: colorTheme,fontSize: availableFontSize[_currentFontSize],language: language);
          break;
        case '26':
          page = Lesson26(colorTheme: colorTheme,fontSize: availableFontSize[_currentFontSize],language: language);
          break;
        case '27':
          page = Lesson27(colorTheme: colorTheme,fontSize: availableFontSize[_currentFontSize],language: language);
          break;
        case '28':
          page = Lesson28(colorTheme: colorTheme,fontSize: availableFontSize[_currentFontSize],language: language);
          break;
      }
    return page;
  }
  void getLessonQuestion(String lessonNo,String language){
      switch(lessonNo) {
        case '1':
          Navigator.pushNamed(context, '/questionnaire01');
          break;
        case '2':
          Navigator.pushNamed(context, '/questionnaire02');
          break;
        case '3':
          Navigator.pushNamed(context, '/questionnaire03');
          break;
        case '4':
          Navigator.pushNamed(context, '/questionnaire04');
          break;
        case '5':
          Navigator.pushNamed(context, '/questionnaire05');
          break;
        case '6':
          Navigator.pushNamed(context, '/questionnaire06');
          break;
        case '7':
          Navigator.pushNamed(context, '/questionnaire07');
          break;
        case '8':
          Navigator.pushNamed(context, '/questionnaire08');
          break;
        case '9':
          Navigator.pushNamed(context, '/questionnaire09');
          break;
        case '10':
          Navigator.pushNamed(context, '/questionnaire10');
          break;
        case '11':
          Navigator.pushNamed(context, '/questionnaire11');
          break;
        case '12':
          Navigator.pushNamed(context, '/questionnaire12');
          break;
        case '13':
          Navigator.pushNamed(context, '/questionnaire13');
          break;
        case '14':
          Navigator.pushNamed(context, '/questionnaire14');
          break;
        case '15':
          Navigator.pushNamed(context, '/questionnaire15');
          break;
        case '16':
          Navigator.pushNamed(context, '/questionnaire16');
          break;
        case '17':
          Navigator.pushNamed(context, '/questionnaire17');
          break;
        case '18':
          Navigator.pushNamed(context, '/questionnaire18');
          break;
        case '19':
          Navigator.pushNamed(context, '/questionnaire19');
          break;
        case '20':
          Navigator.pushNamed(context, '/questionnaire20');
          break;
        case '21':
          Navigator.pushNamed(context, '/questionnaire21');
          break;
        case '22':
          Navigator.pushNamed(context, '/questionnaire22');
          break;
        case '23':
          Navigator.pushNamed(context, '/questionnaire23');
          break;
        case '24':
          Navigator.pushNamed(context, '/questionnaire24');
          break;
        case '25':
          Navigator.pushNamed(context, '/questionnaire25');
          break;
        case '26':
          Navigator.pushNamed(context, '/questionnaire26');
          break;
        case '27':
          Navigator.pushNamed(context, '/questionnaire27');
          break;
        case '28':
          Navigator.pushNamed(context, '/questionnaire28');
          break;
      }
  }

  @override
  Widget build(BuildContext context) {
    var brightness = MediaQuery.of(context).platformBrightness;
    bool isDarkMode = brightness == Brightness.dark;

    final routeArgs = ModalRoute.of(context)?.settings.arguments as Map<String,String>;
    final String lessonNo = routeArgs['lessonNo'].toString();
    final String weekNo =  routeArgs['weekNo'].toString();
    final title = routeArgs['title'].toString();

    Widget pageDetails = getLessonFile(lessonNo);

    return Scaffold(
      appBar: AppBar(
        title: Text(lessonNo=='0'? clsLanguagePreset.introduction(language) :   'WEEK ' + weekNo + ' DAY '  + lessonNo + ': ' + title),
        actions: [
          IconButton(onPressed: _fontDecrease ?  (){
            setState(() {
              int index = _currentFontSize - 1;
              if (index <= 0) {
                _currentFontSize = 0;
                _fontDecrease = false;
              } else {
                _fontIncrease=true;
                _currentFontSize--;
              }
              print(_currentFontSize);
              updateFontSize();
            });
          }: null,
              tooltip: clsLanguagePreset.app_bar_action_button_tooltip_font_decrease(language),
              icon: Icon(Icons.text_decrease,
                  color:  _fontDecrease ? Colors.white: Colors.grey[400])),

          IconButton(onPressed: _fontIncrease ? (){
            setState(() {
              int index = _currentFontSize + 1;
              if(index>6){
                _currentFontSize = 7;
                _fontIncrease = false;
              }else {
                _currentFontSize++;
                _fontDecrease=true;
              }
            });
            print(_currentFontSize);
            updateFontSize();
          }: null,
              tooltip: clsLanguagePreset.app_bar_action_button_tooltip_font_increase(language),
              icon: Icon(Icons.text_increase,
                  color: _fontIncrease ? Colors.white: Colors.grey[400])),
        ],
        backgroundColor: isDarkMode?null:  myThemes.getColor(colorTheme),
      ),
      body:  pageDetails
      ,
      floatingActionButton: lessonNo!='0' ?  FloatingActionButton(
          onPressed: () {
            setState(() {
              getLessonQuestion(lessonNo, language);
            });
          },
          backgroundColor: myThemes.getColor(colorTheme),
          child: Icon(Icons.question_answer),
          tooltip: clsLanguagePreset.float_button_label_open_questionnaire(language)) : null,
    );
  }
}
