<?php
// Mencegah error cache
header('Content-Type: application/json');
header("Cache-Control: no-cache, no-store, must-revalidate"); // HTTP 1.1.
header("Pragma: no-cache"); // HTTP 1.0.
header("Expires: 0"); // Proxies.

// Load Koneksi Database
include "configuration/config_connect.php";

// Ambil URL Favicon dari Database
$q_fav = mysqli_query($conn, "SELECT favicon FROM data LIMIT 1");
$d_fav = mysqli_fetch_assoc($q_fav);
$icon_url = "dist/img/default-icon.png"; // Fallback jika kosong

if(!empty($d_fav['favicon'])) {
    $icon_url = $d_fav['favicon'];
}

// Susun struktur JSON untuk Manifest PWA
$manifest = array(
    "id" => "/crm-dekorasia", // WAJIB ADA: Identitas unik aplikasi untuk PWA modern
    "name" => "CRM DEKOR ASIA",
    "short_name" => "CRM DEKOR", // Disingkat agar tidak terpotong di icon iPhone
    "description" => "Sistem Pipeline CRM Dekor Asia",
    "start_url" => "/index.php",
    "display" => "standalone",
    "orientation" => "portrait",
    "background_color" => "#ffffff",
    "theme_color" => "#3c8dbc",
    "icons" => array(
        array(
            "src" => $icon_url,
            "sizes" => "192x192",
            "type" => "image/png",
            "purpose" => "any maskable" // Ditambah 'maskable' agar bagus di Android/iOS
        ),
        array(
            "src" => $icon_url,
            "sizes" => "512x512",
            "type" => "image/png",
            "purpose" => "any maskable"
        )
    )
);

// Tampilkan sebagai JSON
echo json_encode($manifest, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
?>