<?php
// cms/social-links-read.php
header('Content-Type: application/json');

require_once('db_connection.php');

try {
    $stmt = $pdo->query("SELECT id FROM business_info ORDER BY updated_at DESC LIMIT 1");
    $generalData = $stmt->fetch(PDO::FETCH_ASSOC);
    $links = [];

    if ($generalData) {
        $businessInfoId = $generalData['id'];
        $stmtLinks = $pdo->prepare("SELECT link_icon, link_url FROM social_links WHERE business_info_id = ? ORDER BY id ASC");
        $stmtLinks->execute([$businessInfoId]);
        $links = $stmtLinks->fetchAll(PDO::FETCH_ASSOC);
    }
    
    echo json_encode(['success' => true, 'data' => $links]);

} catch (PDOException $e) {
    http_response_code(500);
    echo json_encode(['success' => false, 'message' => 'Error Al Cargar Los Datos' . $e->getMessage()]);
}
?>