<?php
header('Content-Type: application/json');
require_once 'config.php';

$customer_id = $_POST['customer_id'] ?? '';
$description = $_POST['description'] ?? '';

if (!$customer_id || !$description) {
    echo json_encode(['success' => false, 'message' => 'Missing required fields']);
    exit;
}

$complaint_date = date('Y-m-d H:i:s');
$status = 'Pending';
$recommendation = '';

$stmt = $conn->prepare("INSERT INTO complaints (customer_id, complaint_date, description, status, recommendation) VALUES (?, ?, ?, ?, ?)");
$stmt->bind_param("sssss", $customer_id, $complaint_date, $description, $status, $recommendation);

if ($stmt->execute()) {
    echo json_encode(['success' => true, 'message' => 'Complaint submitted successfully']);
} else {
    echo json_encode(['success' => false, 'message' => 'Failed to submit complaint']);
}

$stmt->close();
