<?php

use xmvc\MVC;

$title = $this->title($type);
$parseDir = $this->parseDir($type);
$fix = $type == 'xmvc' ? 'xmvc_' : '';
$allFilesFileName = $parseDir . "/{$fix}allFiles.php";
if (!is_file($allFilesFileName)) {
    MVC::warningExit("未找到文档");
}
$allFiles = require($allFilesFileName);
$allMethods = require($parseDir . "/{$fix}allMethods.php");
$methodsJson = json_encode($allMethods, JSON_UNESCAPED_UNICODE);

$allFiles['function'] = $allFiles['function'] ?? ['none' => []];
$allFiles['interface'] = $allFiles['interface'] ?? [];
$allFiles['class'] = $allFiles['class'] ?? [];
// @codingStandardsIgnoreStart
?>

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charSet="utf-8" />
    <title><?= $title ?></title>
    <style>
        <?php require(__DIR__ . '/style.css'); ?>
    </style>
    <?php require(__DIR__ . '/javascript.php'); ?>
</head>

<body>
    <div class="div-main">
        <?php require(__DIR__ . '/search.tpl.php'); ?>
        <div class="div-doc">
            <h1><?= $title ?></h1>
            <h2>概述</h2>
            <ul class="overview">
                <li><a href="<?= url('xmvc/doc/phpdoc/index-overview') ?>" target="_blank">概述</a></li>
                <li><a href="<?= url('xmvc/doc/phpdoc/index-metadata') ?>" target="_blank">元数据</a></li>
            </ul>
            <? if (!empty($allFiles['function']) && !empty($allFiles['function']['none'])) {?>
            <h2>函数</h2>
            <ul>
                <?php foreach ($allFiles['function']['none'] as $item) : ?>
                    <li class="class-name"><a href="<?= $this->itemUrl($item) ?>"><?= $item['relFile'] ?><span class="summary"><?= $item['summary'] ?></span></a></li>
                <?php endforeach; //函数库 
                ?>
            </ul>
            <? }; // 函数?>
            <? if (!empty($allFiles['interface'])) :?>
            <h2>接口</h2>
            <ul>
                <?php foreach ($allFiles['interface'] as $namespace => $items) : ?>
                    <h3 class="namespace"><?= $namespace ?></h3>
                    <ul>
                        <?php foreach ($items as $item) : ?>
                            <li class="class-name"><a href="<?= $this->itemUrl($item) ?>"><?= basename(str_replace('\\', '/', $item['name'])) ?><span class="summary"><?= $item['summary'] ?></span></a></li>
                        <?php endforeach;
                        ?>
                    </ul>
                <?php endforeach; //接口 
                ?>
            </ul>
            <? endif; // 接口?>
            <? if (!empty($allFiles['class'])) :?>
            <h2>类库</h2>
            <ul>
                <?php foreach ($allFiles['class'] as $namespace => $items) : ?>
                    <?php if ($namespace != 'xmvc\\test') : ?>
                        <h3 class="namespace"><?= $namespace ?></h3>
                        <ul>
                            <?php foreach ($items as $item) : ?>
                                <li class="class-name"><a href="<?= $this->itemUrl($item) ?>"><?= basename(str_replace('\\', '/', $item['name'])) ?><span class="summary"><?= $item['summary'] ?></span></a></li>
                            <?php endforeach;
                            ?>
                        </ul>
                <?php endif;
                endforeach; //类 
                ?>
            </ul>
            <? endif; // 类库?>
            <h2>测试</h2>
            <ul>
                <?php foreach ($allFiles['class'] as $namespace => $items) : ?>
                    <?php if (strpos($namespace,$type . '\\test') === 0) : ?>
                        <h3 class="namespace"><?= $namespace ?></h3>
                        <ul>
                            <?php foreach ($items as $item) : ?>
                                <li class="class-name"><a href="<?= $this->itemUrl($item) ?>"><?= basename(str_replace('\\', '/', $item['name'])) ?><span class="summary"><?= $item['summary'] ?></span></a></li>
                            <?php endforeach;
                            ?>
                        </ul>
                <?php endif;
                endforeach; //类 
                ?>
            </ul>
            <div style="height:100px"></div>
        </div><!-- div-menu -->
    </div><!-- div-main -->
</body>

</html>