@using Newtonsoft.Json;
@model EFB.Models.ViewChartModel;
@{
    ViewData["Title"] = "Welcome";
}

<div class="row d-flex justify-content-center">
    <div class="card-body col-md-4">
        <div class="container jumbotron">

            <form asp-controller="Charts" asp-action="Index">
                <div class="form-group">
                    <input type="text" class="form-control" placeholder="ICAO Code" name="ICAO" value="@TempData["ICAO"]">
                </div>
                <button type="submit" class="btn btn-secondary">Search</button>

                @{
                    if (TempData["Error"] != null)
                    {//If an error has been flagged, information will be displayed to the user

                        <br />
                        <br />

                        <div class="alert alert-danger">
                            <strong>Warning!</strong> @TempData["Error"] <button type='button' class='close' data-dismiss='alert' aria-hidden='true' />&times;
                        </div>
                    }
                }
            </form>

            @{

            <br />
            <h4>Charts for: @Model.Charts.ICAO</h4>

                <form asp-action="ViewCharts" method="post">
                    <div class="form-group">
                        <label>Select Charts</label><br />
                        <select name="chart" class="form-control">

                            @if (Model.Charts != null) {
                                <option value=""></option>
                                foreach(var item in Model.Charts.GroundLayout) {
                                    var itemString = JsonConvert.SerializeObject(item);

                                    <option value="@itemString">@item.Name</option>
                                }

                                <option value=""></option>
                                foreach(var item in Model.Charts.SID) {
                                    var itemString = JsonConvert.SerializeObject(item);

                                    <option value="@itemString">@item.Name</option>
                                }

                                <option value=""></option>
                                foreach(var item in Model.Charts.STAR) {
                                    var itemString = JsonConvert.SerializeObject(item);

                                    <option value="@itemString">@item.Name</option>
                                }

                                <option value=""></option>
                                foreach(var item in Model.Charts.Approach) {
                                    var itemString = JsonConvert.SerializeObject(item);

                                    <option value="@itemString">@item.Name</option>
                                }

                                <option value=""></option>
                                foreach(var item in Model.Charts.TextualData) {
                                    var itemString = JsonConvert.SerializeObject(item);

                                    <option value="@itemString">@item.Name</option>
                                }

                            }
                        </select>
                        <button type="submit" class="btn btn-primary">View</button>
                    </div>
                </form>
            }
        </div>
    </div>

    <div class="card-body col-md-8 vh-80">
        <div class="container jumbotron vh-100">
            @{
                if (Model.Selected != null)
                {
                    <h3>@Model.Selected.Name</h3>

                    <br />
                    <br />
                    
                    <iframe src="@Model.Selected.URL" width="100%" height="90%"></iframe>

                }
            }
        </div>
    </div>
</div>