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

final colorSliderSelectionProvider = StateProvider<Color>((ref) {
  return Colors.red;
});

class ColorDialog extends ConsumerWidget {
  const ColorDialog({
    required this.colorProvider,
    super.key,
  });

  final AutoDisposeStateProvider<Color> colorProvider;

  @override
  Widget build(BuildContext context, WidgetRef ref) {
    // final selectedColor = ref.watch(colorSliderSelectionProvider);
    // ref.read(colorSliderSelectionProvider).r

    return ShadDialog(
      title: const Text(
        'Edit Boid Healthy Color',
      ),
      description: const Text(
        'Change the boids healthy color.',
      ),
      content: Column(
        children: [
          const SizedBox(height: 16),
          const ColorSlider(),
          const SizedBox(
            height: 16,
          ),
          ShadButton(
            text: const Text('Set Color'),
            onPressed: () {
              ref.read(colorProvider.notifier).state =
                  ref.read(colorSliderSelectionProvider);
              // reset to start color
              ref.read(colorSliderSelectionProvider.notifier).state =
                  Colors.red;
              Navigator.of(context).pop();
            },
          ),
        ],
      ),
    );
  }
}
