<!DOCTYPE html>
<html lang="tr">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Akkurtcast - Haber Bülteni</title>
    <link rel="icon" type="image/png" href="/static/img/icon.png">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
    <style>
        :root { --sidebar-bg: #1a1d21; --sidebar-hover: #2a2e35; --sidebar-text: #a8b2c0; --page-bg: #f0f2f5; --card-border: #e2e8f0; --accent: #0d6efd; }
        * { box-sizing: border-box; }
        body { background: var(--page-bg); margin: 0; font-family: system-ui, -apple-system, sans-serif; }
        .sidebar { min-height: 100vh; background: var(--sidebar-bg); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
        .brand { display: flex; align-items: center; gap: 10px; padding: 20px 18px 16px; color: #fff; font-weight: 800; font-size: 1.05rem; letter-spacing: -0.3px; border-bottom: 1px solid #2a2e35; flex-shrink: 0; }
        .brand img { width: 46px; height: 46px; object-fit: contain; border-radius: 8px; }
        .brand-mark { display: flex; flex-direction: column; min-width: 0; line-height: 1.05; }
        .brand-name { color: #f8fafc; font-size: 1.18rem; font-weight: 850; letter-spacing: .2px; text-shadow: 0 1px 0 rgba(0,0,0,.25); }
        .brand-subtitle { margin-top: 4px; color: #7dd3fc; font-size: .63rem; font-weight: 700; letter-spacing: 1.25px; text-transform: uppercase; }
        .nav-section-label { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 1px; color: #4a5568; padding: 14px 18px 4px; }
        .sidebar a { color: var(--sidebar-text); display: flex; align-items: center; gap: 8px; padding: 9px 18px; text-decoration: none; font-size: 0.875rem; font-weight: 500; border-left: 3px solid transparent; transition: all 0.15s; }
        .sidebar a:hover { background: var(--sidebar-hover); color: #fff; }
        .sidebar a.active { background: rgba(13,110,253,0.12); color: #4d9fff; border-left-color: var(--accent); }
        .sidebar a .nav-icon { width: 22px; height: 22px; min-width: 22px; border-radius: 7px; display: inline-flex; align-items: center; justify-content: center; color: #fff; font-size: .78rem; line-height: 1; box-shadow: inset 0 1px 0 rgba(255,255,255,.18), 0 6px 14px rgba(0,0,0,.18); }
.nav-icon-panel { background: linear-gradient(135deg,#2563eb,#38bdf8); }
.nav-icon-music { background: linear-gradient(135deg,#7c3aed,#ec4899); }
.nav-icon-jingle { background: linear-gradient(135deg,#f59e0b,#f97316); }
.nav-icon-library { background: linear-gradient(135deg,#0f766e,#22c55e); }
.nav-icon-calendar { background: linear-gradient(135deg,#dc2626,#fb7185); }
.nav-icon-automation { background: linear-gradient(135deg,#475569,#94a3b8); }
.nav-icon-news { background: linear-gradient(135deg,#0891b2,#06b6d4); }
.nav-icon-broadcast { background: linear-gradient(135deg,#4338ca,#818cf8); }
.nav-icon-dj { background: linear-gradient(135deg,#111827,#64748b); }
.nav-icon-mobile { background: linear-gradient(135deg,#0e7490,#14b8a6); }
.nav-icon-reports { background: linear-gradient(135deg,#16a34a,#84cc16); }
.nav-icon-widget { background: linear-gradient(135deg,#9333ea,#22d3ee); }
.nav-icon-backup { background: linear-gradient(135deg,#6b7280,#d97706); }
.nav-icon-settings { background: linear-gradient(135deg,#334155,#0ea5e9); }
.nav-icon-logout { background: linear-gradient(135deg,#7f1d1d,#ef4444); }
.sidebar a:hover .nav-icon, .sidebar a.active .nav-icon { transform: translateY(-1px); box-shadow: inset 0 1px 0 rgba(255,255,255,.22), 0 8px 18px rgba(13,110,253,.25); }
        
        .sidebar-footer { margin-top: auto; border-top: 1px solid #2a2e35; padding: 8px 0; }
        .topbar { background: #fff; border-bottom: 1px solid var(--card-border); padding: 12px 24px; display: flex; align-items: center; gap: 12px; position: sticky; top: 0; z-index: 100; }
        .topbar-title { font-weight: 700; font-size: 0.95rem; color: #1a202c; }
        .panel { background: #fff; border: 1px solid var(--card-border); border-radius: 8px; }
        .scroll-box { max-height: 360px; overflow: auto; }
        @media (max-width: 767px) {
            .sidebar { min-height: auto; height: auto; position: static; flex-direction: row; overflow-x: auto; overflow-y: hidden; white-space: nowrap; }
            .brand { border-bottom: none; border-right: 1px solid #2a2e35; padding: 12px 14px; }
            .nav-section-label { display: none; }
            .sidebar a { padding: 12px 14px; border-left: none; border-bottom: 3px solid transparent; }
            .sidebar a.active { border-left-color: transparent; border-bottom-color: var(--accent); }
            .sidebar-footer { margin-top: 0; border-top: none; }
            .topbar { padding: 10px 16px; }
        }
    
        /* Mobile shell fix: keep the sidebar from squeezing content on phones. */
        @media (max-width: 767px) {
            html, body { width: 100%; max-width: 100%; overflow-x: hidden; }
            .container-fluid > .row.g-0 { display: block; width: 100%; margin: 0; }
            aside.sidebar,
            .sidebar {
                width: 100% !important;
                min-width: 0 !important;
                max-width: 100% !important;
                min-height: auto !important;
                height: auto !important;
                position: relative !important;
                top: auto !important;
                flex-direction: row !important;
                align-items: stretch;
                overflow-x: auto;
                overflow-y: hidden;
                white-space: nowrap;
                -webkit-overflow-scrolling: touch;
            }
            .brand { min-width: 188px; padding: 10px 12px !important; }
            .brand img { width: 40px !important; height: 40px !important; }
            .brand-name { font-size: 1rem !important; }
            .brand-subtitle { font-size: .55rem !important; letter-spacing: .9px !important; }
            .sidebar a { flex: 0 0 auto; padding: 12px 10px !important; }
            .sidebar a .nav-icon { width: 28px; height: 28px; min-width: 28px; }
            .sidebar-footer { display: flex; flex: 0 0 auto; }
            main.col,
            main[class*="col"] {
                display: block;
                width: 100% !important;
                max-width: 100% !important;
                flex: 0 0 100% !important;
                min-width: 0 !important;
            }
            .topbar { position: sticky; top: 0; z-index: 50; padding: 10px 14px !important; }
            .topbar-title { font-size: 1rem; }
            .topbar-status { font-size: .75rem; padding: 4px 9px; }
            main > .p-4 { padding: 14px !important; }
            .card-panel { border-radius: 10px; }
            .card-panel-header { align-items: flex-start; flex-direction: column; padding: 14px !important; }
            .card-panel-header > .d-flex,
            .card-panel-header .d-flex { flex-wrap: wrap; }
            .card-panel-body { padding: 14px !important; }
            .broadcast-controls { display: grid !important; grid-template-columns: 1fr; gap: 10px; }
            .broadcast-controls .action-btn { width: 100%; min-height: 44px; }
            .stream-row,
            .stream-actions { flex-direction: column !important; align-items: stretch !important; gap: 10px !important; }
            .stream-url,
            .stream-row a { max-width: 100%; overflow-wrap: anywhere; word-break: break-word; }
            .history-item { align-items: flex-start; }
            .history-time { margin-left: 0; white-space: normal; }
            .now-playing-card { padding: 16px !important; }
            .next-track-box .next-path { white-space: normal; overflow-wrap: anywhere; }
        }
    </style>
</head>
<body>
<div class="container-fluid p-0">
    <div class="row g-0">
        <aside class="col-12 col-md-auto sidebar p-0" style="width: 220px; min-width: 220px;">
            <div class="brand">
                <img src="/static/img/akkurtcast-badge.png" alt="Akkurtcast">
                <span class="brand-mark"><span class="brand-name">Akkurtcast</span><span class="brand-subtitle">Broadcast Panel</span></span>
            </div>
            <div class="nav-section-label">Yayın</div>
            <a href="/"><span class="nav-icon nav-icon-panel"><i class="bi bi-house-door-fill"></i></span> Panel</a>
            <a href="/muzik"><span class="nav-icon nav-icon-music"><i class="bi bi-music-note-beamed"></i></span> Müzik listesi</a>
            <a href="/jingle"><span class="nav-icon nav-icon-jingle"><i class="bi bi-bell-fill"></i></span> Jingle listesi</a>
            <a href="/kutuphane"><span class="nav-icon nav-icon-library"><i class="bi bi-folder-fill"></i></span> Kütüphane</a>
            <div class="nav-section-label">Planlama</div>
            <a href="/takvim"><span class="nav-icon nav-icon-calendar"><i class="bi bi-calendar-week-fill"></i></span> Takvim</a>
            <a href="/otomasyon"><span class="nav-icon nav-icon-automation"><i class="bi bi-sliders"></i></span> Otomasyon</a>
            <a class="active" href="/haber-bulteni"><span class="nav-icon nav-icon-news"><i class="bi bi-newspaper"></i></span> Haber Bülteni</a>
            <div class="nav-section-label">Yayın Araçları</div>
            <a href="/naklen-yayin"><span class="nav-icon nav-icon-broadcast"><i class="bi bi-broadcast-pin"></i></span> Naklen Yayın</a>
            <a href="/dj"><span class="nav-icon nav-icon-dj"><i class="bi bi-headphones"></i></span> DJ</a>
            <a href="/mobil"><span class="nav-icon nav-icon-mobile"><i class="bi bi-phone-fill"></i></span> Mobil</a>
            <div class="nav-section-label">Sistem</div>
            <a href="/raporlar"><span class="nav-icon nav-icon-reports"><i class="bi bi-bar-chart-fill"></i></span> Raporlar</a>
            <a href="/widgetler"><span class="nav-icon nav-icon-widget"><i class="bi bi-puzzle-fill"></i></span> Widget</a>
            <a href="/yedek"><span class="nav-icon nav-icon-backup"><i class="bi bi-device-hdd-fill"></i></span> Yedek</a>
            <a href="/ayarlar"><span class="nav-icon nav-icon-settings"><i class="bi bi-gear-fill"></i></span> Ayarlar</a>
            <a href="/akis"><span class="nav-icon nav-icon-calendar"><i class="bi bi-list-check"></i></span> Yayın Akışı</a>
            <div class="sidebar-footer">
                <a href="/logout"><span class="nav-icon nav-icon-logout"><i class="bi bi-box-arrow-right"></i></span> Çıkış</a>
            </div>
        </aside>
        <main class="col p-0" style="min-width: 0;">
            <div class="topbar">
                <div class="topbar-title">Haber Bülteni</div>
                <span class="text-muted small ms-auto">{{ durum }}</span>
            </div>
            <div class="p-4">
                <div class="mb-4">
                    <h1 class="h3 mb-1">Otomatik haber bülteni</h1>
                    <div class="text-muted">RSS kaynağını seç, haber metnini hazırla, jingle ve fon müziğini ayarla.</div>
                </div>

                <section class="panel p-4 mb-3">
                    <div class="d-flex flex-wrap align-items-start justify-content-between gap-3 mb-3">
                        <div>
                            <h2 class="h5 mb-1">Show Radyo haber kaydı</h2>
                            <div class="text-muted small">Canlı yayından bülteni kaydeder, giriş ve çıkış sesiyle tek MP3 hazırlar, Radyo Pop yayın listesine gönderir.</div>
                        </div>
                        <form method="post" action="/show-haber-manuel-kayit">
                            <button class="btn btn-outline-primary btn-sm">Şimdi kaydet</button>
                        </form>
                    </div>
                    {% if show_haber_durum.latest_exists %}
                    <div class="alert alert-success py-2">
                        Son dosya: {{ show_haber_durum.latest_mtime }} - {{ show_haber_durum.latest_size_mb }} MB
                        <audio class="mt-2" controls src="{{ show_haber_durum.latest_url }}" style="width:100%; max-width:420px;"></audio>
                    </div>
                    {% endif %}
                    <form method="post" action="/show-haber-kaydet" class="row g-3">
                        <div class="col-lg-4">
                            <label class="form-label">Show Radyo yayın URL</label>
                            <input class="form-control" name="stream_url" value="{{ show_haber.stream_url }}">
                        </div>
                        <div class="col-lg-4">
                            <label class="form-label">Yayın aktarımı</label>
                            <input type="hidden" name="play_offset_minutes" value="5">
                            <div class="border rounded bg-light px-3 py-2 small">
                                Kayıt tamamlandıktan 5 dakika sonra Radyo Pop yayın listesine otomatik alınır.
                            </div>
                        </div>
                        <div class="col-lg-4">
                            <label class="form-label">Kayıt üst sınırı</label>
                            <input class="form-control" type="number" min="60" max="600" name="max_duration_seconds" value="{{ show_haber.max_duration_seconds }}">
                        </div>
                        <div class="col-12">
                            <label class="form-label">Show Haber kayıt saatleri</label>
                            <div class="row g-2">
                                {% for saat in show_haber_saatler %}
                                <div class="col-6 col-sm-4 col-md-3 col-xl-2">
                                    <label class="form-check-label small">
                                        <input class="form-check-input" type="checkbox" name="schedule_times" value="{{ saat }}" {% if saat in show_haber.schedule_times %}checked{% endif %}>
                                        {{ saat }}
                                    </label>
                                </div>
                                {% endfor %}
                            </div>
                            <div class="form-text">Ek saatler için virgül veya satırla yazabilirsin.</div>
                            <input class="form-control mt-2" name="custom_schedule_times" value="{{ show_haber_custom_times|join(',') }}" placeholder="08:00,12:00,13:00">
                        </div>
                        <div class="col-md-3">
                            <label class="form-label">Erken başlama saniyesi</label>
                            <input class="form-control" type="number" min="0" max="60" name="start_padding_seconds" value="{{ show_haber.start_padding_seconds }}">
                        </div>
                        <div class="col-md-3">
                            <label class="form-label">Jenerik payı</label>
                            <input class="form-control" type="number" min="0" max="30" name="pre_speech_keep_seconds" value="{{ show_haber.pre_speech_keep_seconds }}">
                            <div class="form-text">İlk konuşmadan kaç saniye önce başlasın.</div>
                        </div>
                        <div class="col-md-3">
                            <label class="form-label">Bitiş aramaya başlama</label>
                            <input class="form-control" type="number" min="0" max="600" name="min_elapsed_before_stop_seconds" value="{{ show_haber.min_elapsed_before_stop_seconds }}">
                        </div>
                        <div class="col-md-3">
                            <label class="form-label">Paketleme</label>
                            <label class="form-check-label d-block mt-2">
                                <input class="form-check-input" type="checkbox" name="wrap_enabled" {% if show_haber.wrap_audio.enabled %}checked{% endif %}>
                                Giriş + haber + çıkış tek MP3
                            </label>
                        </div>
                        <div class="col-md-6">
                            <label class="form-label">Giriş müziği</label>
                            <select class="form-select" name="intro_path">
                                <option value="">Seçme</option>
                                {% for dosya in show_haber_medya %}
                                <option value="{{ dosya.path }}" {% if show_haber.wrap_audio.intro_path == dosya.path %}selected{% endif %}>{{ dosya.name }}</option>
                                {% endfor %}
                            </select>
                        </div>
                        <div class="col-md-3">
                            <label class="form-label">Giriş süre sınırı</label>
                            <input class="form-control" type="number" min="0" max="600" name="intro_max_seconds" value="{{ show_haber.wrap_audio.intro_max_seconds or 0 }}">
                        </div>
                        <div class="col-md-3">
                            <label class="form-label">Giriş çapraz geçiş</label>
                            <input class="form-control" type="number" min="0" max="2" step="0.05" name="intro_crossfade_seconds" value="{{ show_haber.wrap_audio.intro_crossfade_seconds if show_haber.wrap_audio.intro_crossfade_seconds is defined else (show_haber.wrap_audio.crossfade_seconds if show_haber.wrap_audio.crossfade_seconds is defined else 0.35) }}">
                        </div>
                        <div class="col-md-6">
                            <label class="form-label">Çıkış müziği</label>
                            <select class="form-select" name="outro_path">
                                <option value="">Seçme</option>
                                {% for dosya in show_haber_medya %}
                                <option value="{{ dosya.path }}" {% if show_haber.wrap_audio.outro_path == dosya.path %}selected{% endif %}>{{ dosya.name }}</option>
                                {% endfor %}
                            </select>
                        </div>
                        <div class="col-md-3">
                            <label class="form-label">Çıkış süre sınırı</label>
                            <input class="form-control" type="number" min="0" max="600" name="outro_max_seconds" value="{{ show_haber.wrap_audio.outro_max_seconds or 0 }}">
                        </div>
                        <div class="col-md-3">
                            <label class="form-label">Çıkış çapraz geçiş</label>
                            <input class="form-control" type="number" min="0" max="2" step="0.05" name="outro_crossfade_seconds" value="{{ show_haber.wrap_audio.outro_crossfade_seconds if show_haber.wrap_audio.outro_crossfade_seconds is defined else (show_haber.wrap_audio.crossfade_seconds if show_haber.wrap_audio.crossfade_seconds is defined else 0.35) }}">
                        </div>
                        <div class="col-md-6">
                            <label class="form-label">Bitiş cümleleri</label>
                            <textarea class="form-control" name="stop_phrases" rows="4">{{ show_haber.stop_phrases|join('\n') }}</textarea>
                        </div>
                        <div class="col-md-6">
                            <label class="form-label">Zorunlu bitiş kelimeleri</label>
                            <input class="form-control" name="stop_required_terms" value="{{ show_haber.stop_required_terms|join(',') }}">
                        </div>
                        <div class="col-12 text-end">
                            <button class="btn btn-primary">Show Haber ayarlarını kaydet</button>
                        </div>
                    </form>
                </section>

                <div class="row g-3">
                    <div class="col-lg-7">
                        <section class="panel p-4 mb-3">
                            <h2 class="h5 mb-3">Bülten ayarları</h2>
                            <form method="post" action="/haber-bulteni-kaydet" class="row g-3">
                                <div class="col-12">
                                    <label class="form-check-label">
                                        <input class="form-check-input" type="checkbox" name="enabled" {% if ayarlar.enabled %}checked{% endif %}>
                                        Otomatik haber bülteni aktif
                                    </label>
                                </div>
                                <div class="col-md-6">
                                    <label class="form-label">Haber kaynağı</label>
                                    <select class="form-select" name="source">
                                        {% for kaynak in kaynaklar %}
                                        <option value="{{ kaynak.key }}" {% if ayarlar.source == kaynak.key %}selected{% endif %}>{{ kaynak.name }}</option>
                                        {% endfor %}
                                    </select>
                                </div>
                                <div class="col-md-6">
                                    <label class="form-label">Kaç haber okunsun</label>
                                    <input class="form-control" type="number" min="1" max="12" name="item_count" value="{{ ayarlar.item_count }}">
                                </div>
                                <div class="col-12">
                                    <label class="form-label">Özel RSS adresi</label>
                                    <input class="form-control" name="custom_rss" value="{{ ayarlar.custom_rss }}" placeholder="Kaynak özel RSS ise doldur">
                                </div>
                                <div class="col-md-6">
                                    <label class="form-label">Hazır podcast haber bülteni</label>
                                    <select class="form-select" name="podcast_source" id="podcastSource">
                                        {% for kaynak in podcast_kaynaklari %}
                                        <option value="{{ kaynak.key }}" data-url="{{ kaynak.url }}" data-note="{{ kaynak.note }}" {% if ayarlar.podcast_source == kaynak.key %}selected{% endif %}>{{ kaynak.name }}</option>
                                        {% endfor %}
                                    </select>
                                    <div id="podcastNote" class="form-text"></div>
                                </div>
                                <div class="col-md-6">
                                    <label class="form-label">Sesli RSS / podcast adresi</label>
                                    <input class="form-control" id="podcastRss" name="podcast_rss" value="{{ ayarlar.podcast_rss }}" placeholder="Özel kaynak seçersen doldur">
                                    <div class="form-text">Hazır kaynak seçiliyken bu adres otomatik kullanılır.</div>
                                </div>
                                <div class="col-md-6">
                                    <label class="form-label">Giriş jingle</label>
                                    <select class="form-select" name="intro_jingle">
                                        <option value="">Seçme</option>
                                        {% for dosya in jingle_dosyalari %}
                                        <option value="{{ dosya.path }}" {% if ayarlar.intro_jingle == dosya.path %}selected{% endif %}>{{ dosya.name }}</option>
                                        {% endfor %}
                                    </select>
                                </div>
                                <div class="col-md-6">
                                    <label class="form-label">Çıkış jingle</label>
                                    <select class="form-select" name="outro_jingle">
                                        <option value="">Seçme</option>
                                        {% for dosya in jingle_dosyalari %}
                                        <option value="{{ dosya.path }}" {% if ayarlar.outro_jingle == dosya.path %}selected{% endif %}>{{ dosya.name }}</option>
                                        {% endfor %}
                                    </select>
                                </div>
                                <div class="col-md-8">
                                    <label class="form-label">Haber fon müziği</label>
                                    <select class="form-select" name="background_music">
                                        <option value="">Seçme</option>
                                        {% for dosya in haber_muzikleri %}
                                        <option value="{{ dosya.path }}" {% if ayarlar.background_music == dosya.path %}selected{% endif %}>{{ dosya.name }}</option>
                                        {% endfor %}
                                    </select>
                                </div>
                                <div class="col-md-4">
                                    <label class="form-label">Fon ses seviyesi (%)</label>
                                    <input class="form-control" type="number" min="0" max="60" name="background_volume" value="{{ ayarlar.background_volume }}">
                                </div>
                                <div class="col-md-6">
                                    <label class="form-label">Bülten saatleri</label>
                                    <textarea class="form-control" name="times" rows="4" placeholder="08:00&#10;12:00&#10;18:00">{{ ayarlar.times }}</textarea>
                                    <div class="form-text">Her satıra bir saat yaz. Örnek: 08:00</div>
                                </div>
                                <div class="col-md-6">
                                    <label class="form-label">Ses üretimi</label>
                                    <select class="form-select" name="voice_provider">
                                        <option value="text_tts" {% if ayarlar.voice_provider == "text_tts" %}selected{% endif %}>Edge TTS - ücretsiz Türkçe spiker</option>
                                        <option value="openai_tts" {% if ayarlar.voice_provider == "openai_tts" %}selected{% endif %}>OpenAI TTS - daha doğal spiker</option>
                                        <option value="elevenlabs_tts" {% if ayarlar.voice_provider == "elevenlabs_tts" %}selected{% endif %}>ElevenLabs - profesyonel ses</option>
                                        <option value="audio_rss" {% if ayarlar.voice_provider == "audio_rss" %}selected{% endif %}>Hazır sesli RSS / podcast kullan</option>
                                    </select>
                                    <div class="form-text">Önce sesleri dene; hangisini beğenirsen sonra otomatik akışa onu bağlarız.</div>
                                </div>
                                <div class="col-md-6">
                                    <label class="form-label">Edge TTS sesi</label>
                                    <select class="form-select" name="edge_voice">
                                        <option value="tr-TR-EmelNeural" {% if ayarlar.edge_voice == "tr-TR-EmelNeural" %}selected{% endif %}>Emel - kadın haber sesi</option>
                                        <option value="tr-TR-AhmetNeural" {% if ayarlar.edge_voice == "tr-TR-AhmetNeural" %}selected{% endif %}>Ahmet - erkek haber sesi</option>
                                    </select>
                                </div>
                                <div class="col-md-4">
                                    <label class="form-label">OpenAI model</label>
                                    <input class="form-control" name="openai_model" value="{{ ayarlar.openai_model or 'gpt-4o-mini-tts' }}">
                                </div>
                                <div class="col-md-4">
                                    <label class="form-label">OpenAI ses</label>
                                    <select class="form-select" name="openai_voice">
                                        {% for voice in ["alloy", "ash", "ballad", "coral", "echo", "fable", "nova", "onyx", "sage", "shimmer", "verse"] %}
                                        <option value="{{ voice }}" {% if ayarlar.openai_voice == voice %}selected{% endif %}>{{ voice }}</option>
                                        {% endfor %}
                                    </select>
                                </div>
                                <div class="col-md-4">
                                    <label class="form-label">OpenAI API key</label>
                                    <input class="form-control" type="password" name="openai_api_key" value="{{ ayarlar.openai_api_key }}">
                                </div>
                                <div class="col-md-6">
                                    <label class="form-label">ElevenLabs API key</label>
                                    <input class="form-control" type="password" name="elevenlabs_api_key" value="{{ ayarlar.elevenlabs_api_key }}">
                                </div>
                                <div class="col-md-6">
                                    <label class="form-label">ElevenLabs Voice ID</label>
                                    <input class="form-control" name="elevenlabs_voice_id" value="{{ ayarlar.elevenlabs_voice_id }}" placeholder="Örn: pNInz6obpgDQGcFmaJgB">
                                </div>
                                <div class="col-md-4">
                                    <label class="form-label">Eski haber temizliği</label>
                                    <input class="form-control" type="number" min="1" max="365" name="cleanup_days" value="{{ ayarlar.cleanup_days or 14 }}">
                                    <div class="form-text">Bu günden eski sesli bültenler temizlenir.</div>
                                </div>
                                <div class="col-12 text-end">
                                    <button class="btn btn-primary">Ayarları kaydet</button>
                                </div>
                            </form>
                        </section>

                        <section class="panel p-4 mb-3">
                            <h2 class="h5 mb-3">Sesli bülten üret</h2>
                            {% if ayarlar.last_error %}
                            <div class="alert alert-warning">{{ ayarlar.last_error }}</div>
                            {% endif %}
                            <div class="d-flex flex-wrap gap-2 align-items-center">
                                <form method="post" action="/haber-bulteni-sesli-uret">
                                    <button class="btn btn-primary">Sesli haber bülteni üret</button>
                                </form>
                                {% if ayarlar.last_audio %}
                                <audio controls src="/media/haber/{{ ayarlar.last_audio.replace('/web-radyo/haber/', '') }}" style="max-width:320px;width:100%;"></audio>
                                <form method="post" action="/haber-bulteni-yayina-al">
                                    <input type="hidden" name="path" value="{{ ayarlar.last_audio }}">
                                    <button class="btn btn-outline-success">Şimdi yayına al</button>
                                </form>
                                {% endif %}
                            </div>
                            {% if ayarlar.last_audio_name %}
                            <div class="small text-muted mt-2">Son sesli bülten: {{ ayarlar.last_audio_name }}</div>
                            {% endif %}
                        </section>

                        <section class="panel p-4">
                            <h2 class="h5 mb-3">Haber müziği yükle</h2>
                            <form method="post" action="/haber-muzigi-yukle" enctype="multipart/form-data" class="row g-3 align-items-end">
                                <div class="col-md-8">
                                    <input class="form-control" type="file" name="files" accept=".mp3,.wav,.ogg,.flac,.m4a,.aac" multiple>
                                </div>
                                <div class="col-md-4 text-end">
                                    <button class="btn btn-outline-primary">Yükle</button>
                                </div>
                            </form>
                        </section>

                        <section class="panel p-4 mt-3">
                            <h2 class="h5 mb-3">Hazır sesli bültenler</h2>
                            <form method="post" action="/haber-bulteni-temizle" class="row g-2 align-items-end mb-3">
                                <div class="col-md-5">
                                    <label class="form-label small">Kaç günden eskiler silinsin?</label>
                                    <input class="form-control form-control-sm" type="number" min="1" max="365" name="cleanup_days" value="{{ ayarlar.cleanup_days or 14 }}">
                                </div>
                                <div class="col-md-4">
                                    <label class="form-check-label small">
                                        <input class="form-check-input" type="checkbox" name="delete_all">
                                        Hepsini sil
                                    </label>
                                </div>
                                <div class="col-md-3 text-end">
                                    <button class="btn btn-outline-danger btn-sm">Temizle</button>
                                </div>
                            </form>
                            <div class="scroll-box">
                                {% for dosya in haber_ciktilari %}
                                <div class="border-bottom py-2">
                                    <div class="fw-bold">{{ dosya.name }}</div>
                                    <audio controls src="/media/haber/{{ dosya.path.replace('/web-radyo/haber/', '') }}" style="width:100%;"></audio>
                                    <form method="post" action="/haber-bulteni-yayina-al" class="mt-2">
                                        <input type="hidden" name="path" value="{{ dosya.path }}">
                                        <button class="btn btn-outline-success btn-sm">Yayına al</button>
                                    </form>
                                </div>
                                {% else %}
                                <div class="text-muted">Henüz sesli bülten yok.</div>
                                {% endfor %}
                            </div>
                        </section>
                    </div>

                    <div class="col-lg-5">
                        <section class="panel p-4 mb-3">
                            <h2 class="h5 mb-3">RSS önizleme</h2>
                            <div class="d-flex gap-2 mb-3">
                                <a class="btn btn-outline-primary btn-sm" href="/haber-bulteni?preview=1">Kaynağı kontrol et</a>
                                <form method="post" action="/haber-bulteni-taslak">
                                    <button class="btn btn-primary btn-sm">Bülten metni hazırla</button>
                                </form>
                            </div>
                            {% if preview_error %}
                            <div class="alert alert-warning">{{ preview_error }}</div>
                            {% endif %}
                            <div class="scroll-box">
                                {% for item in preview_items %}
                                <div class="border-bottom py-2">
                                    <div class="fw-bold">{{ item.title }}</div>
                                    <div class="small text-muted">{{ item.summary }}</div>
                                    {% if item.audio_url %}
                                    <audio class="mt-2" controls src="{{ item.audio_url }}" style="width:100%;"></audio>
                                    {% endif %}
                                </div>
                                {% else %}
                                <div class="text-muted">Henüz önizleme alınmadı.</div>
                                {% endfor %}
                            </div>
                        </section>

                        <section class="panel p-4">
                            <h2 class="h5 mb-3">Son hazırlanan metin</h2>
                            <div class="small text-muted mb-2">Son üretim: {{ ayarlar.last_generated or "-" }}</div>
                            <textarea class="form-control" rows="14" readonly>{{ taslak }}</textarea>
                        </section>
                    </div>
                </div>
            </div>
        </main>
    </div>
</div>
<script>
function podcastKaynakGuncelle() {
    const select = document.getElementById('podcastSource');
    const input = document.getElementById('podcastRss');
    const note = document.getElementById('podcastNote');
    if (!select || !input || !note) return;
    const option = select.options[select.selectedIndex];
    note.textContent = option.dataset.note || '';
    if (select.value !== 'custom') {
        input.value = option.dataset.url || '';
        input.readOnly = true;
    } else {
        input.readOnly = false;
    }
}
document.addEventListener('DOMContentLoaded', podcastKaynakGuncelle);
document.getElementById('podcastSource')?.addEventListener('change', podcastKaynakGuncelle);
</script>
<script src="/static/js/mobile-nav.js"></script>
</body>
</html>












