import 'package:flutter/material.dart';

void main() {
  runApp(UnixApp());
}

class UnixApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'UNIX App',
      debugShowCheckedModeBanner: false,
      initialRoute: '/',
      routes: {
        '/': (context) => WelcomePage(),
        '/selection': (context) => SelectionPage(),
      },
      onGenerateRoute: (settings) {
        if (settings.name == '/development') {
          final args = settings.arguments as Map<String, dynamic>;
          return MaterialPageRoute(
            builder: (context) {
              return DevelopmentPage(
                selectedSubjects: args['selectedSubjects'],
              );
            },
          );
        }
        assert(false, 'Need to implement ${settings.name}');
        return null;
      },
      theme: ThemeData(
        fontFamily: 'Involve', // Set the default font family here
        // Optionally, define text themes to specify styles for different text types
        textTheme: TextTheme(
          bodyLarge: TextStyle(color: Colors.black),
          bodyMedium: TextStyle(color: Colors.black),
          // Define other text styles if needed
        ),
      ),
    );
  }
}

class WelcomePage extends StatelessWidget {
  final Color darkAccent = Color.fromARGB(255, 0, 0, 0); // Dark blue

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor:
          Color.fromARGB(255, 255, 255, 240), // Fully opaque light color
      body: Center(
        child: Padding(
          padding: const EdgeInsets.all(16.0),
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              Text(
                'Добро',
                style: TextStyle(
                    fontSize: 32,
                    color: darkAccent,
                    fontWeight: FontWeight.bold),
              ),
              Text(
                'пожаловать',
                style: TextStyle(
                    fontSize: 32,
                    color: darkAccent,
                    fontWeight: FontWeight.bold),
              ),
              Text(
                'в',
                style: TextStyle(
                    fontSize: 32,
                    color: darkAccent,
                    fontWeight: FontWeight.bold),
              ),
              Text(
                'UNIX',
                style: TextStyle(
                    fontSize: 32,
                    color: darkAccent,
                    fontWeight: FontWeight.bold),
              ),
              SizedBox(height: 16), // Added spacing for better layout
              Text(
                'Давай выберем твои предметы',
                style: TextStyle(
                  fontSize: 17,
                  color: darkAccent,
                  height: 1.5,
                ),
                textAlign: TextAlign.center, // Center the text
              ),
              SizedBox(height: 30),
              ElevatedButton(
                onPressed: () {
                  Navigator.pushNamed(context, '/selection');
                },
                child: Text(
                  'Начать',
                  style: TextStyle(
                      fontSize: 18, color: Color.fromARGB(255, 255, 255, 240)),
                ),
                style: ElevatedButton.styleFrom(
                  backgroundColor: darkAccent, // Button background color
                  padding:
                      EdgeInsets.symmetric(horizontal: 50.0, vertical: 15.0),
                  shape: RoundedRectangleBorder(
                    borderRadius: BorderRadius.circular(8.0),
                  ),
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }
}

class SelectionPage extends StatefulWidget {
  @override
  _SelectionPageState createState() => _SelectionPageState();
}

class _SelectionPageState extends State<SelectionPage> {
  final Color darkAccent = Color.fromARGB(255, 0, 0, 0); // Simple dark
  final Color darkPrimary = Color.fromARGB(
      255, 52, 49, 49); // Fully opaque dark green for inactive elements

  // State variables for switches and sliders
  bool russianSelected = false;
  bool mathSelected = false;
  bool informaticsSelected = false;

  double russianValue = 50;
  double mathValue = 50;
  double informaticsValue = 50;

  // Method to collect selected subjects and their scores
  Map<String, double> _getSelectedSubjects() {
    Map<String, double> selected = {};
    if (russianSelected) {
      selected['Русский'] = russianValue;
    }
    if (mathSelected) {
      selected['Математика'] = mathValue;
    }
    if (informaticsSelected) {
      selected['Информатика'] = informaticsValue;
    }
    return selected;
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Color.fromARGB(255, 255, 255, 240), // Fully opaque white
      appBar: AppBar(
        title: Text(
          'Выбор предметов',
          style: TextStyle(color: darkAccent),
        ),
        backgroundColor:
            Color.fromARGB(255, 255, 255, 240), // Fully opaque white background
        elevation: 0, // Remove shadow
        leading: IconButton(
          icon: Icon(Icons.arrow_back, color: darkAccent),
          onPressed: () {
            Navigator.pop(context);
          },
        ),
      ),
      body: SingleChildScrollView(
        child: Padding(
          padding: const EdgeInsets.all(16.0),
          child: Column(
            children: [
              SubjectBlock(
                title: 'Русский',
                isSelected: russianSelected,
                onToggle: (value) {
                  setState(() {
                    russianSelected = value;
                  });
                },
                sliderValue: russianValue,
                onSliderChange: (value) {
                  setState(() {
                    russianValue = value;
                  });
                },
                darkAccent: darkAccent,
                darkPrimary: darkAccent,
              ),
              SizedBox(height: 20),
              SubjectBlock(
                title: 'Математика',
                isSelected: mathSelected,
                onToggle: (value) {
                  setState(() {
                    mathSelected = value;
                  });
                },
                sliderValue: mathValue,
                onSliderChange: (value) {
                  setState(() {
                    mathValue = value;
                  });
                },
                darkAccent: darkAccent,
                darkPrimary: darkAccent,
              ),
              SizedBox(height: 20),
              SubjectBlock(
                title: 'Информатика',
                isSelected: informaticsSelected,
                onToggle: (value) {
                  setState(() {
                    informaticsSelected = value;
                  });
                },
                sliderValue: informaticsValue,
                onSliderChange: (value) {
                  setState(() {
                    informaticsValue = value;
                  });
                },
                darkAccent: darkAccent,
                darkPrimary: darkAccent,
              ),
              SizedBox(height: 40),
              ElevatedButton(
                onPressed: () {
                  Map<String, double> selectedSubjects = _getSelectedSubjects();
                  Navigator.pushNamed(
                    context,
                    '/development',
                    arguments: {'selectedSubjects': selectedSubjects},
                  );
                },
                child: Text(
                  'Продолжить',
                  style: TextStyle(
                      fontSize: 18,
                      color: const Color.fromARGB(255, 255, 255, 255)),
                ),
                style: ElevatedButton.styleFrom(
                  backgroundColor: darkAccent, // Button background color
                  padding:
                      EdgeInsets.symmetric(horizontal: 50.0, vertical: 15.0),
                  shape: RoundedRectangleBorder(
                    borderRadius: BorderRadius.circular(8.0),
                  ),
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }
}

class SubjectBlock extends StatelessWidget {
  final String title;
  final bool isSelected;
  final Function(bool) onToggle;
  final double sliderValue;
  final Function(double) onSliderChange;
  final Color darkAccent;
  final Color darkPrimary;

  SubjectBlock({
    required this.title,
    required this.isSelected,
    required this.onToggle,
    required this.sliderValue,
    required this.onSliderChange,
    required this.darkAccent,
    required this.darkPrimary,
  });

  @override
  Widget build(BuildContext context) {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
            Text(
              title,
              style: TextStyle(fontSize: 20, color: darkAccent),
            ),
            Switch(
              value: isSelected,
              onChanged: onToggle,
              activeColor: darkAccent,
              activeTrackColor: darkAccent.withOpacity(0.5),
              inactiveThumbColor: darkAccent,
              inactiveTrackColor: darkPrimary.withOpacity(0.5),
            ),
          ],
        ),
        if (isSelected)
          Padding(
            padding: const EdgeInsets.only(top: 10.0),
            child: Slider(
              value: sliderValue,
              min: 1,
              max: 100,
              divisions: 99,
              label: sliderValue.round().toString(),
              activeColor: darkAccent,
              inactiveColor: darkPrimary,
              onChanged: onSliderChange,
            ),
          ),
      ],
    );
  }
}

class DevelopmentPage extends StatelessWidget {
  final Map<String, double> selectedSubjects;
  final Color customTextColor = Color.fromARGB(255, 0, 0, 0); // Fully dark

  DevelopmentPage({required this.selectedSubjects});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Color.fromARGB(255, 255, 255, 240),
      appBar: AppBar(
        title: Text(
          'Ваши результаты',
          style: TextStyle(color: customTextColor),
        ),
        backgroundColor:
            Color.fromARGB(255, 255, 255, 240), // Fully opaque white background
        elevation: 0, // Remove shadow
        leading: IconButton(
          icon: Icon(Icons.arrow_back, color: customTextColor),
          onPressed: () {
            Navigator.pop(context);
          },
        ),
      ),
      body: Padding(
        padding: const EdgeInsets.all(16.0),
        child: selectedSubjects.isNotEmpty
            ? ListView.builder(
                itemCount: selectedSubjects.length,
                itemBuilder: (context, index) {
                  String subject = selectedSubjects.keys.elementAt(index);
                  double score = selectedSubjects[subject]!;
                  return Card(
                    color: Color.fromARGB(255, 31, 31, 31),
                    margin: EdgeInsets.symmetric(vertical: 8.0),
                    child: ListTile(
                      title: Text(
                        subject,
                        style: TextStyle(
                          fontSize: 20,
                          color: customTextColor,
                          fontWeight: FontWeight.bold,
                        ),
                      ),
                      subtitle: Text(
                        'Баллы: ${score.toInt()}',
                        style: TextStyle(
                          fontSize: 16,
                          color: customTextColor,
                        ),
                      ),
                    ),
                  );
                },
              )
            : Center(
                child: Text(
                  'Нет выбранных предметов.',
                  style: TextStyle(
                    fontSize: 20,
                    color: customTextColor,
                  ),
                ),
              ),
      ),
    );
  }
}


replace slider's with text field's for all