import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';

import '../../../../../common/settings/app_settings.dart';
import '../../../../../constants/colors.dart';

class ColorSeedButton extends ConsumerWidget {
  const ColorSeedButton({super.key});

  @override
  Widget build(BuildContext context, WidgetRef ref) {
    return PopupMenuButton(
      tooltip: 'Select a seed color',
      shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)),
      itemBuilder: (context) {
        return List.generate(ColorSeed.values.length, (index) {
          ColorSeed currentColor = ColorSeed.values[index];
          return PopupMenuItem(
            onTap: () {
              ref
                  .read(colorSeedSelectedProvider.notifier)
                  .setColorSeed(currentColor);
            },
            child: TextButton.icon(
              onPressed: null,
              icon: Icon(
                Icons.color_lens,
                color: currentColor.color,
              ),
              label: Text(
                currentColor.label,
                style: TextStyle(
                    color: Theme.of(context).textTheme.bodyLarge!.color),
              ),
            ),
          );
        });
      },
      child: ListTile(
        leading: Icon(
          Icons.palette,
          color: Theme.of(context).colorScheme.onSurfaceVariant,
        ),
        title: const Text('Set color seed'),
        subtitle: const Text('Select the Material theme color seed.'),
      ),
    );
  }
}
