import 'package:flutter/material.dart';
import 'package:wolf_3d_dart/wolf_3d_data_types.dart';
import 'package:wolf_3d_flutter/wolf_3d_flutter.dart';

String formatGalleryGameTitle(GameVersion version) {
  switch (version) {
    case GameVersion.shareware:
      return 'SHAREWARE';
    case GameVersion.retail:
      return 'RETAIL';
    case GameVersion.spearOfDestiny:
      return 'SPEAR OF DESTINY';
    case GameVersion.spearOfDestinyDemo:
      return 'SOD DEMO';
  }
}

class GalleryGameSelector extends StatelessWidget {
  final Wolf3d wolf3d;
  final WolfensteinData selectedGame;
  final ValueChanged<WolfensteinData> onSelected;

  const GalleryGameSelector({
    super.key,
    required this.wolf3d,
    required this.selectedGame,
    required this.onSelected,
  });

  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: const EdgeInsets.only(right: 12),
      child: Center(
        child: DropdownButtonHideUnderline(
          child: DropdownButton<WolfensteinData>(
            value: selectedGame,
            borderRadius: BorderRadius.circular(8),
            dropdownColor: Theme.of(context).colorScheme.surface,
            iconEnabledColor: Theme.of(context).colorScheme.onSurface,
            onChanged: (WolfensteinData? game) {
              if (game != null) {
                onSelected(game);
              }
            },
            items: wolf3d.availableGames.map((WolfensteinData game) {
              return DropdownMenuItem<WolfensteinData>(
                value: game,
                child: Text(formatGalleryGameTitle(game.version)),
              );
            }).toList(),
          ),
        ),
      ),
    );
  }
}
