// === OPTIMIZED STORY PROTOTYPE WITH CENTRALIZED VOCABULARY ===
// Story content with single vocabulary definition that works across all games

window.ContentModules = window.ContentModules || {};

window.ContentModules.StoryPrototypeOptimized = {
    name: "The Magical Library (Optimized)",
    description: "Adventure story with centralized vocabulary system",
    difficulty: "intermediate",
    language: "en-US",

    // Centralized vocabulary - defined once, used everywhere
    vocabulary: {
        // Key words for the story
        "library": {
            translation: "bibliothèque",
            user_language: "bibliothèque",
            pronunciation: "/ˈlaɪbrəri/",
            type: "noun"
        },
        "magical": {
            translation: "magique",
            user_language: "magique",
            pronunciation: "/ˈmædʒɪkəl/",
            type: "adjective"
        },
        "discovered": {
            translation: "découvert",
            pronunciation: "/dɪˈskʌvərd/",
            type: "verb"
        },
        "ancient": {
            translation: "ancien",
            pronunciation: "/ˈeɪnʃənt/",
            type: "adjective"
        },
        "mysterious": {
            translation: "mystérieux",
            pronunciation: "/mɪˈstɪriəs/",
            type: "adjective"
        },
        "adventure": {
            translation: "aventure",
            pronunciation: "/ədˈventʃər/",
            type: "noun"
        },
        "explore": {
            translation: "explorer",
            pronunciation: "/ɪkˈsplɔːr/",
            type: "verb"
        },
        "hidden": {
            translation: "caché",
            pronunciation: "/ˈhɪdn/",
            type: "adjective"
        },
        "secret": {
            translation: "secret",
            pronunciation: "/ˈsiːkrət/",
            type: "adjective"
        },
        "passage": {
            translation: "passage",
            pronunciation: "/ˈpæsɪdʒ/",
            type: "noun"
        },
        "glowing": {
            translation: "brillant",
            pronunciation: "/ˈɡloʊɪŋ/",
            type: "adjective"
        },
        "symbols": {
            translation: "symboles",
            pronunciation: "/ˈsɪmbəlz/",
            type: "noun"
        },
        "whispered": {
            translation: "chuchoté",
            pronunciation: "/ˈwɪspərd/",
            type: "verb"
        },
        "carefully": {
            translation: "prudemment",
            pronunciation: "/ˈkɛrfəli/",
            type: "adverb"
        },
        "approached": {
            translation: "approché",
            pronunciation: "/əˈproʊtʃt/",
            type: "verb"
        },
        "magnificent": {
            translation: "magnifique",
            pronunciation: "/mæɡˈnɪfɪsənt/",
            type: "adjective"
        },
        "chamber": {
            translation: "chambre",
            pronunciation: "/ˈtʃeɪmbər/",
            type: "noun"
        },
        "floating": {
            translation: "flottant",
            pronunciation: "/ˈfloʊtɪŋ/",
            type: "adjective"
        },
        "shelves": {
            translation: "étagères",
            pronunciation: "/ʃɛlvz/",
            type: "noun"
        },
        "reaching": {
            translation: "atteignant",
            pronunciation: "/ˈriːtʃɪŋ/",
            type: "verb"
        },
        "touched": {
            translation: "touché",
            pronunciation: "/tʌtʃt/",
            type: "verb"
        },
        "spine": {
            translation: "dos (du livre)",
            pronunciation: "/spaɪn/",
            type: "noun"
        },
        "shimmered": {
            translation: "scintillé",
            pronunciation: "/ˈʃɪmərd/",
            type: "verb"
        },
        "transformed": {
            translation: "transformé",
            pronunciation: "/trænsˈfɔːrmd/",
            type: "verb"
        },
        "portal": {
            translation: "portail",
            pronunciation: "/ˈpɔːrtl/",
            type: "noun"
        },
        "worlds": {
            translation: "mondes",
            pronunciation: "/wɜːrldz/",
            type: "noun"
        },
        "imagination": {
            translation: "imagination",
            pronunciation: "/ɪˌmædʒɪˈneɪʃən/",
            type: "noun"
        },
        "realized": {
            translation: "réalisé",
            pronunciation: "/ˈriːəlaɪzd/",
            type: "verb"
        },
        "ordinary": {
            translation: "ordinaire",
            pronunciation: "/ˈɔːrdneri/",
            type: "adjective"
        },
        "gateway": {
            translation: "passerelle",
            pronunciation: "/ˈɡeɪtweɪ/",
            type: "noun"
        },
        "infinite": {
            translation: "infini",
            pronunciation: "/ˈɪnfɪnɪt/",
            type: "adjective"
        },
        "possibilities": {
            translation: "possibilités",
            pronunciation: "/ˌpɑːsəˈbɪlətiz/",
            type: "noun"
        },
        "knowledge": {
            translation: "connaissance",
            pronunciation: "/ˈnɑːlɪdʒ/",
            type: "noun"
        },
        "wisdom": {
            translation: "sagesse",
            pronunciation: "/ˈwɪzdəm/",
            type: "noun"
        },
        "keeper": {
            translation: "gardien",
            pronunciation: "/ˈkiːpər/",
            type: "noun"
        },
        "guardian": {
            translation: "gardien",
            pronunciation: "/ˈɡɑːrdiən/",
            type: "noun"
        },
        "appeared": {
            translation: "apparu",
            pronunciation: "/əˈpɪrd/",
            type: "verb"
        },
        "welcomed": {
            translation: "accueilli",
            pronunciation: "/ˈwɛlkəmd/",
            type: "verb"
        },
        "journey": {
            translation: "voyage",
            pronunciation: "/ˈdʒɜːrni/",
            type: "noun"
        },
        "beginning": {
            translation: "début",
            pronunciation: "/bɪˈɡɪnɪŋ/",
            type: "noun"
        }
    },

    // Story content - just the sentences, no word-by-word translations
    story: {
        title: "The Magical Library",
        chapters: [
            {
                title: "Chapter 1: The Discovery",
                sentences: [
                    {
                        id: 1,
                        original: "Emma had always loved books, but she never imagined she would discover a magical library.",
                        translation: "Emma avait toujours aimé les livres, mais elle n'avait jamais imaginé qu'elle découvrirait une bibliothèque magique."
                    },
                    {
                        id: 2,
                        original: "One rainy afternoon, while exploring the ancient mansion, she found a hidden door.",
                        translation: "Un après-midi pluvieux, en explorant l'ancien manoir, elle trouva une porte cachée."
                    },
                    {
                        id: 3,
                        original: "Behind the door was a secret passage that led to an underground chamber.",
                        translation: "Derrière la porte se trouvait un passage secret qui menait à une chambre souterraine."
                    },
                    {
                        id: 4,
                        original: "The walls were covered with glowing symbols that seemed to whispered ancient secrets.",
                        translation: "Les murs étaient couverts de symboles brillants qui semblaient chuchoter des secrets anciens."
                    },
                    {
                        id: 5,
                        original: "Emma carefully approached the center of the room where a mysterious book floated in midair.",
                        translation: "Emma s'approcha prudemment du centre de la pièce où un livre mystérieux flottait dans les airs."
                    }
                ]
            },
            {
                title: "Chapter 2: The Transformation",
                sentences: [
                    {
                        id: 6,
                        original: "As she entered the chamber, the room transformed into a magnificent library.",
                        translation: "Alors qu'elle entrait dans la chambre, la pièce se transforma en une magnifique bibliothèque."
                    },
                    {
                        id: 7,
                        original: "Books were floating everywhere, and the shelves seemed to be reaching up to infinity.",
                        translation: "Des livres flottaient partout, et les étagères semblaient s'étendre jusqu'à l'infini."
                    },
                    {
                        id: 8,
                        original: "When Emma touched the spine of one book, it shimmered and opened a portal to another world.",
                        translation: "Quand Emma toucha le dos d'un livre, il scintilla et ouvrit un portail vers un autre monde."
                    },
                    {
                        id: 9,
                        original: "She realized that this was no ordinary library - it was a gateway to infinite worlds of imagination.",
                        translation: "Elle réalisa que ce n'était pas une bibliothèque ordinaire - c'était une passerelle vers des mondes infinis d'imagination."
                    },
                    {
                        id: 10,
                        original: "The keeper of the library appeared and welcomed her to begin her journey through knowledge and wisdom.",
                        translation: "Le gardien de la bibliothèque apparut et l'accueillit pour commencer son voyage à travers la connaissance et la sagesse."
                    }
                ]
            }
        ]
    },

    // Compatibility functions for different games

    // For Whack-a-Mole game
    getVocabularyPairs() {
        return Object.entries(this.vocabulary).map(([word, data]) => ({
            english: word,
            translation: data.translation,
            pronunciation: data.pronunciation
        }));
    },

    // For Memory Match game
    getMatchingPairs() {
        return Object.entries(this.vocabulary)
            .slice(0, 12) // Limit to 12 pairs for memory game
            .map(([word, data]) => ({
                english: word,
                chinese: data.translation
            }));
    },

    // For Quiz game
    getQuizQuestions() {
        return Object.entries(this.vocabulary).map(([word, data]) => ({
            question: `What does "${word}" mean?`,
            answer: data.translation,
            options: this.generateOptions(data.translation)
        }));
    },

    generateOptions(correctAnswer) {
        const allTranslations = Object.values(this.vocabulary)
            .map(v => v.translation)
            .filter(t => t !== correctAnswer);

        const shuffled = allTranslations.sort(() => Math.random() - 0.5);
        const options = [correctAnswer, ...shuffled.slice(0, 3)];
        return options.sort(() => Math.random() - 0.5);
    }
};