<?php
// cms/tracking-codes-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);
    $data = ['tracking_codes_head' => '', 'tracking_codes_body' => ''];

    if ($generalData) {
        $businessInfoId = $generalData['id'];
        $stmt = $pdo->prepare("SELECT tracking_codes_head, tracking_codes_body FROM tracking_codes WHERE business_info_id = ?");
        $stmt->execute([$businessInfoId]);
        $trackingData = $stmt->fetch(PDO::FETCH_ASSOC);
        if ($trackingData) {
            $data = $trackingData;
        }
    }
    
    echo json_encode(['success' => true, 'data' => $data]);

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