<?php
/**
 * Grav Multi-Site Setup Configuration
 * Maps hostnames to environment-specific directories
 * Only overrides 'page' stream to serve environment-specific content
 */

$hostname = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : 'localhost';
$hostname = preg_replace('/:\d+$/', '', $hostname);
$hostname = strtolower($hostname);

$hostMap = [
    'charters.turnsys.com' => 'charters.turnsys.com',
    'plan.afabn.org' => 'plan.afabn.org',
    'plan.ap4ap.org' => 'plan.ap4ap.org',
    'plan.ezeda.org' => 'plan.ezeda.org',
    'plan.ezpodstack.org' => 'plan.ezpodstack.org',
    'plan.hfnoc.net' => 'plan.hfnoc.net',
    'plan.knownelement.com' => 'plan.knownelement.com',
    'plan.meetmorse.com' => 'plan.meetmorse.com',
    'plan.merchantsofhope.org' => 'plan.merchantsofhope.org',
    'plan.rackrental.net' => 'plan.rackrental.net',
    'plan.redwfo.com' => 'plan.redwfo.com',
    'plan.rwscp.net' => 'plan.rwscp.net',
    'plan.sidedoorgroup.org' => 'plan.sidedoorgroup.org',
    'plan.sol-calc.com' => 'plan.sol-calc.com',
    'plan.suborbital-systems.com' => 'plan.suborbital-systems.com',
    'plan.teamrental.net' => 'plan.teamrental.net',
    'plan.thecampustradingcompany.com' => 'plan.thecampustradingcompany.com',
    'plan.thepeernet.com' => 'plan.thepeernet.com',
    'plan.turnsys.com' => 'plan.turnsys.com',
    'plan.yourdreamnamehere.com' => 'plan.yourdreamnamehere.com',
    'plan.startinglineproductions.com' => 'plan.startinglineproductions.com',
    'staticsites.turnsys.com' => 'staticsites.turnsys.com',
];

$environment = isset($hostMap[$hostname]) ? $hostMap[$hostname] : 'staticsites.turnsys.com';
$envPath = GRAV_ROOT . '/user/env/' . $environment;

if (!is_dir($envPath)) {
    $envPath = GRAV_ROOT . '/user/env/staticsites.turnsys.com';
}

// Only override page stream - use environment pages, fallback to default
return [
    'streams' => [
        'schemes' => [
            'page' => [
                'type' => 'ReadOnlyStream',
                'prefixes' => [
                    '' => [$envPath . '/pages', 'user://pages'],
                ],
            ],
        ],
    ],
];
