<?php

require __DIR__.'/include/AltoRouter.php';
require __DIR__.'/include/config.php';

$router = new AltoRouter(); 

// map homepage
$router->map( 'GET|POST', '/', function() {
  require __DIR__ . '/views/home.php';
});


$router->map( 'GET', '/progressier.js', function() {
  require __DIR__ . '/load_progressier.php';
});

// MODAL
$router->map( 'GET|POST', '/getModal/Contacts/[*:id]', function($param) {
  require __DIR__ . '/views/modal__contacts_new.php';
});

$router->map( 'GET|POST', '/my-profile', function($param) {
  require __DIR__ . '/views/profile.php';
});
$router->map( 'GET|POST', '/my-cards', function($param) {
  require __DIR__ . '/views/cards.php';
});
$router->map( 'GET|POST', '/my-cards/[*:id]/[*:action]', function($param) {
  require __DIR__ . '/views/cards.php';
});
$router->map( 'GET|POST', '/my-targets', function($param) {
  require __DIR__ . '/views/targets.php';
});
$router->map( 'GET|POST', '/my-targets/[*:id]/[*:action]', function($param) {
  require __DIR__ . '/views/targets.php';
});
$router->map( 'GET|POST', '/open/[*:encoded_id]', function($param) {
  require __DIR__ . '/public_goto.php';
});



$router->map( 'GET|POST', '/auth', function($param) {
  require __DIR__ . '/login.php';
});
$router->map( 'GET|POST', '/install', function($param) {
  require __DIR__ . '/views/pwa_install.php';
});

// map users details page
$router->map( 'GET|POST', '/api/[a:controller]/[*:id]/[*:action]', function( $param ) {
  require __DIR__ . '/api.php';
});

$router->map( 'GET|POST', '/oauth2/[*:id]/[*:action]', function( $param ) {
  require __DIR__ . '/oauth2.php';
});
// map users details page
$router->map( 'GET|POST', '/goto/[a:entity]:[*:entity_id]', function( $param ) {
  require __DIR__ . '/goto.php';
});

$match = $router->match();  
if($match && is_callable( $match['target'] )){
    call_user_func($match['target'], $match['params']);
}else {
	// no route was matched
	header( $_SERVER["SERVER_PROTOCOL"] . ' 404 Not Found');
}



