<?php
require_once __DIR__.'/../../_bootstrap.php';
$u=apiUsuario($pdo);$uid=(int)$u['id'];
$linkId=(int)($_GET['link_id']??0);
try{$link=afGuardianDashboardLink($pdo,$uid,$linkId);}catch(Throwable $e){jsonResponse(['ok'=>false,'erro'=>$e->getMessage()],404);}
$minorId=(int)$link['minor_usuario_id'];
$controls=afGuardianDashboardEnsureControls($pdo,$uid,$linkId);$access=afGuardianDashboardAccessDecision($pdo,$minorId);
jsonResponse(['ok'=>true,'dependent'=>['link_id'=>$linkId,'minor_user_id'=>$minorId,'name'=>$link['nome'],'aura_id'=>$link['aura_id'],'age'=>(int)$link['idade_declarada']],'controls'=>afGuardianDashboardApiControls($controls,$access),'stats'=>afGuardianDashboardStats($pdo,$minorId),'sessions'=>afGuardianDashboardRecentSessions($pdo,$minorId,20),'incidents'=>afGuardianDashboardRecentIncidents($pdo,$minorId,20)]);
