import os

html_inject = """
            <div class="dashboard-header" style="display:flex; justify-content:space-between; align-items:center; margin-bottom: 24px;">
                <div>
                    <h2 style="margin:0; font-size:1.8rem; color:#f39c12;"><i class="fa-solid fa-shield-halved"></i> Er Meydanı (Midas)</h2>
                    <p class="text-muted" style="margin-top:5px;">Buffett yapay zekasının gerçek piyasadaki savaş alanı.</p>
                </div>
                <button class="btn" style="background:#f39c12; color:#fff;" onclick="if(typeof openMidanCapitalModal === 'function') openMidanCapitalModal()">
                    <i class="fa-solid fa-coins"></i> Sermaye Ekle
                </button>
            </div>

            <!-- Özet İstatistikler -->
            <div class="dashboard-widgets" style="grid-template-columns: repeat(4, 1fr); margin-bottom: 24px;">
                <div class="widget" style="text-align:center;">
                    <p class="text-muted" style="margin:0; font-size:0.9rem;">Toplam Midas Varlığı</p>
                    <h3 id="meydan-total-value" style="font-size:1.8rem; margin:10px 0; color:#f39c12;">0.00 ₺</h3>
                    <span id="meydan-total-roi" style="font-weight:600;">--</span>
                </div>
                <div class="widget" style="text-align:center;">
                    <p class="text-muted" style="margin:0; font-size:0.9rem;">Yatırılan Ana Para</p>
                    <h3 id="meydan-deposited" style="font-size:1.5rem; margin:10px 0;">0.00 ₺</h3>
                </div>
                <div class="widget" style="text-align:center;">
                    <p class="text-muted" style="margin:0; font-size:0.9rem;">Kullanılabilir Nakit</p>
                    <h3 id="meydan-cash" style="font-size:1.5rem; margin:10px 0; color:#10b981;">0.00 ₺</h3>
                </div>
                <div class="widget" style="text-align:center;">
                    <p class="text-muted" style="margin:0; font-size:0.9rem;">Hisselerdeki Para</p>
                    <h3 id="meydan-stock-value" style="font-size:1.5rem; margin:10px 0; color:#8b5cf6;">0.00 ₺</h3>
                    <span id="meydan-position-count" class="text-muted">0 Hisse</span>
                </div>
            </div>

            <!-- Tablolar -->
            <div class="dashboard-widgets" style="grid-template-columns: 2fr 1fr;">
                <div class="widget table-container">
                    <h3 style="margin-bottom:15px; border-bottom:1px solid var(--color-border); padding-bottom:10px;">Açık Pozisyonlar</h3>
                    <table class="data-table">
                        <thead>
                            <tr>
                                <th>Hisse</th>
                                <th>Adet</th>
                                <th>Ort. Maliyet</th>
                                <th>Güncel Fiyat</th>
                                <th>Toplam Değer</th>
                                <th>Kâr / Zarar</th>
                                <th>Tarih</th>
                            </tr>
                        </thead>
                        <tbody id="meydan-positions-table">
                            <!-- JS Dolduracak -->
                        </tbody>
                    </table>
                </div>
                <div class="widget table-container">
                    <h3 style="margin-bottom:15px; border-bottom:1px solid var(--color-border); padding-bottom:10px;">
                        İşlem Geçmişi <span id="meydan-history-count" style="font-size:0.8rem; background:rgba(255,255,255,0.1); padding:2px 8px; border-radius:12px; float:right;">0</span>
                    </h3>
                    <div style="max-height: 400px; overflow-y: auto;">
                        <table class="data-table">
                            <thead>
                                <tr>
                                    <th>İşlem</th>
                                    <th>Detay</th>
                                    <th>Tarih</th>
                                </tr>
                            </thead>
                            <tbody id="meydan-history-table">
                                <!-- JS Dolduracak -->
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>

            <!-- Sermaye Ekle Modal -->
            <div id="midas-capital-modal" class="modal-overlay" style="display:none; position:fixed; top:0; left:0; right:0; bottom:0; background:rgba(0,0,0,0.8); z-index:9999; justify-content:center; align-items:center;">
                <div class="modal-content" style="background:var(--color-surface); padding:24px; border-radius:12px; width:400px; max-width:90%; border:1px solid #f39c12;">
                    <h3 style="margin-top:0; color:#f39c12;"><i class="fa-solid fa-coins"></i> Midas'a Sermaye Ekle</h3>
                    <p class="text-muted" style="font-size:0.9rem;">Er Meydanı için yeni nakit girişi yapın. Bu tutar direkt olarak Buffett yapay zekasının kullanımına sunulacaktır.</p>
                    <div class="form-group" style="margin-top:20px;">
                        <label>Eklenecek Tutar (₺)</label>
                        <input type="number" id="midas-capital-input" class="form-control" placeholder="Örn: 50000" style="width:100%; padding:10px; margin-top:5px; background:var(--color-bg); color:#fff; border:1px solid var(--color-border); border-radius:6px;">
                    </div>
                    <div style="display:flex; justify-content:flex-end; gap:10px; margin-top:24px;">
                        <button class="btn btn-outline" onclick="document.getElementById('midas-capital-modal').style.display='none'">İptal</button>
                        <button class="btn" style="background:#f39c12; color:#fff;" onclick="if(typeof saveMidasCapital === 'function') saveMidasCapital()">Ekle</button>
                    </div>
                </div>
            </div>
"""

with open('index.html', 'r', encoding='utf-8') as f:
    content = f.read()

target = '<div id="meydan-container"></div>'

if target in content:
    content = content.replace(target, '<div id="meydan-container">\n' + html_inject + '\n</div>')
    with open('index.html', 'w', encoding='utf-8') as f:
        f.write(content)
    print('MEYDAN HTML TASARIMI EKLENDI')
else:
    print('HEDEF BULUNAMADI')
