<?php
include 'db.php'; // your database connection
header('Content-Type: application/json'); // return JSON

if(isset($_POST['id'])) {
    $id = intval($_POST['id']);
    $row = $conn->query("SELECT is_price_visible, price FROM services WHERE id=$id")->fetch_assoc();
    if($row) {
        $new = $row['is_price_visible'] ? 0 : 1; // toggle
        $conn->query("UPDATE services SET is_price_visible=$new WHERE id=$id");
        echo json_encode(['success'=>true, 'new'=>$new, 'price'=>$row['price']]);
        exit;
    }
}
echo json_encode(['success'=>false]);
