import 'package:wolf_3d_dart/src/data_types/difficulty.dart';
import 'package:wolf_3d_dart/src/registry/keys/menu_pic_key.dart';
import 'package:wolf_3d_dart/src/registry/modules/menu_pic_module.dart';

/// Built-in menu-picture module for Spear of Destiny demo/shareware (`.SDM`).
///
/// Picture indices are derived from `GFXV_SDM.H` (`chunkId - STARTPICS`).
class SpearDemoMenuPicModule extends MenuPicModule {
  const SpearDemoMenuPicModule();

  static final Map<MenuPicKey, int> _indices = {
    MenuPicKey.title: 71, // TITLE1PIC
    MenuPicKey.credits: 75, // CREDITSPIC
    MenuPicKey.pg13: 74, // PG13PIC

    MenuPicKey.controlBackground: 12, // C_CONTROLPIC
    MenuPicKey.footer: 1, // C_MOUSELBACKPIC
    MenuPicKey.heading: 0, // C_BACKDROPPIC
    MenuPicKey.optionsLabel: 13, // C_OPTIONSPIC
    MenuPicKey.customizeLabel: 6, // C_CUSTOMIZEPIC

    MenuPicKey.cursorActive: 2, // C_CURSOR1PIC
    MenuPicKey.cursorInactive: 3, // C_CURSOR2PIC
    MenuPicKey.markerSelected: 5, // C_SELECTEDPIC
    MenuPicKey.markerUnselected: 4, // C_NOTSELECTEDPIC

    MenuPicKey.difficultyBaby: 18, // C_BABYMODEPIC
    MenuPicKey.difficultyEasy: 19, // C_EASYPIC
    MenuPicKey.difficultyNormal: 20, // C_NORMALPIC
    MenuPicKey.difficultyHard: 21, // C_HARDPIC
  };

  @override
  MenuPicRef? resolve(MenuPicKey key) {
    final index = _indices[key];
    return index != null ? MenuPicRef(index) : null;
  }

  @override
  MenuPicKey episodeKey(int episodeIndex) {
    return MenuPicKey.episode1;
  }

  @override
  MenuPicKey difficultyKey(Difficulty difficulty) {
    return switch (difficulty) {
      Difficulty.baby => MenuPicKey.difficultyBaby,
      Difficulty.easy => MenuPicKey.difficultyEasy,
      Difficulty.medium => MenuPicKey.difficultyNormal,
      Difficulty.hard => MenuPicKey.difficultyHard,
    };
  }
}
