<?php
/**
 * Diagnóstico rápido (eliminar después de resolver problemas).
 */
header( 'Content-Type: text/plain; charset=utf-8' );

echo "PHP: " . PHP_VERSION . "\n";

$config_file = dirname( __DIR__ ) . '/config/config.php';
echo "config.php: " . ( is_readable( $config_file ) ? 'OK' : 'NO ENCONTRADO' ) . "\n";

if ( ! is_readable( $config_file ) ) {
	exit;
}

$config = require $config_file;
if ( ! is_array( $config ) ) {
	echo "config.php: ERROR (no devuelve un array)\n";
	exit;
}

echo "app_url (config): " . ( $config['app_url'] ?? '(vacío)' ) . "\n";

require_once dirname( __DIR__ ) . '/core/App.php';
JB_App::load_config();
require_once dirname( __DIR__ ) . '/core/Http.php';
echo "app_url (detectada): " . jb_planeacion_resolve_app_url() . "\n";

$panel_css = jb_planeacion_resolve_app_url() . '/assets/css/panel.css';
echo "panel.css: " . $panel_css . "\n";

$db = $config['db'] ?? array();
try {
	$dsn = sprintf(
		'mysql:host=%s;port=%d;dbname=%s;charset=%s',
		$db['host'] ?? 'localhost',
		(int) ( $db['port'] ?? 3306 ),
		$db['name'] ?? '',
		$db['charset'] ?? 'utf8mb4'
	);
	$pdo = new PDO( $dsn, $db['user'] ?? '', $db['password'] ?? '', array(
		PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
	) );
	echo "MySQL: OK\n";
} catch ( Throwable $e ) {
	echo "MySQL: ERROR - " . $e->getMessage() . "\n";
}

echo "installed: " . ( is_readable( dirname( __DIR__ ) . '/storage/.installed' ) ? 'sí' : 'no' ) . "\n";
