<?php

use app\foreignone\files\ArchiveType;

return [
'foreignone' => (function() {
    global $config;

    // require_once 'lib/files.php';

    $files_collections = array_map(fn(ArchiveType $fn) => $fn->value, ArchiveType::cases());
    $coll_with_folder_support = [ArchiveType::WilliamFriedman->value, ArchiveType::Baconiana->value];

    $pagename_regex = '[a-zA-Z0-9-]+';
    $wiki_root = $config['wiki_root'];

    $routes = [
        'Main' => [
            '/'                                  => 'index',
            '{about,contacts}/'                  => 'about',
            'feed.rss'                           => 'rss',
            '('.$pagename_regex.')/'             => 'page name=$(1)',
            $wiki_root.'/'                       => 'page name='.$wiki_root,
            $wiki_root.'/('.$pagename_regex.')/' => 'page name='.$wiki_root.'/$(1)',
            'articles/'                          => 'articles',
            'articles/('.$pagename_regex.')/'    => 'post name=$(1)',
        ],
        'Files' => [
            'files/'                                                     => 'files',
            'files/(\d+)/'                                               => 'folder folder_id=$(1)',
            'files/{'.implode(',', $files_collections).'}/'              => 'collection collection=${1}',
            'files/{'.implode(',', $coll_with_folder_support).'}/(\d+)/' => 'collection collection=${1} folder_id=$(1)',
        ],
        'Services' => [
            'robots.txt'         => 'robots_txt',
            'latest-{en,ru}.pdf' => 'latest lang=${1}'
        ],
        'Admin' => [
            'admin/'                                             => 'index',
            'admin/{login,logout,log}/'                          => '${1}',
            '('.$pagename_regex.')/{delete,edit}/'               => 'page_${1} short_name=$(1)',
            '('.$pagename_regex.')/create/'                      => 'page_add short_name=$(1)',
            $wiki_root.'/('.$pagename_regex.')/{delete,edit}/'   => 'page_${1} short_name='.$wiki_root.'/$(1)',
            $wiki_root.'/('.$pagename_regex.')/create/'          => 'page_add short_name='.$wiki_root.'/$(1)',
            $wiki_root.'/{delete,edit}/'                         => 'page_${1} short_name='.$wiki_root,
            $wiki_root.'/create/'                                => 'page_add short_name='.$wiki_root,
            'articles/write/'                                    => 'post_add',
            'articles/('.$pagename_regex.')/{delete,edit}/'      => 'post_${1} short_name=$(1)',
            'admin/markdown-preview.ajax'                        => 'ajax_md_preview',
            'admin/{uploads,errors}/'                            => '${1}',
            'admin/{auth,actions}-log/'                          => '${1}_log',
            'admin/uploads/{edit_note,delete}/(\d+)/'            => 'upload_${1} id=$(1)'
        ]
    ];

    return $routes;
})(),

'ic' => (function() {
    return [
        'Main' => [
            '/' => 'index',
            'tbc/' => 'tzo',
            '{works}/' => 'books',
            'tbc/(\d+)/' => 'tzo_part part=$(1)'
        ],
    ];
})()
];
