@page
@model SharedTripModel
@{
    ViewData["Title"] = "Shared Trip";

    if (Model.RedirToIndex) {
        Response.Redirect("/");
        return;
    }

    if (!Model.Legs.Any()) {
        Response.Redirect("/");
        return;
    }

    var dep = Model.Legs.First().DepStation;
    var arr = Model.Legs.Last().ArrStation;
}

<div>
    <p>
        @Model.User's Trip from <b>@dep</b> to <b>@arr</b>, starting @DateTime.Parse(Model.Legs.First().DepTime).ToString("yyyy-MM-dd HH:mm")
    </p>
</div>
<div>
    <table class="table table-striped">
        <thead>
        <tr>
            <th scope="col">Date</th>
            <th scope="col">Departure</th>
            <th scope="col">Arrival</th>
            <th scope="col">Train</th>
            <th scope="col">Comment</th>
            <th scope="col">Actions</th>
        </tr>
        </thead>
        <tbody>
        @foreach (var leg in Model.Legs) {
            if (leg.TrainType == "placeholder") {
                <td></td>
                <td></td>
                <td></td>
                <td></td>
                <td></td>
                <td></td>
                continue;
            }
            var deptime = DateTime.Parse(leg.DepTime);
            var arrtime = DateTime.Parse(leg.ArrTime);
            var date = DateTime.Parse(leg.DepTime).ToString("ddd, dd.MM.");
            var dept = deptime.ToString("HH:mm");
            var arrt = arrtime.ToString("HH:mm");
            <tr>
                <td>
                    @date
                </td>
                <td>
                    <b>@dept</b> @Html.Raw(leg.DepStation.PadRight(30, ' ').Substring(0, 30).TrimEnd())
                </td>
                <td>
                    <b>@arrt</b> @Html.Raw(leg.ArrStation.PadRight(30, ' ').Substring(0, 30).TrimEnd())
                </td>
                <td>@leg.TrainType @leg.TrainNr</td>
                <td>
                    @if (!string.IsNullOrWhiteSpace(leg.Comment)) {
                        @Html.Raw(leg.Comment)
                    }
                </td>
                <td>
                    <a class="btn btn-sm btn-primary" href="https://marudor.de/details/@leg.TrainType @leg.TrainNr/@(deptime.ToUniversalTime().Subtract(new DateTime(1970, 1, 1)).TotalSeconds)000/?station=@leg.DepStationId" target="_blank">Marudor</a>
                    <a class="btn btn-sm btn-warning" href="https://travelynx.de/s/@leg.DepStationId?train=@leg.TrainType @leg.TrainNr" target="_blank">Travelynx</a>
                </td>
            </tr>
        }
        </tbody>
    </table>
</div>