@inherits Dynamicweb.Rendering.RazorTemplateBase<Dynamicweb.Rendering.RazorTemplateModel<Dynamicweb.Rendering.Template>>
@using Dynamicweb
@using Dynamicweb.Core
@using Dynamicweb.Ecommerce.Cart
@using Dynamicweb.Ecommerce.Orders

@{ 
	string cardId = Context.Current.Request.QueryString.Get("SavedCardID");
	PaymentCardToken card = Dynamicweb.Ecommerce.Services.PaymentCard.GetById(Converter.ToInt32(cardId));
}

<div class="h-100" data-dw-colorscheme="@Pageview.CurrentParagraph?.ColorSchemeId" id="SavedCardLog">
	<header class="d-flex flex-row align-items-center gap-3 px-2 py-3 border-bottom">
		<h1 class="h6 m-0 flex-fill">@Translate("Your saved card")</h1>
	</header>
	
	@if (card != null)
	{
		<table class="table d-print-table mb-0">
			<tr>
				<td class="">@Translate("Card name")</td>
				<td class="text-end">@card.Name</td>
			</tr>
			<tr>
				<td class="">@Translate("Card type")</td>
				<td class="text-end">
					@{
						string iconPath = "/Files/Images/Icons/";
						string svgIcon = ReadFile(iconPath + card.CardType.ToLower().Replace(" ", "") + ".svg");

						if (!string.IsNullOrEmpty(svgIcon))
						{
							<span class="ms-3 icon-6">@svgIcon</span>
						}
						else
						{
							<span>@card.CardType</span>
						}
					}
				</td>
			</tr>
			<tr>
				<td>@Translate("Card identifier")</td>
				<td class="text-end">@card.Identifier</td>
			</tr>
			<tr>
				<td>@Translate("Last used")</td>
				<td class="text-end">@card.UsedDate</td>
			</tr>
		</table>
		
		<div class="p-3">
			@{
            	string deleteUrl = $"{GetString("Ecom:CustomerCenter.SavedCards.BaseUrl")}&DelSavedCardID={cardId}";
            }
			<a class="btn btn-secondary" data-dw-button="secondary" href="@deleteUrl" role="button" id="SavedCardDeleteButton">@Translate("Delete")</a>
			<a href="@GetString("Ecom:CustomerCenter.SavedCards.BaseUrl")" class="btn btn-link" id="SavedCardBackButton">@Translate("Back")</a>
		</div>
	}
	else
	{
		<div class="alert alert-info text-center mt-3" role="alert">
			@Translate("There was an error loading the card. Please try again!")
		</div>
	}
</div>
