<?php
/**
 * WeaverSM Configuration
 */
if (defined('CONFIG_LOADED')) return;
define('CONFIG_LOADED', true);

if (session_status() === PHP_SESSION_NONE) {
    session_start();
}

error_reporting(E_ALL);
ini_set('display_errors', 0);
date_default_timezone_set('UTC');

// Site Settings
define('SITE_NAME', 'WeaverSM');
define('SITE_EMAIL', 'support@weaversm.com');

// Auto-detect URL so dev (Replit) and production both work
if (!defined('SITE_URL')) {
    if (!empty($_SERVER['HTTP_HOST'])) {
        $scheme = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? 'https' : 'http';
        define('SITE_URL', $scheme . '://' . $_SERVER['HTTP_HOST']);
    } else {
        define('SITE_URL', 'https://weaversm.com');
    }
}

// Paths
define('ROOT_PATH', dirname(__DIR__) . '/');
define('CONFIG_PATH', ROOT_PATH . 'config/');
define('INCLUDES_PATH', ROOT_PATH . 'includes/');
define('CLASSES_PATH', ROOT_PATH . 'classes/');
define('UPLOADS_PATH', ROOT_PATH . 'uploads/');
define('UPLOADS_URL', SITE_URL . '/uploads');

// Security
define('MAX_LOGIN_ATTEMPTS', 5);
define('LOCKOUT_DURATION', 15);
define('CSRF_TOKEN_EXPIRY', 3600);

// Banner Settings
define('BANNER_MAX_WIDTH', 800);
define('BANNER_MAX_HEIGHT', 200);

// Include files
require_once CONFIG_PATH . 'database.php';
require_once INCLUDES_PATH . 'functions.php';
require_once INCLUDES_PATH . 'security.php';

// Autoload classes
spl_autoload_register(function ($class) {
    $file = CLASSES_PATH . $class . '.php';
    if (file_exists($file)) {
        require_once $file;
    }
});
