<?php
require_once __DIR__ . '/env.php';

$envFile = dirname(__DIR__) . '/.env';
if (!file_exists($envFile)) {
    if (PHP_SAPI === 'cli') {
        fwrite(STDERR, "Family Hub: .env file not found.\n");
        fwrite(STDERR, "Open install.php in your browser or copy env.example to .env and edit.\n");
        exit(1);
    }
    header('Location: install.php');
    exit;
}

// Load environment variables
Env::load();

// Paths
define('ROOT_PATH', dirname(__DIR__));
define('DATA_PATH', ROOT_PATH . '/data');
define('EXPORT_PATH', ROOT_PATH . '/exports');

// Google API Configuration
define('GOOGLE_CLIENT_ID', Env::get('GOOGLE_CLIENT_ID'));
define('GOOGLE_CLIENT_SECRET', Env::get('GOOGLE_CLIENT_SECRET'));
define('GOOGLE_REDIRECT_URI', Env::get('GOOGLE_REDIRECT_URI'));
define('GOOGLE_CALENDAR_ID', Env::get('GOOGLE_CALENDAR_ID'));
define('GOOGLE_CALENDAR_EMBED_CODE', Env::get('GOOGLE_CALENDAR_EMBED_CODE'));
define('GOOGLE_DRIVE_FOLDER_ID', Env::get('GOOGLE_DRIVE_FOLDER_ID'));

// Application Settings
define('APP_ENV', Env::get('APP_ENV', 'production'));
define('APP_DEBUG', Env::get('APP_DEBUG', 'false') === 'true');
define('APP_URL', Env::get('APP_URL', 'http://localhost/family-hub'));

// Export settings
define('EXPORT_DESTINATION', EXPORT_PATH);
define('EXPORT_FREQUENCY', Env::get('EXPORT_FREQUENCY', 'daily'));
define('EXPORT_RETENTION_DAYS', (int)Env::get('EXPORT_RETENTION_DAYS', 30));

// Tab configuration
$TABS = [
    'chores' => ['title' => 'Chores', 'icon' => 'tasks'],
    'groceries' => ['title' => 'Grocery List', 'icon' => 'shopping-cart'],
    'meals' => ['title' => 'Meal Plan', 'icon' => 'utensils'],
    'calendar' => ['title' => 'Calendar', 'icon' => 'calendar-days'],
    'currency' => ['title' => 'Currency', 'icon' => 'coins'],
    'settings' => ['title' => 'Family settings', 'icon' => 'cog'],
];

// Load local configuration if exists
if (file_exists(__DIR__ . '/local.php')) {
    include __DIR__ . '/local.php';
}
?>