import glob

html_to_inject = """
    <!-- Bible Dipping Widget -->
    <div id="bible-widget-btn" title="Bible Dipping">
        <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M21 4H7a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h14a1 1 0 0 0 1-1V5a1 1 0 0 0-1-1zm-1 13H7V6h13v11zM5 18H4V6H3v13a2 2 0 0 0 2 2h16v-1H5a1 1 0 0 1 0-2z"/><rect x="10" y="8" width="8" height="2"/><rect x="10" y="11" width="8" height="2"/><rect x="10" y="14" width="5" height="2"/></svg>
    </div>

    <div id="bible-modal">
        <button id="bible-modal-close">&times;</button>
        
        <audio id="bible-audio" src="assets/audio/bible-music.mp3" loop></audio>

        <div id="bible-input-container">
            <h2 id="bible-input-title">Seek the Word</h2>
            <p id="bible-input-desc">Enter a page number to dip into the Bible, or pick randomly.</p>
            <div style="display: flex; gap: 1rem; justify-content: center; align-items: center; flex-wrap: wrap;">
                <input type="number" id="bible-page-input" class="bible-input-box" placeholder="Page #" min="1" max="1200">
                <button id="bible-btn-open" class="bible-action-btn">Open Page</button>
                <span style="color: #e6c888; font-family: 'Instrument Sans'; font-style: italic;">or</span>
                <button id="bible-btn-random" class="bible-action-btn">Randomize</button>
            </div>
        </div>

        <div id="bible-flip-container">
            <div class="bible-book">
                <div class="bible-page-anim"></div>
                <div class="bible-page-anim"></div>
                <div class="bible-page-anim"></div>
                <div class="bible-page-anim"></div>
            </div>
            <div id="bible-flip-hint">Click anywhere to stop</div>
        </div>

        <div id="bible-reveal-container">
            <div class="bible-quote-text" id="bible-quote-text">...</div>
            <div class="bible-quote-ref" id="bible-quote-ref">...</div>
        </div>
    </div>
"""

css_link = '<link rel="stylesheet" href="css/bible-widget.css">'
js_link = '<script src="js/bible-widget.js"></script>'

for filepath in glob.glob('*.html'):
    with open(filepath, 'r', encoding='utf-8') as f:
        content = f.read()
        
    if 'id="bible-widget-btn"' not in content:
        # inject css before </head>
        content = content.replace('</head>', f'    {css_link}\n</head>')
        
        # inject js before </body>
        content = content.replace('</body>', f'    {js_link}\n</body>')
        
        # inject html before </body>
        content = content.replace('</body>', f'{html_to_inject}\n</body>')
        
        with open(filepath, 'w', encoding='utf-8') as f:
            f.write(content)
            
print("Injected Bible Widget into HTML files")
