<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>
        Previous Flights || <%= config.name %>
    </title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta2/dist/css/bootstrap.min.css" rel="stylesheet"
        integrity="sha384-BmbxuPwQa2lc/FVzBcNJ7UAyJxM6wuqIj61tLrc4wSX0szH/Ev+nYRRuWlolflfl" crossorigin="anonymous">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.4.0/font/bootstrap-icons.css">
    <link rel="stylesheet" href="https://unpkg.com/bootstrap-table@1.18.3/dist/bootstrap-table.min.css">
    <%- include("./components/head.ejs")%>
</head>

<body class="w-100 bg-light-light h-auto">
    <%- include("./components/nav.ejs")%>
        <div class="w-100 content bg-light-light px-3 px-md-5 pt-3 mb-4" id="content">
            <h2>Previous Flights</h2>
            <p class="text-muted">Click on a pirep to see more.</p>
            <div class="table-responsive">
            <table data-toggle="table" data-search="true" data-show-columns="true" id="mainTable">
                <thead>
                    <tr class="tr-class-2">
                        <th data-field="route">Route</th>
                        <th data-field="airline">Airline</th>
                        <th data-field="aircraft">Aircraft</th>
                        <th data-field="status">Status</th>
                    </tr>
                </thead>
                <tbody>
                    <% pireps.forEach(pirep=>{%>
                        <tr id="tr-id-<%=pirep.id%>" class="tr-class-<%=pirep.id%> pirepClickable" data-title="<%=pirep.id%>"
                            title="<%= pirep.id%>" data-object='{"key": "value"}' style="cursor: pointer;"
                            data-bs-toggle="modal" data-bs-target="#modal-<%=pirep.id%>">
                            <td id="td-id-<%=pirep.id %>" class="td-class-<%=pirep.id %>" data-title="<%= pirep.id %>">
                                <strong>
                                        <%= pirep.route%>
                                </strong>
                            </td>
                            <td data-text="<%= operator_search.get(parseInt(pirep.operator)).name %>">
                                <%= operator_search.get(parseInt(pirep.operator)).name %>
                            </td>
                            <td data-text="<%= pirep.vehiclePublic %>">
                                <%= pirep.vehiclePublic %>
                            </td>
                            <td data-text="<%= pirep.status == "a" ? "Accepted" : pirep.status == "d" ? "Denied" : "Awaiting" %>">
                                <% if (pirep.status=='a' ){%>
                                    <span class="badge bg-success">Accepted</span>
                                <%}else if(pirep.status=="d" ){%>
                                    <span class="badge bg-danger">Rejected</span>
                                <%}else{%>
                                    <span class="badge bg-secondary">Awaiting</span>
                                <%}%>
                            </td>
                        </tr>
                    <%})%>
                </tbody>
            </table>
            </div>
        </div>
        <% pireps.forEach(pirep =>{%>
                                        <!-- Modal -->
                                        <div class="modal fade modal-fullscreen-sm-down" id="modal-<%=pirep.id%>" tabindex="-1"
                                            aria-labelledby="exampleModalLabel" aria-hidden="true">
                                            <div class="modal-dialog">
                                                <div class="modal-content">
                                                    <div class="modal-header">
                                                        <h5 class="modal-title" id="exampleModalLabel">
                                                            <%= pirep.route%>
                                                        </h5>
                                                        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                                                    </div>
                                                    <div class="modal-body">
                                                        <h4>Flight <%= pirep.route%>
                                                        </h4>
                                                        <hr>
                                                        <p class="fs-6">
                                                            <strong><i class="bi bi-person"></i> User: </strong>
                                                            <%=config.code + pirep.author%><br>
                                                                <strong><i class="bi bi-calendar-date"></i> Flight Date: </strong>
                                                                <%= new Date(pirep.filed).toLocaleDateString() %><br>
                                                                    <strong><i class="fa fa-plane"></i> Vehicle: </strong>
                                                                    <%= pirep.vehiclePublic%><br>
                                                                        <strong><i class="bi bi-shop"></i> Airline: </strong>
                                                                        <%= pirep.airline%><br>
                                                                            <strong><i class="bi bi-clock"></i> Flight Time: </strong>
                                                                            <%= (pirep.flightTime / 60).toFixed(2); %> hours (<%= pirep.flightTime%> mins)<br>
                                                                                    <strong><i class="bi bi-droplet-half"></i> Fuel Used: </strong>
                                                                                    <%= pirep.fuel%>kg<br>
                                                                                        <strong><i class="bi bi-type"></i> Comments: </strong>
                                                                                        <%= pirep.comments%><br>
                                                        </p>
                                                        <% if(config.other.pirepPic==true){%>
                                                        
                                                            <strong><i class="bi bi-image"></i> Image: </strong><br><br>
                                                            <div class="w-100 text-center">
                                                                <% if(pirep.pirepImg=="REMOVED" ){%>
                                                                    <p class="fw-bold">Image removed in accordance with the image removal policy set in VACenter settings.</p>
                                                                    <%}else{%>
                                                                        <img src='<%= pirep.pirepImg%>.webp' style="width: 75%;" class="rounded mx-auto text-center">
                                                                        <%}%>
                                                        
                                                            </div>
                                                            <%}%>
                                                        <br>
                                                        <% if (pirep.status=='a' ){%>
                                                            <span class="badge bg-success">Accepted</span>
                                                            <%}else if(pirep.status=="d" ){%>
                                                                <span class="badge bg-danger">Rejected</span>
                                                                <br><br>
                                                                <h5>Reject Reason:</h5>
                                                                <p>
                                                                    <%= pirep.rejectReason%>
                                                                </p>
                                                                <%}else{%>
                                                                    <span class="badge bg-secondary">Awaiting</span>
                                                                    <%}%>
                                                                        <p class="text-muted mt-4" style="font-size: 9px;"><strong>ID: </strong>
                                                                            <%= pirep.id%>
                                                                        </p>
                                                    </div>
                                                    <div class="modal-footer">
                                                        <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
        <%})%>
        <%- include('components/footer.ejs') %>
        <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta3/dist/js/bootstrap.bundle.min.js"
            integrity="sha384-JEW9xMcG8R+pH31jmWH6WWP0WintQrMb4s7ZOdauHnUtxwoG2vI5DkLtS3qm9Ekf"
            crossorigin="anonymous"></script>
        <script src="https://code.jquery.com/jquery-3.6.0.min.js"
            integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>
        <script src="https://unpkg.com/bootstrap-table@1.18.3/dist/bootstrap-table.min.js"></script>

        
</body>

</html>