@model OdometerRecordInput
@{
    var isNew = Model.Id == 0;
}
<div class="modal-header">
    <h5 class="modal-title">@(isNew ? "Add New Odometer Record" : "Edit Odometer Record")</h5>
    <button type="button" class="btn-close" onclick="hideAddOdometerRecordModal()" aria-label="Close"></button>
</div>
<div class="modal-body">
    <form>
        <div class="form-group">
            <div class="row">
                <div class="col-md-6 col-12">
                    <input type="text" id="workAroundInput" style="height:0px; width:0px; display:none;">
                    <label for="odometerRecordDate">Date</label>
                    <div class="input-group">
                        <input type="text" id="odometerRecordDate" class="form-control" placeholder="Date recorded" value="@Model.Date">
                        <span class="input-group-text"><i class="bi bi-calendar-event"></i></span>
                    </div>
                    <label for="odometerRecordMileage">Odometer</label>
                    <input type="number" id="odometerRecordMileage" class="form-control" placeholder="Odometer reading" value="@(isNew ? "" : Model.Mileage)">
                </div>
                <div class="col-md-6 col-12">
                    <label for="odometerRecordNotes">Notes(optional)</label>
                    <textarea id="odometerRecordNotes" class="form-control" rows="5">@Model.Notes</textarea>
                    @if (Model.Files.Any())
                    {
                        <div>
                            @await Html.PartialAsync("_UploadedFiles", Model.Files)
                            <label for="odometerRecordFiles">Upload more documents</label>
                            <input onChange="uploadVehicleFilesAsync(this)" type="file" multiple accept=".png,.jpg,.jpeg,.pdf,.xls,.xlsx,.docx" class="form-control-file" id="odometerRecordFiles">
                        </div>
                    }
                    else
                    {
                        <label for="odometerRecordFiles">Upload documents(optional)</label>
                        <input onChange="uploadVehicleFilesAsync(this)" type="file" multiple accept=".png,.jpg,.jpeg,.pdf,.xls,.xlsx,.docx" class="form-control-file" id="odometerRecordFiles">
                    }
                </div>
            </div>
        </div>
    </form>
</div>
<div class="modal-footer">
    @if (!isNew)
    {
        <button type="button" class="btn btn-danger" onclick="deleteOdometerRecord(@Model.Id)" style="margin-right:auto;">Delete</button>
    }
    <button type="button" class="btn btn-secondary" onclick="hideAddOdometerRecordModal()">Cancel</button>
    @if (isNew)
    {
        <button type="button" class="btn btn-primary" onclick="saveOdometerRecordToVehicle()">Add New Odometer Record</button>
    }
    else if (!isNew)
    {
        <button type="button" class="btn btn-primary" onclick="saveOdometerRecordToVehicle(true)">Edit Odometer Record</button>
    }
</div>
<script>
    var uploadedFiles = [];
    getUploadedFilesFromModel();
    function getUploadedFilesFromModel() {
    @foreach (UploadedFiles filesUploaded in Model.Files)
    {
        @:uploadedFiles.push({ name: "@filesUploaded.Name", location: "@filesUploaded.Location" });
    }
        }
    function getOdometerRecordModelData() {
        return { id: @Model.Id}
    }
</script>