<?php

return [
   'debug'  => true,
   'markdown' => [
      'extra' => false
   ],


   'kangaroopunch.kangaworld-integration' => [
      'sql' => [
   		'host' => 'mysql',
   		'port' => 3306,
   		'data' => 'dosThing',
   		'user' => 'dosThing',
   		'pass' => 'password'
   	]
   ],

   // For REST APIs.
   'api' => [
      'basicAuth' => true,
      'allowInsecure' => true
   ],

   'hooks' => [
       // See:  https://getkirby.com/docs/cookbook/extensions/subpage-builder
       'route:after' => function ($route, $path, $method) {
           $uid = explode('/', $path);
           $uid = end($uid);
           $uid = str_replace('+', '/', $uid);
           $page = kirby()->page($uid);
           if ($page && $page->children()->isEmpty()) {
               buildPageTree($page);
           }
       }
   ],

   'email' => [
      'transport' => [
         'type' => 'smtp',
         'host' => 'mail.jaegertech.com',
         'port' => 465,
         'security' => true,
         'auth' => true,
         'username' => '...',
         'password' => '...'
      ]
   ],

   'user.email.activation' => true,
   'user.email.activation.sender' => 'noreply@kangaroopunch.com',
   'user.email.activation.subject' => 'Kanga World Account Activation',

   'routes' => [
      [
         'pattern' => 'logout',
         'action'  => function() {

            if ($user = kirby()->user()) {
               $user->logout();
            }

            go('/');
         }
      ],
      [
         'pattern' => 'user/activate/(:alphanum)',
         'action'  => function($token) {

            if (option('user.email.activation', false) === false) {
               go();
            }

            $kirby = kirby();
            $kirby->impersonate('kirby');

            if ($user = $kirby->users()->findBy('emailActivationToken', $token)) {
               if ($user->emailActivationToken()->toString() === Str::toType($token, 'string')) {
                  $user->update(['emailActivation' => true]);
                  $kirby->session()->set('kpActivated', true);
                  go('/activated');
               } else {
                  return false;
                  //go('CUSTOM_ERROR_ACTIVATION_PAGE');
                  //return page('CUSTOM_ERROR_ACTIVATION_PAGE');
               }
            }

            $kirby->impersonate();
         }
      ]
   ]

];
