namespace MidrandBookshop.Components.Pages; public partial class Account : ComponentBase { [Inject] private AuthenticationStateProvider AuthStateProvider { get; set; } = default!; private ClaimsPrincipal? User { get; set; } private bool showAddForm = false; private AddressItem? editingAddress = null; private string newAddressName = ""; private string newStreetAddress = ""; private string newCity = ""; private string newPostalCode = ""; private bool isBilling, isShipping; private List orderHistory = new() { // 1. Delivered + Paid (Green Mapping Rules) new OrderItem { OrderId = "#MB-2026-8712", ProductId = "mastering-css-isolation", ProductTitle = "Mastering CSS Isolation in Modern .NET Web Applications Architecture", OrderDate = new DateTime(2026, 4, 14), ShippingAddressName = "Midrand Warehouse", Status = "Delivered", PaymentStatus = "Paid", Total = 890.00 }, // 2. Shipped + Paid (Amber Logistics + Green Payment Rules) new OrderItem { OrderId = "#MB-2026-9481", ProductId = "introduction-to-blazor", ProductTitle = "Introduction to Blazor WebAssembly Framework Development", OrderDate = new DateTime(2026, 5, 20), ShippingAddressName = "Home Address", Status = "Shipped", PaymentStatus = "Paid", Total = 720.00 }, // 3. Unshipped + Abandoned/Unpaid (Muted Grey / Soft Red Rules — Hides Invoice Button) new OrderItem { OrderId = "#MB-2026-1034", ProductId = "csharp-functional-paradigms", ProductTitle = "Advanced Functional Architecture & Monadic Paradigms in Modern C#", OrderDate = new DateTime(2026, 6, 11), ShippingAddressName = "Home Address", Status = "Unshipped", PaymentStatus = "Unpaid", Total = 650.00 } }; private List savedAddresses = new() { new AddressItem { Id = 1, Name = "Home Address", Street = "12 Main Road", City = "Midrand", PostalCode = "1685", IsBilling = true, IsShipping = true, IsPrimary = true }, new AddressItem { Id = 2, Name = "Midrand Warehouse", Street = "Corner of Church & Third Roads", City = "Midrand", PostalCode = "1685", IsBilling = false, IsShipping = false, IsPrimary = false } }; protected override async Task OnInitializedAsync() { var authState = await AuthStateProvider.GetAuthenticationStateAsync(); User = authState?.User; } private void DownloadInvoice(string orderId) { Navigation.NavigateTo($"/api/invoices/download/{orderId.Replace("#", "")}", forceLoad: true); } private string GetStatusClass(string status) => status?.ToLower() switch { "delivered" => "status-delivered", // Green "shipped" => "status-shipped", // Amber _ => "status-processing" // Muted Architectural Dark Grey }; private string GetPaymentStatusClass(string paymentStatus) => paymentStatus?.ToLower() switch { "paid" => "pay-paid", // Green "refunded" => "pay-refunded", // Grey _ => "pay-pending" // Red Alert Tone }; private void EditAddress(AddressItem addr) { editingAddress = addr; showAddForm = false; newAddressName = addr.Name; newStreetAddress = addr.Street; newCity = addr.City; newPostalCode = addr.PostalCode; isBilling = addr.IsBilling; isShipping = addr.IsShipping; } private void CancelAddressActions() { showAddForm = false; editingAddress = null; ClearFormFields(); } private void ClearFormFields() { newAddressName = ""; newStreetAddress = ""; newCity = ""; newPostalCode = ""; isBilling = false; isShipping = false; } private void SaveAddress() { if (string.IsNullOrWhiteSpace(newAddressName) || string.IsNullOrWhiteSpace(newStreetAddress)) return; if (editingAddress == null) { var nextId = savedAddresses.Any() ? savedAddresses.Max(a => a.Id) + 1 : 1; var newAddr = new AddressItem { Id = nextId, Name = newAddressName, Street = newStreetAddress, City = newCity, PostalCode = newPostalCode, IsBilling = isBilling, IsShipping = isShipping, IsPrimary = !savedAddresses.Any() }; savedAddresses.Add(newAddr); } else { var target = savedAddresses.FirstOrDefault(a => a.Id == editingAddress.Id); if (target != null) { target.Name = newAddressName; target.Street = newStreetAddress; target.City = newCity; target.PostalCode = newPostalCode; target.IsBilling = isBilling; target.IsShipping = isShipping; } editingAddress = null; } showAddForm = false; ClearFormFields(); } private void DeleteAddress(AddressItem addr) { if (editingAddress?.Id == addr.Id) editingAddress = null; savedAddresses.Remove(addr); if (addr.IsPrimary && savedAddresses.Any()) savedAddresses.First().IsPrimary = true; } private void SetPrimary(AddressItem target, ChangeEventArgs e) { var isChecked = (bool)(e.Value ?? false); if (isChecked) { foreach (var addr in savedAddresses) addr.IsPrimary = (addr.Id == target.Id); } else target.IsPrimary = false; } private void TriggerLogout() { Navigation.NavigateTo("/logout", forceLoad: true); } public class AddressItem { public int Id { get; set; } public string Name { get; set; } = ""; public string Street { get; set; } = ""; public string City { get; set; } = ""; public string PostalCode { get; set; } = ""; public bool IsBilling { get; set; } public bool IsShipping { get; set; } public bool IsPrimary { get; set; } } public class OrderItem { public string OrderId { get; set; } = ""; public string ProductId { get; set; } = ""; public string ProductTitle { get; set; } = ""; public DateTime OrderDate { get; set; } public string ShippingAddressName { get; set; } = ""; public string Status { get; set; } = ""; public string PaymentStatus { get; set; } = "Pending"; public double Total { get; set; } } }