<?php
// admin/delete.php – Tar bort en kanal (med alla dess streams och metadata)
require __DIR__ . '/_auth.php';
requireLogin();

$db = db();
$id = intval($_GET['id'] ?? 0);

if (!$id) { header('Location: index.php'); exit; }

$station = $db->query("SELECT name FROM stations WHERE id=$id")->fetch(PDO::FETCH_ASSOC);
if (!$station) { flash('err', 'Kanalen hittades inte.'); header('Location: index.php'); exit; }

// ON DELETE CASCADE i databasen sköter streams, stream_status, metadata och play_log
$db->prepare("DELETE FROM stations WHERE id=?")->execute([$id]);

flash('ok', "Kanalen \"{$station['name']}\" togs bort.");
header('Location: index.php');
