<?php
require_once __DIR__ . '/../includes/redirect_helper.php';
$name = trim($_POST['name']);
$message = trim($_POST['message']);
$timestamp = date('Y-m-d H:i:s');

$comments_file = __DIR__ . '/../data/comments.json'; // ✅ unified path
$comments = file_exists($comments_file) ? json_decode(file_get_contents($comments_file), true) : [];

$comments[] = [
  'name'     => $name,
  'message'  => $message,
  'timestamp'=> $timestamp,
  'approved' => false,   // start unapproved
  'reply'    => ''
];

file_put_contents($comments_file, json_encode($comments, JSON_PRETTY_PRINT));
ah_redirect_back('/index.php', ['commented' => 1]);
?>
