<?php
require_once __DIR__ . '/../includes/redirect_helper.php';
session_start();
$role = $_SESSION['role'] ?? 'guest';
if (!in_array($role, ['master','admin'])) {
  header('Location: /login/index.php');
  exit;
}

$friends_file = __DIR__ . '/../data/friends.json';
$friends = file_exists($friends_file) ? json_decode(file_get_contents($friends_file), true) : [];

$id = isset($_GET['delete']) ? (int)$_GET['delete'] : -1;
if ($id >= 0 && isset($friends[$id])) {
  array_splice($friends, $id, 1);
  file_put_contents($friends_file, json_encode(array_values($friends), JSON_PRETTY_PRINT));
}

ah_redirect_back('/admin/friends.php', ['saved' => 1]);
?>
