import Link from "next/link";
import fs from 'fs';
import path from 'path';

export async function getData() {
    let dirs: string[] = [];
    try {
        fs.readdirSync(__dirname).filter(item => {
            const p = path.resolve(__dirname, item);
            const stat = fs.statSync(p);
            if (stat.isDirectory()) dirs.push(item)
        });
    } catch (e) {
        console.error(e)
    }

    return dirs;
}

export default async function Page() {
    const list = await getData();
    return (
        <>
            <span>Components List</span>
            {
                list.map(i => {
                    return (
                        <li key={i}>
                            <Link href={`/components/${i}`}>{i}</Link>
                        </li>
                    )
                })
            }
        </>
    )
}