@model IEnumerable<PantheonRA.WebApi.Contracts.TravelOrders.DistanceViewModel>

@{
    var currency = Loc.DomesticCurrency;
    bool fromCreate = ViewBag.FromCreate != null ? (bool)ViewBag.FromCreate : false;
    var decimalFormat = "{0:N2}";
}

<div class="row">
    <div class="col-md-12">
        <div class="panel-group" id="distance-accordion" role="tablist" aria-multiselectable="true">
            @for (int i = 0; i < Model.Count(); i++)
            {
                var expensesTotal = Model.ElementAt(i).DailyAllows.Sum(y => y.Value / y.anFxRate);
                expensesTotal += Model.ElementAt(i).Expenses.Sum(y => y.Value);
                expensesTotal = Math.Round(expensesTotal.HasValue ? expensesTotal.Value : 0, 2);
                ViewBag.ExpensesTotal = expensesTotal;

                ViewBag.Enumerator = i;
                ViewBag.DistanceAnNo = Model.ElementAt(i).Distance.OrdinalNumber;
                ViewBag.IsDomestic = Model.ElementAt(i).Distance.Country == (string)ViewBag.CountryName ? true : false;
                bool isNewDistance = Model.ElementAt(i).Distance.OrdinalNumber == (int)ViewBag.MaxOrdinal;

                <div id="distance-accordion-@i" class="panel travelorder-panel panel-default">
                    @Html.Partial("_DistancesHeader", Model.ElementAt(i).Distance)

                    <div id="collapse-@i" class="panel-collapse collapse @((Model.Count() < 2 || isNewDistance) ? "in" : string.Empty)" role="tabpanel" aria-labelledby="heading-@i">
                        <div class="panel-body travelorder-panel-body" style="padding:0;border:none">
                            @Html.Partial("_Distances", Model.ElementAt(i).Distance)
                        </div>

                        <!--daily allows and expenses-->
                        <div id="partial-accordion-@i">
                            <div class="panel travelorder-panel">
                                <div class="panel-heading" id="partial-heading-@i">
                                    <h4 class="panel-title">
                                        <a role="button" id="expand-dailyAllow-@i" class="collapsed text-success" data-toggle="collapse"
                                           data-parent="#partial-accordion-@i"
                                           href="#partial-collapse-@i">
                                            @Loc.DailyAllowsAndExpenses (@string.Format(decimalFormat, expensesTotal) @currency)
                                        </a>
                                    </h4>
                                </div>
                                <div id="partial-collapse-@i" class="panel-collapse collapse">
                                    <div class="row">
                                        <div class="col-md-12">
                                            <div class="panel-body travelorder-panel-body" style="border:none;padding-bottom: 0px !important;">
                                                <!--Daily allows-->
                                                @Html.Partial("_DailyAllows", Model.ElementAt(i).DailyAllows)

                                                <!--Daily Expenses-->
                                                @Html.Partial("_Expenses", Model.ElementAt(i).Expenses)
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            }
        </div>
    </div>
</div>