<?php
/**
 * Get Store Information API - Global Endpoint
 * Used by Modern MessageBox system across all modules
 */
header('Content-Type: application/json');
session_start();
require_once('../includes/config.php');

// Check if user is logged in
if (!isset($_SESSION['uid'])) {
    echo json_encode([
        'success' => false, 
        'message' => 'Unauthorized'
    ]);
    exit();
}

try {
    $query = "SELECT StoreName, StoreCode, StoreLogo1, City, State FROM tblstore_settings LIMIT 1";
    $result = mysqli_query($con, $query);
    
    if ($result && mysqli_num_rows($result) > 0) {
        $storeInfo = mysqli_fetch_assoc($result);
        echo json_encode([
            'success' => true,
            'data' => $storeInfo
        ]);
    } else {
        // Return default values if no store settings found
        echo json_encode([
            'success' => true,
            'data' => [
                'StoreName' => 'UZRS Inventory',
                'StoreCode' => '',
                'StoreLogo1' => '',
                'City' => '',
                'State' => ''
            ]
        ]);
    }
} catch (Exception $e) {
    echo json_encode([
        'success' => false,
        'message' => $e->getMessage()
    ]);
}
?>
