@model ServiceRecordInput
@{
    var isNew = Model.Id == 0;
}
<div class="modal-header">
    <h5 class="modal-title">@(isNew ? "Add New Service Record" : "Edit Service Record")</h5>
    <button type="button" class="btn-close" onclick="hideAddServiceRecordModal()" 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="serviceRecordDate">Date</label>
                    <div class="input-group">
                        <input type="text" id="serviceRecordDate" class="form-control" placeholder="Date service was performed" value="@Model.Date">
                        <span class="input-group-text"><i class="bi bi-calendar-event"></i></span>
                    </div>
                    <label for="serviceRecordMileage">Odometer</label>
                    <input type="number" id="serviceRecordMileage" class="form-control" placeholder="Odometer reading when serviced" value="@(isNew ? "" : Model.Mileage)">
                    <label for="serviceRecordDescription">Description</label>
                    <input type="text" id="serviceRecordDescription" class="form-control" placeholder="Description of item(s) serviced(i.e. Oil Change)" value="@Model.Description">
                    <label for="serviceRecordCost">Cost</label>
                    <input type="text" id="serviceRecordCost" class="form-control" placeholder="Cost of the service" value="@(isNew ? "" : Model.Cost)">
                    @if (isNew)
                    {
                        @await Html.PartialAsync("_SupplyStore", "ServiceRecord")
                    }
                </div>
                <div class="col-md-6 col-12">
                    <label for="serviceRecordNotes">Notes(optional)</label>
                    <textarea id="serviceRecordNotes" class="form-control" rows="5">@Model.Notes</textarea>
                    @if (Model.Files.Any())
                    {
                        <div>
                            @await Html.PartialAsync("_UploadedFiles", Model.Files)
                            <label for="serviceRecordFiles">Upload more documents</label>
                            <input onChange="uploadVehicleFilesAsync(this)" type="file" multiple accept=".png,.jpg,.jpeg,.pdf,.xls,.xlsx,.docx" class="form-control-file" id="serviceRecordFiles">
                        </div>
                    }
                    else
                    {
                        @if (isNew)
                        {
                            <div class="form-check">
                                <input class="form-check-input" type="checkbox" value="" id="addReminderCheck">
                                <label class="form-check-label" for="addReminderCheck">
                                    Add Reminder
                                </label>
                            </div>
                        }
                        <label for="serviceRecordFiles">Upload documents(optional)</label>
                        <input onChange="uploadVehicleFilesAsync(this)" type="file" multiple accept=".png,.jpg,.jpeg,.pdf,.xls,.xlsx,.docx" class="form-control-file" id="serviceRecordFiles">
                    }
                </div>
            </div>
        </div>
    </form>
</div>
<div class="modal-footer">
    @if (!isNew)
    {
        <button type="button" class="btn btn-danger" onclick="deleteServiceRecord(@Model.Id)" style="margin-right:auto;">Delete</button>
    }
    <button type="button" class="btn btn-secondary" onclick="hideAddServiceRecordModal()">Cancel</button>
    @if (isNew)
    {
        <button type="button" class="btn btn-primary" onclick="saveServiceRecordToVehicle()">Add New Service Record</button>
    }
    else if (!isNew)
    {
        <button type="button" class="btn btn-primary" onclick="saveServiceRecordToVehicle(true)">Edit Service Record</button>
    }
</div>
<script>
    var uploadedFiles = [];
    var selectedSupplies = [];
    getUploadedFilesFromModel();
    function getUploadedFilesFromModel() {
    @foreach (UploadedFiles filesUploaded in Model.Files)
    {
        @:uploadedFiles.push({ name: "@filesUploaded.Name", location: "@filesUploaded.Location" });
    }
    }
    function getServiceRecordModelData(){
        return {id: @Model.Id}
    }
</script>