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

$uid = $conn->real_escape_string($_GET['id']);

// 1. Info del Usuario
$u = $conn->query("SELECT name, picture_url, custom_pic, mood, fb_url, ig_url, tt_url, theme_color FROM users WHERE google_id = '$uid'")->fetch_assoc();

// 2. Sus Trabajos Terminados (Fotos de la comunidad)
$posts = [];
$res_p = $conn->query("SELECT image_data, caption FROM community_posts WHERE user_id = '$uid' ORDER BY id DESC");
while($row = $res_p->fetch_assoc()) { $posts[] = $row; }

// 3. Sus Moldes Públicos
$molds = [];
$res_m = $conn->query("SELECT title, image_data, category FROM projects WHERE user_id = '$uid' AND visibility = 'public' ORDER BY id DESC");
while($row = $res_m->fetch_assoc()) { $molds[] = $row; }

echo json_encode(["user" => $u, "posts" => $posts, "molds" => $molds]);
$conn->close();
?>
