<!DOCTYPE html>
<html lang="tr">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Akkurtcast - Otomasyon</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-active: #0d6efd;
            --sidebar-text: #a8b2c0; --topbar-bg: #fff; --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: var(--topbar-bg); 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: 340px; 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 class="active" href="/otomasyon"><span class="nav-icon nav-icon-automation"><i class="bi bi-sliders"></i></span> Otomasyon</a>
            <a 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">Otomasyon Merkezi</div>
                <a class="btn btn-outline-primary btn-sm ms-auto" href="/mobil">Mobil kumanda</a>
            </div>
            <div class="p-4 vstack gap-3">
                <section class="panel p-4">
                    <h2 class="h5 mb-3">Yayın Sağlığı</h2>
                    <div class="row g-3">
                        <div class="col-md-2"><div class="text-muted small">Sunucu</div><div class="fw-bold">{{ health.container }}</div></div>
                        <div class="col-md-2"><div class="text-muted small">Dinleyici</div><div class="fw-bold">{{ health.listeners }}</div></div>
                        <div class="col-md-2"><div class="text-muted small">Kaynak</div><div class="fw-bold">{{ health.source }}</div></div>
                        <div class="col-md-2"><div class="text-muted small">Kalan</div><div class="fw-bold">{{ health.remaining }}</div></div>
                        <div class="col-md-2"><div class="text-muted small">Zamanlayıcı</div><div class="fw-bold">{{ health.scheduler }}</div></div>
                        <div class="col-md-2"><div class="text-muted small">Son jingle</div><div class="fw-bold">{{ health.last_jingle }}</div></div>
                    </div>
                    <div class="small text-muted mt-2">Son jingle sonucu: {{ health.last_jingle_result }}</div>
                </section>

                <section class="panel p-4">
                    <h2 class="h5 mb-3">Otomatik Bakım</h2>
                    <div class="alert alert-light border small">
                        Saat anonsu, normal anons ve reklam akışlarını artık <a href="/muzik">Müzik Listesi</a> içindeki çalma listesi kurallarıyla yönet.
                        Bu bölüm yalnızca sistem bakımını ayarlar.
                    </div>
                    <form method="post" action="/otomasyon-ayar" class="row g-3 align-items-end">
                        <div class="col-md-2">
                            <label class="form-check-label"><input class="form-check-input" type="checkbox" name="auto_backup_enabled" {% if ayarlar.auto_backup_enabled %}checked{% endif %}> Otomatik yedek</label>
                        </div>
                        <div class="col-md-2">
                            <label class="form-label">Yedek sakla (gün)</label>
                            <input class="form-control" type="number" name="backup_keep_days" min="1" max="365" value="{{ ayarlar.backup_keep_days }}">
                        </div>
                        <div class="col-md-2">
                            <label class="form-label">Kayıt sakla (gün)</label>
                            <input class="form-control" type="number" name="recording_keep_days" min="1" max="365" value="{{ ayarlar.recording_keep_days }}">
                        </div>
                        <div class="col-12 text-end"><button class="btn btn-primary">Kaydet</button></div>
                    </form>
                </section>

                <div class="row g-3">
                    <div class="col-lg-6">
                        <section class="panel p-4 h-100">
                            <h2 class="h5 mb-3">Önümüzdeki Yayın Akışı</h2>
                            <div class="table-responsive">
                                <table class="table table-sm mb-0"><tbody>
                                {% for item in upcoming %}
                                <tr><td style="width:80px">{{ item.time }}</td><td>{{ item.type }}</td><td>{{ item.name }}</td></tr>
                                {% else %}
                                <tr><td class="text-muted">Önümüzdeki 90 dakikada planlı olay yok.</td></tr>
                                {% endfor %}
                                </tbody></table>
                            </div>
                        </section>
                    </div>
                    <div class="col-lg-6">
                        <section class="panel p-4 h-100">
                            <h2 class="h5 mb-3">Jingle Denetim Günlüğü</h2>
                            <div class="scroll-box">
                                {% for item in jingle_audit %}
                                <div class="border-bottom py-2">
                                    <div class="fw-semibold">{{ item.time }} · {{ item.name or item.event }}</div>
                                    <div class="small text-muted">{{ item.event }}{% if item.reason %} · {{ item.reason }}{% endif %}{% if item.track %} · {{ item.track }}{% endif %}</div>
                                </div>
                                {% else %}
                                <div class="text-muted">Henüz jingle denetim kaydı yok.</div>
                                {% endfor %}
                            </div>
                        </section>
                    </div>
                </div>

                <div class="row g-3">
                    <div class="col-lg-6">
                        <section class="panel p-4 h-100">
                            <h2 class="h5 mb-3">Acil Anons</h2>
                            <form method="post" action="/acil-anons" class="row g-3">
                                <div class="col-md-8"><select class="form-select" name="path">{% for dosya in jingle_dosyalari %}<option value="{{ dosya.path }}">{{ dosya.name }}</option>{% endfor %}</select></div>
                                <div class="col-md-4"><select class="form-select" name="cut_policy"><option value="cut">Şimdi kes</option><option value="after">Şarkı bitince</option><option value="over">Şarkının üzerine</option></select></div>
                                <div class="col-12"><button class="btn btn-danger w-100">Acil anons çal</button></div>
                            </form>
                        </section>
                    </div>
                    <div class="col-lg-6">
                        <section class="panel p-4 h-100">
                            <h2 class="h5 mb-3">HTTPS / Alan Adı Rehberi</h2>
                            <div class="small text-muted">Ubuntu sunucuda öneri: Caddy reverse proxy. Panel için <code>panel.alanadin.com</code>, yayın için <code>radyo.alanadin.com/radyo</code>. Caddy otomatik Let's Encrypt SSL alır.</div>
                            <pre class="small bg-light border rounded p-2 mt-3 mb-0">panel.alanadin.com {
  reverse_proxy 127.0.0.1:5050
}
radyo.alanadin.com {
  reverse_proxy 127.0.0.1:8090
}</pre>
                        </section>
                    </div>
                </div>

                <section class="panel p-4">
                    <h2 class="h5 mb-3">Şarkı Favori / Yasak</h2>
                    <form method="get" action="/otomasyon" class="d-flex gap-2 mb-3">
                        <input class="form-control" name="track_q" value="{{ track_query }}" placeholder="Şarkı listesinde ara">
                        <button class="btn btn-primary">Ara</button>
                    </form>
                    <div class="scroll-box table-responsive">
                        <table class="table table-sm align-middle mb-0">
                            <thead><tr><th>Şarkı</th><th class="text-end">İşlem</th></tr></thead>
                            <tbody>
                            {% for track in muzik_dosyalari %}
                            <tr>
                                <td>{{ track.name }}</td>
                                <td class="text-end">
                                    <form method="post" action="/track-isaretle" class="d-inline">
                                        <input type="hidden" name="path" value="{{ track.path }}">
                                        <input type="hidden" name="action" value="{{ 'unfavorite' if track.path in favorites else 'favorite' }}">
                                        <button class="btn btn-outline-success btn-sm">{{ 'Favoriden çıkar' if track.path in favorites else 'Favori' }}</button>
                                    </form>
                                    <form method="post" action="/track-isaretle" class="d-inline">
                                        <input type="hidden" name="path" value="{{ track.path }}">
                                        <input type="hidden" name="action" value="{{ 'unban' if track.path in banned else 'ban' }}">
                                        <button class="btn btn-outline-danger btn-sm">{{ 'Yasağı kaldır' if track.path in banned else 'Yasakla' }}</button>
                                    </form>
                                </td>
                            </tr>
                            {% endfor %}
                            </tbody>
                        </table>
                    </div>
                </section>

                <div class="row g-3">
                    <div class="col-lg-6">
                        <section class="panel p-4 h-100">
                            <h2 class="h5 mb-3">Bugünkü Yayın Akışı</h2>
                            <div class="table-responsive"><table class="table table-sm mb-0"><tbody>{% for item in flow %}<tr><td>{{ item.time }}</td><td>{{ item.type }}</td><td>{{ item.name }}</td></tr>{% else %}<tr><td class="text-muted">Akış kuralı yok.</td></tr>{% endfor %}</tbody></table></div>
                        </section>
                    </div>
                    <div class="col-lg-6">
                        <section class="panel p-4 h-100">
                            <h2 class="h5 mb-3">Yayın Geçmişi Arama</h2>
                            <form method="get" action="/otomasyon" class="d-flex gap-2 mb-3"><input class="form-control" name="q" value="{{ query }}" placeholder="Şarkı, sanatçı, dosya ara"><button class="btn btn-primary">Ara</button></form>
                            <div class="scroll-box">{% for item in history %}<div class="border-bottom py-2"><div class="fw-semibold">{{ item.title }}</div><div class="small text-muted">{{ item.artist }} · {{ item.time }}</div></div>{% else %}<div class="text-muted">Kayıt yok.</div>{% endfor %}</div>
                        </section>
                    </div>
                </div>

                <section class="panel p-4">
                    <div class="d-flex justify-content-between align-items-center gap-3 mb-3">
                        <h2 class="h5 mb-0">Ses Kalite Taraması</h2>
                        <a class="btn btn-outline-primary btn-sm" href="/otomasyon?scan=quality">Taramayı başlat</a>
                    </div>
                    {% if scan_quality %}
                    <div class="table-responsive"><table class="table table-sm mb-0"><thead><tr><th>Dosya</th><th>Süre</th><th>Uyarı</th></tr></thead><tbody>{% for item in quality %}<tr><td>{{ item.name }}</td><td>{{ item.duration }}</td><td>{{ item.issues }}</td></tr>{% else %}<tr><td colspan="3" class="text-muted">Belirgin sorun bulunmadı.</td></tr>{% endfor %}</tbody></table></div>
                    {% else %}
                    <div class="text-muted">Bu tarama dosya sürelerini incelediği için sayfa açılışında çalıştırılmıyor.</div>
                    {% endif %}
                </section>
            </div>
        </main>
    </div>
</div>
<script src="/static/js/mobile-nav.js"></script>
</body>
</html>
















