true, 'notes' => load()]); break; case 'add': $text = trim($body['text'] ?? ''); $detail = trim($body['detail'] ?? ''); if (!$text) { http_response_code(400); echo json_encode(['ok'=>false,'error'=>'text required']); break; } $notes = load(); $note = ['id' => uniqid('n',true), 'text' => $text, 'detail' => $detail, 'done' => false, 'ts' => time() * 1000]; array_unshift($notes, $note); save($notes); echo json_encode(['ok' => true, 'note' => $note]); break; case 'toggle': $id = $body['id'] ?? ''; $notes = load(); foreach ($notes as &$n) { if ($n['id'] === $id) { $n['done'] = !$n['done']; break; } } save($notes); echo json_encode(['ok' => true]); break; case 'delete': $id = $body['id'] ?? ''; $notes = array_values(array_filter(load(), fn($n) => $n['id'] !== $id)); save($notes); echo json_encode(['ok' => true]); break; case 'clear-done': $notes = array_values(array_filter(load(), fn($n) => !$n['done'])); save($notes); echo json_encode(['ok' => true]); break; case 'edit': $id = $body['id'] ?? ''; $text = trim($body['text'] ?? ''); $detail = trim($body['detail'] ?? ''); if (!$text) { http_response_code(400); echo json_encode(['ok'=>false,'error'=>'text required']); break; } $notes = load(); foreach ($notes as &$n) { if ($n['id'] === $id) { $n['text'] = $text; $n['detail'] = $detail; break; } } save($notes); echo json_encode(['ok' => true]); break; default: http_response_code(404); echo json_encode(['ok' => false, 'error' => 'unknown action']); }