@page "/Borrowings" @using BlazorFrontend.Services @using LibraryManagement.Shared.Models @inject LibraryApiClient ApiClient @inject IJSRuntime JS My Loans

My Loans

Track your current borrowings and return upcoming books.

@if (_isLoading) {
} else {
@if (!_borrowings.Any()) { } @foreach (var loan in PaginatedBorrowings) { }
Book Information Dates Status Fines Actions
You don't have any borrowing history yet.

@loan.BookTitle

Loan ID: #@loan.Id

Borrowed: @loan.BorrowDate.ToString("MMM dd, yyyy")

Due: @loan.DueDate.ToString("MMM dd, yyyy")

@if (loan.ReturnDate.HasValue) {

Returned: @loan.ReturnDate.Value.ToString("MMM dd, yyyy")

}
@(loan.Status == "PendingReturn" ? "Pending Approval" : loan.Status) @if (loan.FineAmount > 0) {
MMK @loan.FineAmount.ToString("N0") @if (loan.IsFinePaid) { Paid }
} else { No Fines }
@if (loan.Status == "Borrowed") { } else if (loan.Status == "PendingReturn") { Awaiting Approval } else { }
@if (TotalPages > 1) {

Showing @((_currentPage - 1) * _pageSize + 1) to @(Math.Min(_currentPage * _pageSize, _borrowings.Count())) of @_borrowings.Count() records

Page @_currentPage of @TotalPages
}
} @code { private bool _isLoading = true; private IEnumerable _borrowings = Enumerable.Empty(); // Pagination private int _currentPage = 1; private int _pageSize = 10; private IEnumerable PaginatedBorrowings => _borrowings .Skip((_currentPage - 1) * _pageSize) .Take(_pageSize); private int TotalPages => (int)Math.Ceiling(_borrowings.Count() / (double)_pageSize); protected override async Task OnInitializedAsync() { await LoadDataAsync(); } private async Task LoadDataAsync() { _isLoading = true; try { _borrowings = await ApiClient.GetMyBorrowingsAsync(); _currentPage = 1; } catch (Exception ex) { Console.WriteLine($"Error loading borrowings: {ex.Message}"); } finally { _isLoading = false; } } private async Task RequestReturnAsync(BorrowingDto loan) { bool confirmed = await JS.InvokeAsync("confirm", $"Request return for \"{loan.BookTitle}\"? It will be marked as pending until approved by a librarian."); if (!confirmed) return; var success = await ApiClient.RequestReturnAsync(loan.Id); if (success) { await JS.InvokeVoidAsync("showToast", "Return request submitted successfully!", "success"); await LoadDataAsync(); } else { await JS.InvokeVoidAsync("showToast", "Failed to submit return request.", "error"); } } }