@using CarCareTracker.Helper
@inject IConfigHelper config
@inject ITranslationHelper translator
@{
    var userConfig = config.GetUserConfig(User);
    var hideZero = userConfig.HideZero;
    var userLanguage = userConfig.UserLanguage;
}
@model VehicleHistoryViewModel
<div class="vehicleDetailTabContainer">
    <div class="row mt-2">
        <div class="d-flex">
            <img src="/defaults/lubelogger_logo.png" />
            <span class="display-6 ms-5">@translator.Translate(userLanguage, "Vehicle Maintenance Report")</span>
        </div>
    </div>
    <hr />
    <div class="row">
        <div class="col-6">
            <ul class="list-group">
                <li class="list-group-item">
                    <span class="display-6">@($"{Model.VehicleData.Year} {Model.VehicleData.Make} {Model.VehicleData.Model}")</span>
                </li>
                <li class="list-group-item">
                    <span class="lead">@Model.VehicleData.LicensePlate</span>
                </li>
                <li class="list-group-item">
                    <div class="row">
                        <div class="col-4">
                            @if (Model.VehicleData.IsElectric)
                            {
                                <span><i class="bi bi-ev-station me-2"></i>@translator.Translate(userLanguage, "Electric")</span>
                            }
                            else if (Model.VehicleData.IsDiesel)
                            {
                                <span><i class="bi bi-fuel-pump-diesel me-2"></i>@translator.Translate(userLanguage, "Diesel")</span>
                            }
                            else
                            {
                                <span><i class="bi bi-fuel-pump me-2"></i>@translator.Translate(userLanguage, "Gasoline")</span>
                            }
                        </div>
                        @if (!string.IsNullOrWhiteSpace(Model.DaysOwned))
                        {
                            <div class="col-4">
                                <span><i class="bi bi-calendar-range me-2"></i>@($"{Model.DaysOwned} {translator.Translate(userLanguage, "Days")}")</span>
                            </div>
                        }
                        @if (Model.DistanceTraveled != default)
                        {
                            <div class="col-4">
                                <span><i class="bi bi-speedometer me-2"></i>@($"{Model.DistanceTraveled} {Model.DistanceUnit}")</span>
                            </div>
                        }
                    </div>
                </li>
            </ul>
        </div>
        <div class="col-6">
            <ul class="list-group">
                <li class="list-group-item">@($"{translator.Translate(userLanguage, "Last Reported Odometer Reading")}: {Model.Odometer}") </li>
                <li class="list-group-item">@($"{translator.Translate(userLanguage, "Average Fuel Economy")}: {Model.MPG}") </li>
                <li class="list-group-item">@($"{translator.Translate(userLanguage, "Total Spent(excl. fuel)")}: {Model.TotalCost.ToString("C")} ({Model.TotalCostPerMile.ToString("C")}/{Model.DistanceUnit})") </li>
                <li class="list-group-item">@($"{translator.Translate(userLanguage, "Total Spent on Fuel")}: {Model.TotalGasCost.ToString("C")} ({Model.TotalGasCostPerMile.ToString("C")}/{Model.DistanceUnit})") </li>
            </ul>
        </div>
    </div>
    <hr />
    @if (Model.TotalDepreciation != default)
    {
            <div class="row">
                <div class="col-3">
                    @(Model.TotalDepreciation > 0 ? translator.Translate(userLanguage, "Depreciation") : translator.Translate(userLanguage, "Appreciation"))
                </div>
                <div class="col-3">
                    <span><i class="bi @(Model.TotalDepreciation > 0 ? "bi-graph-down-arrow" : "bi-graph-up-arrow") me-2"></i>@Math.Abs(Model.TotalDepreciation).ToString("C")</span>
                </div>
                @if (Model.DepreciationPerDay != default)
                {
                    <div class="col-3">
                        <span><i class="bi bi-calendar-event me-2"></i>@($"{Model.DepreciationPerDay.ToString("C")}/{translator.Translate(userLanguage, "day")}")</span>
                    </div>
                }
                @if (Model.DepreciationPerMile != default)
                {
                    <div class="col-3">
                        <span><i class="bi bi-speedometer me-2"></i>@($"{Model.DepreciationPerMile.ToString("C")}/{Model.DistanceUnit}")</span>
                    </div>
                }
            </div>
        <hr />
    }
    <div class="row">
        <div class="col-12">
            <table class="table table-hover">
                <thead>
                    <tr class="d-flex">
                        <th scope="col" class="col-2 servicehistorytype">@translator.Translate(userLanguage, "Type")</th>
                        <th scope="col" class="col-1 servicehistorydate">@translator.Translate(userLanguage, "Date")</th>
                        <th scope="col" class="col-1">@translator.Translate(userLanguage, "Odometer")</th>
                        <th scope="col" class="col-3">@translator.Translate(userLanguage, "Description")</th>
                        <th scope="col" class="col-1">@translator.Translate(userLanguage, "Cost")</th>
                        <th scope="col" class="col-4">@translator.Translate(userLanguage, "Notes")</th>
                    </tr>
                </thead>
                <tbody>
                    @foreach (GenericReportModel reportData in Model.VehicleHistory)
                    {
                        <tr class="d-flex">
                            <td class="col-2 servicehistorytype">
                                @if (reportData.DataType == ImportMode.ServiceRecord)
                                {
                                    <span><i class="bi bi-card-checklist me-2"></i>@translator.Translate(userLanguage, "Service")</span>
                                }
                                else if (reportData.DataType == ImportMode.RepairRecord)
                                {
                                    <span><i class="bi bi-exclamation-octagon me-2"></i>@translator.Translate(userLanguage, "Repair")</span>
                                }
                                else if (reportData.DataType == ImportMode.UpgradeRecord)
                                {
                                    <span><i class="bi bi-wrench-adjustable me-2"></i>@translator.Translate(userLanguage, "Upgrade")</span>
                                }
                                else if (reportData.DataType == ImportMode.TaxRecord)
                                {
                                    <span><i class="bi bi-currency-dollar me-2"></i>@translator.Translate(userLanguage, "Tax")</span>
                                }
                            </td>
                            <td class="col-1 servicehistorydate">@reportData.Date.ToShortDateString()</td>
                            <td class="col-1">@(reportData.Odometer == default ? "---" : reportData.Odometer.ToString("N0"))</td>
                            <td class="col-3">@reportData.Description</td>
                            <td class="col-1">@((hideZero && reportData.Cost == default) ? "---" : reportData.Cost.ToString("C"))</td>
                            <td class="col-4 text-wrap">@CarCareTracker.Helper.StaticHelper.TruncateStrings(reportData.Notes, 100)</td>
                        </tr>
                    }
                </tbody>
            </table>
        </div>
    </div>
</div>
