#![allow(dead_code)]
#![allow(long_running_const_eval)]
#![allow(unused_imports)]

use crate::character::Character::{self, *};
use crate::condition::Condition::{self, *};
use crate::entity::Entity;
use crate::item::Item::{self, *};
use crate::location::Location::{self, *};
use crate::save_point::SavePoint::{self, *};
use crate::script::Token::{self, *};
use crate::script::script;
use crate::snippet::Snippet::{self, *};
use crate::sound::Sound::{self, *};
use crate::style::Style::{self, *};

#[derive(Clone, Copy, Debug, Eq, PartialEq)]
#[repr(u32)]
pub enum Label {
    OtherGenie,
    OtherUnknown01,
    OtherLeopard,
    OtherWitch,
    OtherDesertTurtle,
    OtherHornedOwl,
    OtherSwallow,
    OtherIncantRedSpell,
    OtherIncantBlueSpell,
    OtherIncantWhiteSpell,
    OtherIncantBlackSpell,
    OtherBookshelf,
    OtherBamBabaBam1,
    OtherBamBabaBam2,
    OtherBamBabaBam3,
    OtherBamBabaBam4,
    OtherStrengthPlus1,
    OtherStrengthPlus2,
    OtherStrengthPlus4,
    OtherStrengthPlus8,
    OtherDefensePlus0,
    OtherDefensePlus1,
    OtherDefensePlus2,
    OtherDefensePlus3,
    OtherEndurancePlus3,
    OtherEndurancePlus5,
    OtherEndurancePlus7,
    OtherEndurancePlus10,
    OtherEndurancePlus15,
    OtherSellGoldBar,
    OtherMagicalHit,
}

use self::Label::*;

const fn find_label(script: &'static [Token<Label>], label: Label) -> usize {
    let mut i = 0;
    while i < script.len() {
        match script[i] {
            Token::Label(l) if l as u8 == label as u8 => return i,
            _ => i += 1,
        };
    }
    unreachable!();
}

pub fn dialog_for_label(index: usize) -> &'static [Token<'static, Label>] {
    &SCRIPTS[INDEXED[index]..]
}

pub fn dialog(index: usize) -> &'static [Token<'static, Label>] {
    &SCRIPTS[INDEXED[index]..]
}

const SCRIPTS: &[Token<Label>] = script![

Label(OtherGenie)
    "Genie" End

Label(OtherUnknown01)
    ToggleCanSpeedUp Style(WhiteOnTransparent) SetOutline(true) End

Label(OtherLeopard)
    "Leopard" End

Label(OtherWitch)
    "Witch" End

Label(OtherDesertTurtle)
    "Desert Turtle" End

Label(OtherHornedOwl)
    "Horned Owl" End

Label(OtherSwallow)
    "Swallow" End

Label(OtherIncantRedSpell)
    PauseSound "Incant the Red Spell." NewLine
    Style(RedOnBlack) IncantSpell("🌝🪿🪲🪿") " Ｃ" Style(WhiteOnBlack) SetOutline(false) NewLine
    "Come in." Wait(30) ResumeSound End

Label(OtherIncantBlueSpell)
    PauseSound "Incant the Blue Spell." NewLine
    Style(BlueOnBlack) IncantSpell("🪿🌝🌝🪲") End

Label(OtherIncantWhiteSpell)
    PauseSound "Incant the White Spell." NewLine
    IncantSpell("🪲🌝🪲🪲🪲🌝") End

Label(OtherIncantBlackSpell)
    PauseSound "Incant the Black Spell." NewLine
    SetOutline(true) Style(BlackOnBlack) IncantSpell("🌝🪲🌝🌝🌝🪲") End

Label(OtherBookshelf)
    "The bookshelf is full of" NewLine
    "difficult-looking books." More Clear
    "Read one?" End

Label(OtherBamBabaBam1)
    "Bam baba bam!" NewLine
    End

Label(OtherBamBabaBam2)
    Wait(15) "Ba" Wait(15) "Ba" Wait(15) "Ba" Wait(15) NewLine
    End

Label(OtherBamBabaBam3)
    "Bam baba bam!" Wait(15) "Ba ba ba!" NewLine
    End

Label(OtherBamBabaBam4)
    "Ba ba ba ba ba ba bam!" NewLine
    End

Label(OtherStrengthPlus1)
    "Strength +1" End

Label(OtherStrengthPlus2)
    "Strength +2" End

Label(OtherStrengthPlus4)
    "Strength +4" End

Label(OtherStrengthPlus8)
    "Strength +8" End

Label(OtherDefensePlus0)
    "Defense +0" End

Label(OtherDefensePlus1)
    "Defense +1" End

Label(OtherDefensePlus2)
    "Defense +2" End

Label(OtherDefensePlus3)
    "Defense +3" End

Label(OtherEndurancePlus3)
    "Endurance +3" End

Label(OtherEndurancePlus5)
    "Endurance +5" End

Label(OtherEndurancePlus7)
    "Endurance +7" End

Label(OtherEndurancePlus10)
    "Endurance +10" End

Label(OtherEndurancePlus15)
    "Endurance +15" End

Label(OtherSellGoldBar)
    NewLine
    "By the way..." Wait(30) NewLine
    "You have a Gold" NewLine
    "Bar with you." More NewLine
    "If you like," NewLine
    "I'll buy it from you." More NewLine
    End

Label(OtherMagicalHit)
    NewLine
    "Magical Hit" End
    ];

pub const INDEXED: &[usize] = &[
    find_label(SCRIPTS, OtherGenie),
    find_label(SCRIPTS, OtherUnknown01),
    find_label(SCRIPTS, OtherLeopard),
    find_label(SCRIPTS, OtherWitch),
    find_label(SCRIPTS, OtherDesertTurtle),
    find_label(SCRIPTS, OtherHornedOwl),
    find_label(SCRIPTS, OtherSwallow),
    find_label(SCRIPTS, OtherIncantRedSpell),
    find_label(SCRIPTS, OtherIncantBlueSpell),
    find_label(SCRIPTS, OtherIncantWhiteSpell),
    find_label(SCRIPTS, OtherIncantBlackSpell),
    find_label(SCRIPTS, OtherBookshelf),
    find_label(SCRIPTS, OtherBamBabaBam1),
    find_label(SCRIPTS, OtherBamBabaBam2),
    find_label(SCRIPTS, OtherBamBabaBam3),
    find_label(SCRIPTS, OtherBamBabaBam4),
    find_label(SCRIPTS, OtherStrengthPlus1),
    find_label(SCRIPTS, OtherStrengthPlus2),
    find_label(SCRIPTS, OtherStrengthPlus4),
    find_label(SCRIPTS, OtherStrengthPlus8),
    find_label(SCRIPTS, OtherDefensePlus0),
    find_label(SCRIPTS, OtherDefensePlus1),
    find_label(SCRIPTS, OtherDefensePlus2),
    find_label(SCRIPTS, OtherDefensePlus3),
    find_label(SCRIPTS, OtherEndurancePlus3),
    find_label(SCRIPTS, OtherEndurancePlus5),
    find_label(SCRIPTS, OtherEndurancePlus7),
    find_label(SCRIPTS, OtherEndurancePlus10),
    find_label(SCRIPTS, OtherEndurancePlus15),
    find_label(SCRIPTS, OtherSellGoldBar),
    find_label(SCRIPTS, OtherMagicalHit),
];
