<?php
require_once __DIR__ . '/_admin.php';
$pdo = pdoOrFail();
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $stmt = $pdo->prepare('UPDATE branches SET name=:name, venue_name=:venue_name, address=:address, district=:district, phone=:phone, whatsapp=:whatsapp, map_embed=:map_embed, short_description=:short_description, seo_title=:seo_title, seo_description=:seo_description, seo_keywords=:seo_keywords WHERE id=:id');
    $stmt->execute([
        ':id' => (int)$_POST['id'], ':name' => trim($_POST['name']), ':venue_name' => trim($_POST['venue_name']), ':address' => trim($_POST['address']), ':district' => trim($_POST['district']), ':phone' => trim($_POST['phone']), ':whatsapp' => trim($_POST['whatsapp']), ':map_embed' => trim($_POST['map_embed']), ':short_description' => trim($_POST['short_description']), ':seo_title' => trim($_POST['seo_title']), ':seo_description' => trim($_POST['seo_description']), ':seo_keywords' => trim($_POST['seo_keywords'])
    ]);
    $_SESSION['flash'] = 'Sube bilgisi guncellendi.';
    header('Location: branches.php');
    exit;
}
$branches = $pdo->query('SELECT * FROM branches ORDER BY id ASC')->fetchAll();
adminHeader('Sube Yonetimi');
foreach ($branches as $branch): ?>
<form class="admin-card admin-form" method="post"><input type="hidden" name="id" value="<?= e($branch['id']) ?>"><h2><?= e($branch['name']) ?></h2><div class="form-grid">
<label>Sube adi<input name="name" value="<?= e($branch['name']) ?>" required></label><label>Mekan<input name="venue_name" value="<?= e($branch['venue_name']) ?>" required></label><label>Ilce<input name="district" value="<?= e($branch['district']) ?>"></label><label>Telefon<input name="phone" value="<?= e($branch['phone']) ?>"></label><label>WhatsApp<input name="whatsapp" value="<?= e($branch['whatsapp']) ?>"></label><label>Map embed<input name="map_embed" value="<?= e($branch['map_embed']) ?>"></label></div><label>Adres<textarea name="address"><?= e($branch['address']) ?></textarea></label><label>Kisa aciklama<textarea name="short_description"><?= e($branch['short_description']) ?></textarea></label><div class="form-grid"><label>SEO title<input name="seo_title" value="<?= e($branch['seo_title']) ?>"></label><label>SEO keywords<input name="seo_keywords" value="<?= e($branch['seo_keywords']) ?>"></label></div><label>SEO description<textarea name="seo_description"><?= e($branch['seo_description']) ?></textarea></label><button class="btn btn-primary">Kaydet</button></form>
<?php endforeach; adminFooter(); ?>
