@using CarCareTracker.Helper
@inject IConfigHelper config
@{
    var enableCsvImports = config.GetUserConfig(User).EnableCsvImports;
    var hideZero = config.GetUserConfig(User).HideZero;
}
@model List<TaxRecord>
<div class="row">
    <div class="d-flex justify-content-between">
        <div class="d-flex align-items-center flex-wrap">
            <span class="ms-2 badge bg-success">@($"# of Tax Records: {Model.Count()}")</span>
            <span class="ms-2 badge bg-primary">@($"Total: {Model.Sum(x => x.Cost).ToString("C")}")</span>
        </div>
        <div>
            @if (enableCsvImports)
            {
                <div class="btn-group">
                    <button onclick="showAddTaxRecordModal()" class="btn btn-primary btn-md mt-1 mb-1"><i class="bi bi-pencil-square me-2"></i>Add Tax Record</button>
                    <button type="button" class="btn btn-md btn-primary btn-md mt-1 mb-1 dropdown-toggle dropdown-toggle-split" data-bs-toggle="dropdown" aria-expanded="false">
                        <span class="visually-hidden">Toggle Dropdown</span>
                    </button>
                    <ul class="dropdown-menu">
                        <li><a class="dropdown-item" href="#" onclick="showBulkImportModal('TaxRecord')">Import via CSV</a></li>
                        <li><a class="dropdown-item" href="#" onclick="exportVehicleData('TaxRecord')">Export to CSV</a></li>
                    </ul>
                </div>
            }
            else
            {
                <button onclick="showAddTaxRecordModal()" class="btn btn-primary btn-md mt-1 mb-1"><i class="bi bi-pencil-square me-2"></i>Add Tax Record</button>
            }
        </div>
    </div>
</div>
<div class="row vehicleDetailTabContainer">
    <div class="col-12">
        <div class="row mt-2 showOnPrint">
            <div class="d-flex">
                <img src="/defaults/lubelogger_logo.png" />
            </div>
        </div>
        <table class="table table-hover">
            <thead class="sticky-top">
                <tr class="d-flex">
                    <th scope="col" class="col-3 col-xl-1">Date</th>
                    <th scope="col" class="col-4 col-xl-6">Description</th>
                    <th scope="col" class="col-2">Cost</th>
                    <th scope="col" class="col-3">Notes</th>
                </tr>
            </thead>
            <tbody>
                @foreach (TaxRecord taxRecord in Model)
                {
                    <tr class="d-flex" style="cursor:pointer;" onclick="showEditTaxRecordModal(@taxRecord.Id)">
                        <td class="col-3 col-xl-1">@taxRecord.Date.ToShortDateString()</td>
                        <td class="col-4 col-xl-6">@taxRecord.Description</td>
                        <td class="col-2">@((hideZero && taxRecord.Cost == default) ? "---" : taxRecord.Cost.ToString("C"))</td>
                        <td class="col-3 text-truncate">@CarCareTracker.Helper.StaticHelper.TruncateStrings(taxRecord.Notes)</td>
                    </tr>
                }
            </tbody>
        </table>
    </div>
</div>


<div class="modal fade" data-bs-focus="false" id="taxRecordModal" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog modal-lg" role="document">
        <div class="modal-content" id="taxRecordModalContent">
        </div>
    </div>
</div>