<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Blade;

class UserDocController extends Controller
{
    public function index(Request $request)
    {
        $files = scandir(public_path($request->folder));

        return Blade::render('
            <!DOCTYPE html>
            <html lang="en">
            <head>
                <meta charset="UTF-8">
                <meta name="viewport" content="width=device-width, initial-scale=1.0">
                <title>Files</title>
            </head>
            <body>
                <ul>
                    @foreach($lists as $list)
                        <li><a href="{{ url($link_folder) }}/{{ $list }}">{{ $list }}</a></li>
                    @endforeach
                </ul>
            </body>
            </html>
        ', [
            'link_folder' => $request->folder,
            'lists' => array_filter($files, fn ($data) => ! ($data == '.' || $data == '..')),
        ]);
    }
}
