import 'package:ecosim/src/benchmark/benchmark_screen.dart';
import 'package:ecosim/src/ecosim/params_screen.dart';
import 'package:ecosim/src/seeking/seeking_screen.dart';
import 'package:flutter/material.dart';
import 'package:shadcn_ui/shadcn_ui.dart';

// Start screen of the application
// Here the user can select which simulation
// they want to run
class MainScreen extends StatelessWidget {
  const MainScreen({super.key});

  @override
  Widget build(BuildContext context) {
    final theme = ShadTheme.of(context);
    return Scaffold(
      appBar: AppBar(
        title: Text(
          'Ecosystem Simulation',
          style: theme.textTheme.h3,
        ),
      ),
      body: SingleChildScrollView(
        child: Center(
          child: Column(
            children: [
              const SizedBox(height: 32),
              ShadButton(
                onPressed: () {
                  Navigator.push(
                    context,
                    MaterialPageRoute(
                      builder: (context) => const ParameterScreen(),
                    ),
                  );
                },
                text: const Text("Start Ecosystem Simulation"),
              ),
              const SizedBox(height: 32),
              const Divider(),
              const SizedBox(height: 16),
              Text(
                'Other Simulation Demos',
                style: theme.textTheme.lead,
              ),
              const SizedBox(height: 16),
              ShadButton(
                onPressed: () {
                  Navigator.push(
                    context,
                    MaterialPageRoute(
                      builder: (context) => const SeekingScreen(),
                    ),
                  );
                },
                text: const Text("Seeking a Target"),
              ),
              const SizedBox(height: 16),
              ShadButton(
                onPressed: () {
                  showShadDialog(
                      context: context,
                      builder: (context) {
                        final formKey = GlobalKey<ShadFormState>();
                        return ShadDialog(
                          title: const Text('Set Benchmark Boid Count'),
                          content: Column(
                            children: [
                              ShadForm(
                                key: formKey,
                                child: ShadInputFormField(
                                  label: const Text('Boid Count'),
                                  id: 'benchmark_boid_count',
                                  initialValue: '500',
                                ),
                              ),
                              ShadButton(
                                text: const Text('Start Benchmark'),
                                onPressed: () {
                                  Navigator.push(
                                    context,
                                    MaterialPageRoute(
                                      builder: (context) =>
                                          BenchmarkSimulationScreen(
                                        boids: int.parse(formKey.currentState!
                                            .value['benchmark_boid_count']),
                                      ),
                                    ),
                                  );
                                },
                              )
                            ],
                          ),
                        );
                      });
                },
                text: const Text("Benchmark"),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
