<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>
        Home || <%= 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">
    <%- 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">
            <h1>Welcome <%= user.display%> to <%= config.name %></h1>
            <br>
            <% if(currentSession){%>
                <h2><i class="bi bi-exclamation-circle text-warning"></i> Current Session</h2>
                <hr>
                <p>You are currently flying, click the button below to return to your flight.</p>
                <div class="form-control w-100 mx-2 my-2 px-5 py-3">
                    <h1></h1>
                    <h3 class="fw-bold">Flying <%= operator_search.get((route_search.get(currentSession.route)).operator).code + (route_search.get(currentSession.route)).num %></h3>
                    <p>
                        Click the button to return to the flight.
                            </p>
                    <a href="/slotUI?ses=<%=currentSession.id%>" class="btn btn-<%= config.other.navColor[2] %>">Go to flight</a>
                        </div>
                <%}%>
            <br>
            <h2>Quick Stats</h2>
            <hr>
            <div class="w-100 row row-cols-1 mx-auto row-cols-md-2 row-cols-lg-4 g-3">
                <div class="col">
                    <div class="bg-dark text-light rounded text-center p-3">
                        <h4><%= user.rank%></h4>
                        
                        <h4>Rank</h4>
                    </div>
                </div>
                <div class="col">
                    <div class="bg-dark text-light rounded text-center p-3">
                        <h1>
                            <%= user.hours.toFixed(2)%>
                        </h1>
                        <h4>Flight Hours</h4>
                    </div>
                </div>
                <div class="col">
                    <div class="bg-dark text-light rounded text-center p-3">
                        <h1>
                            <%= user.pireps.length %>
                        </h1>
                        <h4>PIREPS Filed</h4>
                    </div>
                </div>
                <div class="col">
                    <div class="bg-dark text-light rounded text-center p-3">
                        <h5>
                            <%= mode(vics) %>
                        </h5>
                        <br>
                        <h4>Most common aircraft</h4>
                    </div>
                </div>
            </div>
            <br>
            <h2>Recommended Flights</h2>
            <hr>
            <h5>This feature is not available yet.</h5>
            <br>
            <h2>Your Flights</h2>
            <hr>
            <div class="row row-cols-1 row-cols-md-2 row-cols-lg-3 g-3 mt-2 ms-0 w-100">
                <% const keeper = [...user.pireps]%>
                <% user.pireps.splice(0,9).forEach(pirep=>{%>
                    <div class="col">
                        <div class="rounded bg-light p-3 shadow">
                            <h4><i class="bi bi-file-bar-graph-fill"></i>
                                <%= pirep.depICAO%> <i class="bi bi-chevron-right"></i> <%= pirep.arrICAO %>
                            </h4>
                            <p class="mb-5">
                                <%= pirep.route%><br>
                                <%= ((pirep.flightTime)/60).toFixed(2)%> hours<br>
                                <%= pirep.vehiclePublic %>
                            </p>
                            <p>
                                <% if(pirep.status == "a"){%>
                                    <span class="text-success"><i class="bi bi-check-circle"></i> Approved</span>    
                                <%}else if(pirep.status == "d"){%>
                                    <span class="text-danger"><i class="bi bi-x-circle"></i> Denied</span><br>
                                    <p><span class="fw-bold">Reject Reason:</span> <%= pirep.rejectReason %></p>
                                <%}else if(pirep.status == "n"){%>
                                    <span class="text-dark"><i class="bi bi-clock"></i> Awaiting Action</span>    
                                <%}else{%>
                                    <span class="text-primary">Error! Please report this PIREP <%= pirep.id%></span>    
                                <%}%>
                            </p>
                            <p class="text-muted">
                                <%= new Date(pirep.filed).toLocaleString('en-AU', { hour12: true })%>
                            </p>
                            
                        </div>
                    </div>
                    <%})%>
                        <% if(keeper.length==0){%>
                            <h5>No PIREPS Found</h5>
                        <%}%>
            </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://cdnjs.cloudflare.com/ajax/libs/suncalc/1.8.0/suncalc.min.js"
        integrity="sha512-s40QuZdS5wcjdt2OHUWSGRCECWr+YqbvRSaiBpEKOlOsbePPvXreeOTB4SVteinFcc1RpW/uDueEsknm9iJl2g=="
        crossorigin="anonymous" referrerpolicy="no-referrer"></script>
</body>
</html>