<?php
header("Content-Type: application/json; charset=UTF-8");
header("Access-Control-Allow-Methods: POST");
include_once 'db_connect.php';

$id = $_POST['id'] ?? '';
$name_ar = $_POST['name_ar'] ?? '';
$name_en = $_POST['name_en'] ?? '';

if (!empty($id) && !empty($name_ar) && !empty($name_en)) {
    try {
        $stmt = $conn->prepare("UPDATE medical_specialties SET name_ar = ?, name_en = ? WHERE id = ?");
        if ($stmt->execute([$name_ar, $name_en, $id])) {
            echo json_encode([
                "status" => "success",
                "message" => "تم تحديث الاختصاص بنجاح"
            ]);
        } else {
            echo json_encode(["status" => "error", "message" => "لم يتم إجراء أي تغييرات"]);
        }
    } catch (Exception $e) {
        echo json_encode(["status" => "error", "message" => $e->getMessage()]);
    }
} else {
    echo json_encode(["status" => "error", "message" => "بيانات غير مكتملة للتحديث"]);
}
?>