<?php
// DIC configuration
use DI\Container;
use Slim\Flash\Messages;

$container = new Container();
// $container = $app->getContainer();

$container->set('settings', function(){
    return [
        'displayErrorDetails' => true, // set to false in production
        'addContentLengthHeader' => false, // Allow the web server to send the content-length header
        'debug' => false,
        'testing' => false,        
        'close_registration' => true,

        // Renderer settings
        'renderer' => [
            'template_path' => __DIR__ . '/../templates/',
            //'cache_path' => __DIR__.'/../templates/.cache/',
            'cache_path' => false,
            'autoreload' => true,
            'debug' => true
        ],

        
        'db' => [
            'path' => __DIR__."/../db/surfaces2018.db",
            'schema' => __DIR__."/../db/schema.sql",
            'load_schema' =>  __DIR__."/../db/.schema.lock"
        ],
        'recaptcha' => [
          'secret' => "6LesRDsUAAAAAA6t3UgL4U4Foc9njmXX-8HIiLj_",
          'secrettest' => "6LeIxAcTAAAAAGG-vFI1TnRWxMZNFuojJ4WifJWe",
          'sitekey' => "6LesRDsUAAAAAJvyoODvjiza9u75qEGJmbKHEV6s",
          'sitekeytest' => "6LeIxAcTAAAAAJcZVRqyHh71UMIEGNQ_MXjiZKhI"
        ],
        
    ];
});

$container->set('flash', function($c){
    $storage = [];
    return new Messages($storage);
});

// $container['renderer'] = function ($c) {
//     $settings = $c->get('settings')['renderer'];

//     $view = new Slim\Views\Twig($settings['template_path'],[
//         'cache' => $settings['cache_path'],

//     ]);

//     $view->addExtension(new Knlv\Slim\Views\TwigMessages(
//       new Slim\Flash\Messages() 
//     ));
//     return $view;
// };

$container->set('db', function ($c) {
    $dbconf = $c->get('settings')['db'];
    try{
        $db = new DB($dbconf['path']);
        if(!file_exists($dbconf['load_schema'])){
          $db->loadSchema($dbconf['schema']);
          touch($dbconf['load_schema']);
        }

    }
    catch(\PDOException $e){
        echo $e->getMessage();
    }
    return $db;
});
// monolog
// $container['logger'] = function ($c) {
//     $settings = $c->get('settings')['logger'];
//     $logger = new Monolog\Logger($settings['name']);
//     $logger->pushProcessor(new Monolog\Processor\UidProcessor());
//     $logger->pushHandler(new Monolog\Handler\StreamHandler($settings['path'], $settings['level']));
//     return $logger;
// };