<?php
use Psr\Container\ContainerInterface as Container;
use Dotenv\Dotenv;

if (file_exists(implode(DIRECTORY_SEPARATOR, [dirname(__DIR__, 2), '.env']))) {
  $dotenv = Dotenv::createImmutable(dirname(__DIR__, 2));
  $dotenv->load();
}

return [
  'base_path' => $_ENV['BASE_PATH'] ?? null,
  'base_url' => $_ENV['BASE_URL'] ?? null,
  'locations' => DI\decorate(function($prev, Container $container) {
    $arr = (array) $prev;
    $arr['base'] = dirname(__DIR__, 2);
    $arr['resources'] = implode(DIRECTORY_SEPARATOR, [
      $arr['base'],
      'resources'
    ]);
    $arr['routes'] = implode(DIRECTORY_SEPARATOR, [
      $arr['resources'],
      'routes'
    ]);
    $arr['templates'] = implode(DIRECTORY_SEPARATOR, [
      $arr['resources'],
      'views'
    ]);
    $arr['cache'] = implode(DIRECTORY_SEPARATOR, [
      $arr['base'],
      'cache'
    ]);
    return (object) $arr;
  }),
  'urls' => function(Container $c) {
    $arr = ['base' => ($c->has('base_url')) ? $c->get('base_url') : '/'];
    $arr['assets'] = implode('/', [
      $arr['base'],
      'assets'
    ]);
    $arr['styles'] = implode('/', [
      $arr['assets'],
      'styles'
    ]);
    $arr['scripts'] = implode('/', [
      $arr['assets'],
      'scripts'
    ]);
    $arr['images'] = implode('/', [
      $arr['assets'],
      'images'
    ]);
    $arr['api'] = 'http://localhost:8081';
    $arr['ws'] = 'ws://localhost:8020';
    return (object) $arr;
  },
  'format' => function(Container $c) {
    return [];
  }
];
