// Look around.

import { readdirSync } from "fs"
import { NOSE_WWW } from "@/config"
import { projectName, projectDir } from "@/project"
import { sessionGet } from "@/session"

export default function () {
    const project = projectName()
    const root = sessionGet("cwd") || projectDir()

    let files: string[] = []

    for (const file of readdirSync(root, { withFileTypes: true })) {
        files.push(file.isDirectory() ? `${file.name}/` : file.name)
    }

    if (root === NOSE_WWW) {
        files = files.filter(file => file.endsWith(`${project}.ts`) || file.endsWith(`${project}.tsx`))
    }

    return <>
        {root !== projectDir() && <a href="#cd ..;ls">..</a>}
        {files.map(file =>
            <a href={file.endsWith('/') ? `#cd ${file};ls` : `#cat ${file}`}>{file}</a>
        )}
    </>
}