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

$name = trim($_POST['name'] ?? '');
$phone = trim($_POST['phone'] ?? '');
$address = trim($_POST['address'] ?? '');

if ($name === '') {
    echo json_encode(['status'=>'error','msg'=>'Client name required']);
    exit;
}

$stmt = $conn->prepare("INSERT INTO clients (name, phone, address, status) VALUES (?, ?, ?, 1)");
$stmt->bind_param("sss", $name, $phone, $address);

if ($stmt->execute()) {
    echo json_encode([
        'status' => 'ok',
        'id' => $stmt->insert_id,
        'name' => $name
    ]);
} else {
    echo json_encode(['status'=>'error','msg'=>'DB insert failed']);
}
