@page
@model WorkFlowCheck.Web.Pages.BaseStock.PDFFiles.PDFFilesPageModel
@using WorkFlowCheck.Common.Helper
@using WorkFlowCheck.Common.DTO
@{
    ViewData["Title"] = "PDF fájlok";
}
<h1>@ViewData["Title"]</h1>

<div class="card shadow p-4">
    <table id="tbPDFFilesPage" class="table table-bordered table-hover table-sm" style="width:100%">
        <thead class="table-primary">
            <tr>
                <th>ID</th>
                <th>@DisplayNameHelper.GetDisplayName(nameof(PDFFileDTO.FileName), typeof(PDFFileDTO))</th>
                <th>@DisplayNameHelper.GetDisplayName(nameof(PDFFileDTO.CreateDate), typeof(PDFFileDTO))</th>
                <th>@DisplayNameHelper.GetDisplayName(nameof(PDFFileDTO.FileSize), typeof(PDFFileDTO))</th>
                <th class="text-center">Action</th>
            </tr>
        </thead>
        <tfoot class="table-light">
            <tr>
                <th>ID</th>
                <th>@DisplayNameHelper.GetDisplayName(nameof(PDFFileDTO.FileName), typeof(PDFFileDTO))</th>
                <th>@DisplayNameHelper.GetDisplayName(nameof(PDFFileDTO.FileSize), typeof(PDFFileDTO))</th>
                <th>@DisplayNameHelper.GetDisplayName(nameof(PDFFileDTO.CreateDate), typeof(PDFFileDTO))</th>
                <th>Action</th>
            </tr>
        </tfoot>
    </table>
</div>

@section Scripts {
    <script>
        const table = new DataTable('#tbPDFFilesPage', {
                ajax: {
                        url: "@Url.Page("./PDFFilesPage", "LoadPDFFiles")",
                        type: "GET",
                        dataSrc : "data"
                },
                columns: [
                    { data: "id" },
                    { data: "fileName" },
                    { data: "createDate" },
                    { data: "fileSize" },
                    { data: null, render: function (data, type, row) {
                         return renderActionButtonsDownloadPDFs(row.id);
                    }}
                ],
                columnDefs: [
                    {
                        "targets": 0,
                        "visible": false
                    },
                    {
                        "targets": 2,
                        "className": "text-start"
                    },
                    {
                        "targets": 3,
                        "className": "text-end"
                    },
                    {
                        "targets": 4,
                        "className": "text-center",
                        "width": "10%"
                    }
                ],

                processing:true,
                language: { url: '//cdn.datatables.net/plug-ins/2.2.2/i18n/hu.json',}
        });

        $('#tbPDFFilesPage').on('click', '.download-btn', function ()
        {
            const row = table.row($(this).closest('tr')).data();
            window.location.href = `@Url.Page("/BaseStock/PDFFiles/PDFFilesPage")?handler=DownloadFile&filename=${row.fileName}`;
        });
    </script>
}
