import 'package:ecosim/src/ecosim/ecosystem_screen.dart';
import 'package:ecosim/src/common/widgets/color_dialog.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:shadcn_ui/shadcn_ui.dart';

import '../common/widgets/flex_app_bar.dart';

// default color providers:
final defaultBoidHealthyColorProvider = StateProvider.autoDispose<Color>(
  (ref) {
    return Colors.white;
  },
);
final defaultBoidUnHealthyColorProvider =
    StateProvider.autoDispose<Color>((ref) {
  return Colors.red;
});
final defaultPredatorHealthyColorProvider =
    StateProvider.autoDispose<Color>((ref) {
  return Colors.purple;
});
final defaultPredatorUnHealthyColorProvider =
    StateProvider.autoDispose<Color>((ref) {
  return Colors.blue;
});

// The Screen where the user sets the parameters
// for the ecosystem simulation
class ParameterScreen extends ConsumerStatefulWidget {
  const ParameterScreen({super.key});

  @override
  ConsumerState<ConsumerStatefulWidget> createState() =>
      _ParameterScreenState();
}

class _ParameterScreenState extends ConsumerState<ParameterScreen> {
  final formKey = GlobalKey<ShadFormState>();

  // Default Parameters Presets:

  // Boids
  final defaultBoidStartCount = 100;
  final defaultBoidTickDamage = 4.0;
  final defaultBoidReplicateInterval = 5.0;
  final defaultBoidReplicateProbability = 0.2;
  final defaultBoidMutationThreshold = 0.8;
  final defaultBoidCollisionRadius = 8.0;
  final defaultBoidMaxHealth = 100.0;

  // Predators
  final defaultPredatorStartCount = 10;
  final defaultPredatorBoidNutrition = 30.0;
  final defaultPredatorCollisionRadius = 10.0;

  // World
  final defaultWorldReplicationRadiusFood = 40.0;
  final defaultWorldReplicationRadiusPoison = 5.0;
  final defaultWorldReplicationRadiusCooldown = 2.0;
  final defaultWorldFoodDecayRate = 0.1;
  final defaultWorldPoisonDecayRate = 0.5;
  final defaultWorldFoodNutrition = 5.0;
  final defaultWorldPoisonDamage = 30.0;
  final defaultWorldWidth = 1300.0;
  final defaultWorldHeight = 730.0;
  final defaultWorldFoodStartCount = 600;
  final defaultWorldPoisonStartCount = 150;

  @override
  Widget build(BuildContext context) {
    final defaultBoidHealthyColor = ref.watch(defaultBoidHealthyColorProvider);
    final defaultBoidUnHealthyColor =
        ref.watch(defaultBoidUnHealthyColorProvider);
    final defaultPredatorHealthyColor =
        ref.watch(defaultPredatorHealthyColorProvider);
    final defaultPredatorUnHealthyColor =
        ref.watch(defaultPredatorUnHealthyColorProvider);

    final theme = ShadTheme.of(context);
    final AppBar appBar = FlexAppBar.styled(
      context,
      centerTitle: true,
      title: const Text('Simulation Parameters'),
      // actions: const <Widget>[AboutIconButton()],
      leading: IconButton(
        // onPressed: () => context.pop(),
        onPressed: () => Navigator.pop(context),
        icon: const Icon(
          Icons.chevron_left,
          size: 38,
        ),
      ),
      blurred: true,
      opacity: 0.5,
      gradient: false,
      hasBorderOnSurface: true,
      scrim: false,
    ).toAppBar();
    return Scaffold(
      extendBodyBehindAppBar: true,
      appBar: appBar,
      body: SingleChildScrollView(
        child: Center(
          child: ConstrainedBox(
            constraints: BoxConstraints(
                maxWidth:
                    MediaQuery.of(context).size.width > 1016 ? 1000 : 500),
            child: Padding(
              padding: const EdgeInsets.all(12.0),
              child: Column(
                children: [
                  const SizedBox(
                    height: 8,
                  ),
                  ShadForm(
                    key: formKey,
                    child: GridView.count(
                      shrinkWrap: true,
                      physics: const NeverScrollableScrollPhysics(),
                      crossAxisCount:
                          MediaQuery.of(context).size.width > 1016 ? 2 : 1,
                      crossAxisSpacing: 16,
                      mainAxisSpacing: 16,
                      childAspectRatio: MediaQuery.of(context).size.width > 1016
                          ? .78
                          : MediaQuery.of(context).size.width > 430
                              ? .7
                              : MediaQuery.of(context).size.width > 390
                                  ? .65
                                  : .5,
                      children: [
                        // boid configuration 1
                        ShadCard(
                          title: Text(
                            'Boids Configuration 1',
                            style: theme.textTheme.h3,
                          ),
                          description: const Text('Configure the boids.'),
                          content: Column(
                            children: [
                              const SizedBox(height: 16),
                              // prey start count
                              ShadInputFormField(
                                id: 'boid_start_count',
                                label: const Text('Boids Start Count'),
                                initialValue: defaultBoidStartCount.toString(),
                                keyboardType: TextInputType.number,
                                inputFormatters: [
                                  FilteringTextInputFormatter.digitsOnly,
                                ],
                                validator: (v) {
                                  if (v.isEmpty) {
                                    return 'Cannot be empty!';
                                  }
                                  if (int.parse(v) < 0) {
                                    return 'Must be larger than 0 or 0.';
                                  }
                                  return null;
                                },
                              ),
                              const SizedBox(height: 16),
                              // prey food nutrition
                              ShadInputFormField(
                                id: 'world_food_nutrition',
                                label: const Text('Food Nutrition'),
                                initialValue:
                                    defaultWorldFoodNutrition.toString(),
                                keyboardType:
                                    const TextInputType.numberWithOptions(
                                  decimal: true,
                                ),
                                inputFormatters: [
                                  FilteringTextInputFormatter.allow(
                                    RegExp(
                                      r'^(\d+)?\.?\d{0,2}',
                                    ),
                                  )
                                ],
                                validator: (v) {
                                  if (double.tryParse(v) == null) {
                                    return 'Must be a valid double value!';
                                  }
                                  if (v.isEmpty) {
                                    return 'Cannot be empty!';
                                  }
                                  if (double.parse(v) < 0) {
                                    return 'Must be larger than 0.';
                                  }
                                  return null;
                                },
                              ),
                              const SizedBox(height: 16),
                              // prey poison damage
                              ShadInputFormField(
                                id: 'world_poison_damage',
                                label: const Text('Poison Damage'),
                                initialValue:
                                    defaultWorldPoisonDamage.toString(),
                                keyboardType:
                                    const TextInputType.numberWithOptions(
                                  decimal: true,
                                ),
                                inputFormatters: [
                                  FilteringTextInputFormatter.allow(
                                    RegExp(
                                      r'^(\d+)?\.?\d{0,2}',
                                    ),
                                  )
                                ],
                                validator: (v) {
                                  if (double.tryParse(v) == null) {
                                    return 'Must be a valid double value!';
                                  }
                                  if (v.isEmpty) {
                                    return 'Cannot be empty!';
                                  }
                                  // if (double.parse(v) < 0) {
                                  //   return 'Must be larger than 0.';
                                  // }
                                  return null;
                                },
                              ),
                              const SizedBox(height: 16),
                              // boid max health
                              ShadInputFormField(
                                id: 'boid_max_health',
                                label: const Text('Max Health'),
                                initialValue: defaultBoidMaxHealth.toString(),
                                keyboardType:
                                    const TextInputType.numberWithOptions(
                                  decimal: true,
                                ),
                                inputFormatters: [
                                  FilteringTextInputFormatter.allow(
                                    RegExp(
                                      r'^(\d+)?\.?\d{0,2}',
                                    ),
                                  )
                                ],
                                validator: (v) {
                                  if (double.tryParse(v) == null) {
                                    return 'Must be a valid double value!';
                                  }
                                  if (v.isEmpty) {
                                    return 'Cannot be empty!';
                                  }
                                  // if (double.parse(v) < 0) {
                                  //   return 'Must be larger than 0.';
                                  // }
                                  return null;
                                },
                              ),
                              const SizedBox(height: 16),
                              // prey healthy color
                              ShadCard(
                                border:
                                    Border.all(width: 2, color: Colors.white),
                                padding: const EdgeInsets.all(0),
                                content: ListTile(
                                  leading: Icon(
                                    Icons.arrow_drop_up,
                                    size: 48,
                                    color: defaultBoidHealthyColor,
                                  ),
                                  title: const Text('Healthy Color'),
                                  trailing: ShadButton(
                                    size: ShadButtonSize.sm,
                                    text: const Text('Edit'),
                                    onPressed: () {
                                      showShadDialog(
                                        context: context,
                                        builder: (context) {
                                          return ColorDialog(
                                            colorProvider:
                                                defaultBoidHealthyColorProvider,
                                          );
                                        },
                                      );
                                    },
                                  ),
                                ),
                              ),
                              const SizedBox(height: 16),
                              // prey unhealthy color
                              ShadCard(
                                border:
                                    Border.all(width: 2, color: Colors.white),
                                padding: const EdgeInsets.all(0),
                                content: ListTile(
                                  leading: Icon(
                                    Icons.arrow_drop_up,
                                    size: 48,
                                    color: defaultBoidUnHealthyColor,
                                  ),
                                  title: const Text('Unhealthy Color'),
                                  trailing: ShadButton(
                                    size: ShadButtonSize.sm,
                                    text: const Text('Edit'),
                                    onPressed: () {
                                      showShadDialog(
                                        context: context,
                                        builder: (context) {
                                          return ColorDialog(
                                            colorProvider:
                                                defaultBoidUnHealthyColorProvider,
                                          );
                                        },
                                      );
                                    },
                                  ),
                                ),
                              ),
                            ],
                          ),
                        ),
                        // boid configuration 2
                        ShadCard(
                          title: Text(
                            'Boids Configuration 2',
                            style: theme.textTheme.h3,
                          ),
                          description: const Text('Configure the boids.'),
                          content: Column(
                            children: [
                              const SizedBox(height: 16),
                              // prey start count
                              ShadInputFormField(
                                id: 'boid_tick_damage',
                                label: const Text('Tick Damage'),
                                initialValue: defaultBoidTickDamage.toString(),
                                keyboardType:
                                    const TextInputType.numberWithOptions(
                                  decimal: true,
                                ),
                                inputFormatters: [
                                  FilteringTextInputFormatter.allow(
                                    RegExp(
                                      r'^(\d+)?\.?\d{0,2}',
                                    ),
                                  )
                                ],
                                validator: (v) {
                                  if (double.tryParse(v) == null) {
                                    return 'Must be a valid double value!';
                                  }
                                  if (v.isEmpty) {
                                    return 'Cannot be empty!';
                                  }
                                  if (double.parse(v) < 0) {
                                    return 'Must be larger than 0.';
                                  }
                                  return null;
                                },
                              ),
                              const SizedBox(height: 16),
                              // prey food nutrition
                              ShadInputFormField(
                                id: 'boid_replicate_interval',
                                label: const Text('Replicate Interval'),
                                initialValue:
                                    defaultBoidReplicateInterval.toString(),
                                keyboardType:
                                    const TextInputType.numberWithOptions(
                                  decimal: true,
                                ),
                                inputFormatters: [
                                  FilteringTextInputFormatter.allow(
                                    RegExp(
                                      r'^(\d+)?\.?\d{0,2}',
                                    ),
                                  )
                                ],
                                validator: (v) {
                                  if (double.tryParse(v) == null) {
                                    return 'Must be a valid double value!';
                                  }
                                  if (v.isEmpty) {
                                    return 'Cannot be empty!';
                                  }
                                  if (double.parse(v) < 0) {
                                    return 'Must be larger than 0.';
                                  }
                                  return null;
                                },
                              ),
                              const SizedBox(height: 16),
                              // prey poison damage
                              ShadInputFormField(
                                id: 'boid_replicate_probability',
                                label: const Text('Replicate Probability'),
                                initialValue:
                                    defaultBoidReplicateProbability.toString(),
                                keyboardType:
                                    const TextInputType.numberWithOptions(
                                  decimal: true,
                                ),
                                inputFormatters: [
                                  FilteringTextInputFormatter.allow(
                                    RegExp(
                                      r'^(\d+)?\.?\d{0,2}',
                                    ),
                                  )
                                ],
                                validator: (v) {
                                  if (double.tryParse(v) == null) {
                                    return 'Must be a valid double value!';
                                  }
                                  if (v.isEmpty) {
                                    return 'Cannot be empty!';
                                  }
                                  if (double.parse(v) < 0) {
                                    return 'Must be larger than 0.';
                                  }
                                  return null;
                                },
                              ),
                              const SizedBox(height: 16),
                              // boid mutation threshold
                              ShadInputFormField(
                                id: 'boid_mutation_threshold',
                                label: const Text('Mutation Threshold'),
                                initialValue:
                                    defaultBoidMutationThreshold.toString(),
                                keyboardType:
                                    const TextInputType.numberWithOptions(
                                  decimal: true,
                                ),
                                inputFormatters: [
                                  FilteringTextInputFormatter.allow(
                                    RegExp(
                                      r'^(\d+)?\.?\d{0,2}',
                                    ),
                                  )
                                ],
                                validator: (v) {
                                  if (double.tryParse(v) == null) {
                                    return 'Must be a valid double value!';
                                  }
                                  if (v.isEmpty) {
                                    return 'Cannot be empty!';
                                  }
                                  if (double.parse(v) < 0) {
                                    return 'Must be larger than 0.';
                                  }
                                  return null;
                                },
                              ),
                              const SizedBox(height: 16),
                              // boid collision radius
                              ShadInputFormField(
                                id: 'boid_collision_radius',
                                label: const Text('Collision Radius'),
                                initialValue:
                                    defaultBoidCollisionRadius.toString(),
                                keyboardType:
                                    const TextInputType.numberWithOptions(
                                  decimal: true,
                                ),
                                inputFormatters: [
                                  FilteringTextInputFormatter.allow(
                                    RegExp(
                                      r'^(\d+)?\.?\d{0,2}',
                                    ),
                                  )
                                ],
                                validator: (v) {
                                  if (double.tryParse(v) == null) {
                                    return 'Must be a valid double value!';
                                  }
                                  if (v.isEmpty) {
                                    return 'Cannot be empty!';
                                  }
                                  if (double.parse(v) < 0) {
                                    return 'Must be larger than 0.';
                                  }
                                  return null;
                                },
                              ),
                            ],
                          ),
                        ),
                        // predator configuration
                        ShadCard(
                          title: Text(
                            'Predators Configuration',
                            style: theme.textTheme.h3,
                          ),
                          description: const Text('Configure the predators.'),
                          content: Column(
                            children: [
                              const SizedBox(height: 16),
                              // predator start count
                              ShadInputFormField(
                                id: 'predator_start_count',
                                label: const Text('Predator Start Count'),
                                placeholder: const Text('data'),
                                description: const Text('desc'),
                                initialValue:
                                    defaultPredatorStartCount.toString(),
                                keyboardType: TextInputType.number,
                                inputFormatters: [
                                  FilteringTextInputFormatter.digitsOnly,
                                ],
                                validator: (v) {
                                  if (v.isEmpty) {
                                    return 'Cannot be empty!';
                                  }
                                  if (int.parse(v) < 0) {
                                    return 'Must be larger than 0 or 0.';
                                  }
                                  return null;
                                },
                              ),
                              const SizedBox(height: 16),
                              // predator boid nutrition
                              ShadInputFormField(
                                id: 'predator_boid_nutrition',
                                label: const Text('Boid Nutrition'),
                                placeholder: const Text('data'),
                                description: const Text('desc'),
                                initialValue:
                                    defaultPredatorBoidNutrition.toString(),
                                keyboardType:
                                    const TextInputType.numberWithOptions(
                                  decimal: true,
                                ),
                                inputFormatters: [
                                  FilteringTextInputFormatter.allow(
                                    RegExp(
                                      r'^(\d+)?\.?\d{0,2}',
                                    ),
                                  )
                                ],
                                validator: (v) {
                                  if (double.tryParse(v) == null) {
                                    return 'Must be a valid double value!';
                                  }
                                  if (v.isEmpty) {
                                    return 'Cannot be empty!';
                                  }
                                  if (double.parse(v) < 0) {
                                    return 'Must be larger than 0.';
                                  }
                                  return null;
                                },
                              ),
                              const SizedBox(height: 16),
                              // predator collision radius
                              ShadInputFormField(
                                id: 'predator_collision_radius',
                                label: const Text('Collision Radius'),
                                placeholder: const Text('data'),
                                description: const Text('desc'),
                                initialValue:
                                    defaultPredatorCollisionRadius.toString(),
                                keyboardType:
                                    const TextInputType.numberWithOptions(
                                  decimal: true,
                                ),
                                inputFormatters: [
                                  FilteringTextInputFormatter.allow(
                                    RegExp(
                                      r'^(\d+)?\.?\d{0,2}',
                                    ),
                                  )
                                ],
                                validator: (v) {
                                  if (double.tryParse(v) == null) {
                                    return 'Must be a valid double value!';
                                  }
                                  if (v.isEmpty) {
                                    return 'Cannot be empty!';
                                  }
                                  if (double.parse(v) < 0) {
                                    return 'Must be larger than 0.';
                                  }
                                  return null;
                                },
                              ),
                              const SizedBox(height: 16),
                              // predator healthy color
                              ShadCard(
                                border:
                                    Border.all(width: 2, color: Colors.white),
                                padding: const EdgeInsets.all(0),
                                content: ListTile(
                                  leading: Icon(
                                    Icons.arrow_drop_up,
                                    size: 48,
                                    color: defaultPredatorHealthyColor,
                                  ),
                                  title: const Text('Healthy Color'),
                                  trailing: ShadButton(
                                    size: ShadButtonSize.sm,
                                    text: const Text('Edit'),
                                    onPressed: () {
                                      showShadDialog(
                                        context: context,
                                        builder: (context) {
                                          return ColorDialog(
                                            colorProvider:
                                                defaultPredatorHealthyColorProvider,
                                          );
                                        },
                                      );
                                    },
                                  ),
                                ),
                              ),
                              const SizedBox(height: 16),
                              // prey unhealthy color
                              ShadCard(
                                border:
                                    Border.all(width: 2, color: Colors.white),
                                padding: const EdgeInsets.all(0),
                                content: ListTile(
                                  leading: Icon(
                                    Icons.arrow_drop_up,
                                    size: 48,
                                    color: defaultPredatorUnHealthyColor,
                                  ),
                                  title: const Text('Unhealthy Color'),
                                  trailing: ShadButton(
                                    size: ShadButtonSize.sm,
                                    text: const Text('Edit'),
                                    onPressed: () {
                                      showShadDialog(
                                        context: context,
                                        builder: (context) {
                                          return ColorDialog(
                                            colorProvider:
                                                defaultPredatorUnHealthyColorProvider,
                                          );
                                        },
                                      );
                                    },
                                  ),
                                ),
                              ),
                            ],
                          ),
                        ),
                        // world configuration 1
                        ShadCard(
                          title: Text(
                            'World Configuration 1',
                            style: theme.textTheme.h3,
                          ),
                          description: const Text('Configure the world.'),
                          content: Column(
                            children: [
                              const SizedBox(height: 16),
                              // world replication radius food
                              ShadInputFormField(
                                id: 'world_replication_radius_food',
                                label: const Text('Replication Radius Food'),
                                placeholder: const Text('data'),
                                // description: const Text('desc'),
                                initialValue: defaultWorldReplicationRadiusFood
                                    .toString(),
                                keyboardType:
                                    const TextInputType.numberWithOptions(
                                  decimal: true,
                                ),
                                inputFormatters: [
                                  FilteringTextInputFormatter.allow(
                                    RegExp(
                                      r'^(\d+)?\.?\d{0,2}',
                                    ),
                                  )
                                ],
                                validator: (v) {
                                  if (double.tryParse(v) == null) {
                                    return 'Must be a valid double value!';
                                  }
                                  if (v.isEmpty) {
                                    return 'Cannot be empty!';
                                  }
                                  if (double.parse(v) < 0) {
                                    return 'Must be larger than 0.';
                                  }
                                  return null;
                                },
                              ),
                              const SizedBox(height: 16),
                              // world replication radius poison
                              ShadInputFormField(
                                id: 'world_replication_radius_poison',
                                label: const Text('Replication Radius Poison'),
                                placeholder: const Text('data'),
                                // description: const Text('desc'),
                                initialValue:
                                    defaultWorldReplicationRadiusPoison
                                        .toString(),
                                keyboardType:
                                    const TextInputType.numberWithOptions(
                                  decimal: true,
                                ),
                                inputFormatters: [
                                  FilteringTextInputFormatter.allow(
                                    RegExp(
                                      r'^(\d+)?\.?\d{0,2}',
                                    ),
                                  )
                                ],
                                validator: (v) {
                                  if (double.tryParse(v) == null) {
                                    return 'Must be a valid double value!';
                                  }
                                  if (v.isEmpty) {
                                    return 'Cannot be empty!';
                                  }
                                  if (double.parse(v) < 0) {
                                    return 'Must be larger than 0.';
                                  }
                                  return null;
                                },
                              ),
                              const SizedBox(height: 16),
                              // world replication cooldown
                              ShadInputFormField(
                                id: 'world_replication_radius_cooldown',
                                label:
                                    const Text('Replication Radius Cooldown'),
                                placeholder: const Text('data'),
                                // description: const Text('desc'),
                                initialValue:
                                    defaultWorldReplicationRadiusCooldown
                                        .toString(),
                                keyboardType:
                                    const TextInputType.numberWithOptions(
                                  decimal: true,
                                ),
                                inputFormatters: [
                                  FilteringTextInputFormatter.allow(
                                    RegExp(
                                      r'^(\d+)?\.?\d{0,2}',
                                    ),
                                  )
                                ],
                                validator: (v) {
                                  if (double.tryParse(v) == null) {
                                    return 'Must be a valid double value!';
                                  }
                                  if (v.isEmpty) {
                                    return 'Cannot be empty!';
                                  }
                                  if (double.parse(v) < 0) {
                                    return 'Must be larger than 0.';
                                  }
                                  return null;
                                },
                              ),
                              const SizedBox(height: 16),
                              // world food decay rate
                              ShadInputFormField(
                                id: 'world_food_decay_rate',
                                label: const Text('Food Decay Rate'),
                                placeholder: const Text('data'),
                                // description: const Text('desc'),
                                initialValue:
                                    defaultWorldFoodDecayRate.toString(),
                                keyboardType:
                                    const TextInputType.numberWithOptions(
                                  decimal: true,
                                ),
                                inputFormatters: [
                                  FilteringTextInputFormatter.allow(
                                    RegExp(
                                      r'^(\d+)?\.?\d{0,2}',
                                    ),
                                  )
                                ],
                                validator: (v) {
                                  if (double.tryParse(v) == null) {
                                    return 'Must be a valid double value!';
                                  }
                                  if (v.isEmpty) {
                                    return 'Cannot be empty!';
                                  }
                                  if (double.parse(v) < 0) {
                                    return 'Must be larger than 0.';
                                  }
                                  return null;
                                },
                              ),
                              const SizedBox(height: 16),
                              // world poison decay rate
                              ShadInputFormField(
                                id: 'world_poison_decay_rate',
                                label: const Text('Poison Decay Rate'),
                                placeholder: const Text('data'),
                                // description: const Text('desc'),
                                initialValue:
                                    defaultWorldPoisonDecayRate.toString(),
                                keyboardType:
                                    const TextInputType.numberWithOptions(
                                  decimal: true,
                                ),
                                inputFormatters: [
                                  FilteringTextInputFormatter.allow(
                                    RegExp(
                                      r'^(\d+)?\.?\d{0,2}',
                                    ),
                                  )
                                ],
                                validator: (v) {
                                  if (double.tryParse(v) == null) {
                                    return 'Must be a valid double value!';
                                  }
                                  if (v.isEmpty) {
                                    return 'Cannot be empty!';
                                  }
                                  if (double.parse(v) < 0) {
                                    return 'Must be larger than 0.';
                                  }
                                  return null;
                                },
                              ),
                              const SizedBox(height: 16),
                            ],
                          ),
                        ),
                        // world configuration 2
                        ShadCard(
                          title: Text(
                            'World Configuration 2',
                            style: theme.textTheme.h3,
                          ),
                          description: const Text('Configure the world.'),
                          content: Column(
                            children: [
                              const SizedBox(height: 16),
                              // world width
                              ShadInputFormField(
                                id: 'world_width',
                                label: const Text('World Width'),
                                placeholder: const Text('data'),
                                // description: const Text('desc'),
                                initialValue: defaultWorldWidth.toString(),
                                keyboardType:
                                    const TextInputType.numberWithOptions(
                                  decimal: true,
                                ),
                                inputFormatters: [
                                  FilteringTextInputFormatter.allow(
                                    RegExp(
                                      r'^(\d+)?\.?\d{0,2}',
                                    ),
                                  )
                                ],
                                validator: (v) {
                                  if (double.tryParse(v) == null) {
                                    return 'Must be a valid double value!';
                                  }
                                  if (v.isEmpty) {
                                    return 'Cannot be empty!';
                                  }
                                  if (double.parse(v) < 0) {
                                    return 'Must be larger than 0.';
                                  }
                                  return null;
                                },
                              ),
                              const SizedBox(height: 16),
                              // world height
                              ShadInputFormField(
                                id: 'world_height',
                                label: const Text('World Height'),
                                placeholder: const Text('data'),
                                // description: const Text('desc'),
                                initialValue: defaultWorldHeight.toString(),
                                keyboardType:
                                    const TextInputType.numberWithOptions(
                                  decimal: true,
                                ),
                                inputFormatters: [
                                  FilteringTextInputFormatter.allow(
                                    RegExp(
                                      r'^(\d+)?\.?\d{0,2}',
                                    ),
                                  )
                                ],
                                validator: (v) {
                                  if (double.tryParse(v) == null) {
                                    return 'Must be a valid double value!';
                                  }
                                  if (v.isEmpty) {
                                    return 'Cannot be empty!';
                                  }
                                  if (double.parse(v) < 0) {
                                    return 'Must be larger than 0.';
                                  }
                                  return null;
                                },
                              ),
                              const SizedBox(height: 16),
                              // world food start count
                              ShadInputFormField(
                                id: 'world_food_start_count',
                                label: const Text('Food Start Count'),
                                placeholder: const Text('data'),
                                // description: const Text('desc'),
                                initialValue:
                                    defaultWorldFoodStartCount.toString(),
                                keyboardType:
                                    const TextInputType.numberWithOptions(
                                  decimal: true,
                                ),
                                inputFormatters: [
                                  FilteringTextInputFormatter.digitsOnly
                                ],
                                validator: (v) {
                                  if (int.tryParse(v) == null) {
                                    return 'Must be a valid int value!';
                                  }
                                  if (v.isEmpty) {
                                    return 'Cannot be empty!';
                                  }
                                  if (double.parse(v) <= 0) {
                                    return 'Must be larger than 0 or 0.';
                                  }
                                  return null;
                                },
                              ),
                              const SizedBox(height: 16),
                              // world poison start count
                              ShadInputFormField(
                                id: 'world_poison_start_count',
                                label: const Text('Poison Start Count'),
                                placeholder: const Text('data'),
                                // description: const Text('desc'),
                                initialValue:
                                    defaultWorldPoisonStartCount.toString(),
                                keyboardType:
                                    const TextInputType.numberWithOptions(
                                  decimal: true,
                                ),
                                inputFormatters: [
                                  FilteringTextInputFormatter.digitsOnly
                                ],
                                validator: (v) {
                                  if (int.tryParse(v) == null) {
                                    return 'Must be a valid int value!';
                                  }
                                  if (v.isEmpty) {
                                    return 'Cannot be empty!';
                                  }
                                  if (double.parse(v) <= 0) {
                                    return 'Must be larger than 0 or 0.';
                                  }
                                  return null;
                                },
                              ),
                              const SizedBox(height: 16),
                            ],
                          ),
                        ),
                      ],
                    ),
                  ),
                  const SizedBox(
                    height: 12,
                  ),
                  ShadButton(
                    text: const Text('Start Simulaton'),
                    onPressed: () {
                      if (formKey.currentState!.saveAndValidate()) {
                        debugPrint(formKey.currentState!.value.toString());
                        debugPrint('Validation Succeeded :)');
                        // Launch the ecosystem simulation with
                        // the users input parameters
                        Navigator.push(
                          context,
                          MaterialPageRoute(
                            builder: (context) => EcosystemSimulationScreen(
                              boidStartCount: int.parse(
                                formKey.currentState!.value['boid_start_count'],
                              ),
                              worldFoodNutrition: double.parse(
                                formKey.currentState!
                                    .value['world_food_nutrition'],
                              ),
                              worldPoisonDamage: double.parse(
                                formKey
                                    .currentState!.value['world_poison_damage'],
                              ),
                              boidHealthyColor: defaultBoidHealthyColor,
                              boidUnhealthyColor: defaultBoidUnHealthyColor,
                              predatorStartCount: int.parse(
                                formKey.currentState!
                                    .value['predator_start_count'],
                              ),
                              predatorBoidNutrition: double.parse(
                                formKey.currentState!
                                    .value['predator_boid_nutrition'],
                              ),
                              predatorHealthyColor: defaultPredatorHealthyColor,
                              predatorUnhealthyColor:
                                  defaultPredatorUnHealthyColor,
                              worldReplicationRadiusFood: double.parse(
                                formKey.currentState!
                                    .value['world_replication_radius_food'],
                              ),
                              worldReplicationRadiusPoison: double.parse(
                                formKey.currentState!
                                    .value['world_replication_radius_poison'],
                              ),
                              worldReplicationRadiusCooldown: double.parse(
                                formKey.currentState!
                                    .value['world_replication_radius_cooldown'],
                              ),
                              worldFoodDecayRate: double.parse(
                                formKey.currentState!
                                    .value['world_food_decay_rate'],
                              ),
                              worldPoisonDecayRate: double.parse(
                                formKey.currentState!
                                    .value['world_poison_decay_rate'],
                              ),
                              worldWidth: double.parse(
                                formKey.currentState!.value['world_width'],
                              ),
                              worldHeight: double.parse(
                                formKey.currentState!.value['world_height'],
                              ),
                              worldFoodStartCount: int.parse(
                                formKey.currentState!
                                    .value['world_food_start_count'],
                              ),
                              worldPoisonStartCount: int.parse(
                                formKey.currentState!
                                    .value['world_poison_start_count'],
                              ),
                              boidTickDamage: double.parse(
                                formKey.currentState!.value['boid_tick_damage'],
                              ),
                              boidReplicateInterval: double.parse(
                                formKey.currentState!
                                    .value['boid_replicate_interval'],
                              ),
                              boidReplicateProbability: double.parse(
                                formKey.currentState!
                                    .value['boid_replicate_probability'],
                              ),
                              boidMutationThreshold: double.parse(
                                formKey.currentState!
                                    .value['boid_mutation_threshold'],
                              ),
                              boidCollisionRadius: double.parse(
                                formKey.currentState!
                                    .value['boid_collision_radius'],
                              ),
                              predatorCollisionRadius: double.parse(
                                formKey.currentState!
                                    .value['predator_collision_radius'],
                              ),
                              boidMaxHealth: double.parse(
                                formKey.currentState!.value['boid_max_health'],
                              ),
                            ),
                          ),
                        );
                      } else {
                        debugPrint('Validation Failed :(');
                      }
                    },
                  ),
                  const SizedBox(
                    height: 32,
                  ),
                ],
              ),
            ),
          ),
        ),
      ),
    );
  }
}
