<?php

use Dotenv\Dotenv;

/*
|--------------------------------------------------------------------------
| Load Environment File
|--------------------------------------------------------------------------
|
| We will first load the appropriate .env file based on the hostname.
| This allows different configurations based on the domain.
|
*/

$hostname = $_SERVER['HTTP_HOST'] ?? 'localhost';
$envFiles = [
    'gamedev1.site' => '.env.dewabet303',
    'gamedev2.site' => '.env.shio338',
    'gamedev3.site' => '.env.totoslot99',
];

// Payslot88
$envFiles += [
    'rtp-xlslot88.click'        => '.env.xlslot88',
    'rtp-xlslot88.cloud'        => '.env.xlslot88',

    'rtprealpayslot88.xyz'      => '.env.payslot88',
    'rtprealpayslot88.info'     => '.env.payslot88',
    'rtprealpayslot88.live'     => '.env.payslot88',
    'rtprealpayslot88.online'   => '.env.payslot88',
    'rtprealpayslot88.store'    => '.env.payslot88',
    'rtprealpayslot88.art'      => '.env.payslot88',
    'rtprealpayslot88.site'     => '.env.payslot88',
    'rtp-payslot88.one'         => '.env.payslot88',

    'rtptotoslot99c.store'      => '.env.totoslot99',
    'rtp-totoslot99.lol'        => '.env.totoslot99',
    'rtp-totoslot99.store'      => '.env.totoslot99',
    'rtp-totoslot99.site'       => '.env.totoslot99',
    'rtp-totoslot99.online'     => '.env.totoslot99',
    'rtp-totoslot99.club'       => '.env.totoslot99',
    'rtp-totoslot99best.site'   => '.env.totoslot99',
    'rtp-totoslot99best.store'  => '.env.totoslot99',

    'rtp-indokoin.lol'          => '.env.indokoin',
    'rtp-indokoin.store'        => '.env.indokoin',
    'rtp-indokoin.site'         => '.env.indokoin',
    'rtp-indokoin.club'         => '.env.indokoin',
    'rtp-indokoin.info'         => '.env.indokoin',
    'rtp-indokoin.pro'          => '.env.indokoin',

    'rtprealxo4d.xyz'           => '.env.xo4d',
    'rtprealxo4d.pro'           => '.env.xo4d',
    'rtprealxo4d.info'          => '.env.xo4d',
    'rtprealxo4d.live'          => '.env.xo4d',
    'rtprealxo4d.store'         => '.env.xo4d',
    'rtprealxo4d.site'          => '.env.xo4d',

    'rtp-qris288.site'          => '.env.qris288',
    'rtp-qris288.store'         => '.env.qris288',
    'rtp-qris288.club'          => '.env.qris288',
    'rtp-qris288.info'          => '.env.qris288',
    'rtp-qris288best.online'    => '.env.qris288',
    'rtp-qris288best.store'     => '.env.qris288',

    'rtpdewabet303jp.xyz'       => '.env.dewabet303',
    'rtpdewabet303jp.live'      => '.env.dewabet303',
    'rtpdewabet303jp.info'      => '.env.dewabet303',

    'rtp-mantan4d.live'         => '.env.mantan4d',
    'rtp-mantan4d.club'         => '.env.mantan4d',
    'rtp-mantan4d.store'        => '.env.mantan4d',
    'rtp-mantan4d.site'         => '.env.mantan4d',

];

if (array_key_exists($hostname, $envFiles)) {
    $envFile = $envFiles[$hostname];
    $envPath = __DIR__ . '/../env/' . $envFile;
    if (file_exists($envPath)) {
        $dotenv = Dotenv::createImmutable(__DIR__ . '/../env', $envFile);
        $dotenv->load();
    }
} else {
    // Optionally load a default .env file if no match is found
    $dotenv = Dotenv::createImmutable(__DIR__ . '/../');
    $dotenv->load();
}

/*
|--------------------------------------------------------------------------
| Create The Application
|--------------------------------------------------------------------------
|
| The first thing we will do is create a new Laravel application instance
| which serves as the "glue" for all the components of Laravel, and is
| the IoC container for the system binding all of the various parts.
|
*/

$app = new Illuminate\Foundation\Application(
    $_ENV['APP_BASE_PATH'] ?? dirname(__DIR__)
);

/*
|--------------------------------------------------------------------------
| Bind Important Interfaces
|--------------------------------------------------------------------------
|
| Next, we need to bind some important interfaces into the container so
| we will be able to resolve them when needed. The kernels serve the
| incoming requests to this application from both the web and CLI.
|
*/

$app->singleton(
    Illuminate\Contracts\Http\Kernel::class,
    App\Http\Kernel::class
);

$app->singleton(
    Illuminate\Contracts\Console\Kernel::class,
    App\Console\Kernel::class
);

$app->singleton(
    Illuminate\Contracts\Debug\ExceptionHandler::class,
    App\Exceptions\Handler::class
);

/*
|--------------------------------------------------------------------------
| Return The Application
|--------------------------------------------------------------------------
|
| This script returns the application instance. The instance is given to
| the calling script so we can separate the building of the instances
| from the actual running of the application and sending responses.
|
*/

return $app;
