2022-11-25 02:42:55 +01:00
@model (Dictionary<string, object> Items, int Level)
@functions {
private bool IsValidURL(string source)
{
2023-05-08 11:02:13 +02:00
return Uri.TryCreate(source, UriKind.Absolute, out var uriResult) &&
(uriResult.Scheme == Uri.UriSchemeHttp || uriResult.Scheme == Uri.UriSchemeHttps);
2022-11-25 02:42:55 +01:00
}
}
2023-05-08 11:02:13 +02:00
2023-08-10 14:57:54 +03:00
@if (Model.Items.Any())
2023-04-11 13:21:02 +09:00
{
2023-05-08 11:02:13 +02:00
<table class="table my-0" v-pre>
2023-08-10 14:57:54 +03:00
@if (Model.Items.ContainsKey("Cart"))
2023-05-08 11:02:13 +02:00
{
2023-08-10 14:57:54 +03:00
<tbody>
@foreach (var (key, value) in (Dictionary <string, object>)Model.Items["Cart"])
2022-11-25 02:42:55 +01:00
{
2023-08-10 14:57:54 +03:00
<tr>
2023-08-26 13:48:48 +02:00
<th>@key</th>
2023-08-10 14:57:54 +03:00
<td class="text-end">@value</td>
</tr>
2023-05-08 11:02:13 +02:00
}
2023-08-10 14:57:54 +03:00
</tbody>
<tfoot style="border-top-width:3px">
@if (Model.Items.ContainsKey("Subtotal"))
2023-05-08 11:02:13 +02:00
{
2023-08-10 14:57:54 +03:00
<tr>
2023-08-26 13:48:48 +02:00
<th>Subtotal</th>
2023-08-10 14:57:54 +03:00
<td class="text-end">@Model.Items["Subtotal"]</td>
</tr>
2023-05-08 11:02:13 +02:00
}
2023-08-10 14:57:54 +03:00
@if (Model.Items.ContainsKey("Discount"))
2023-05-08 11:02:13 +02:00
{
2023-08-10 14:57:54 +03:00
<tr>
2023-08-26 13:48:48 +02:00
<th>Discount</th>
2023-08-10 14:57:54 +03:00
<td class="text-end">@Model.Items["Discount"]</td>
</tr>
}
@if (Model.Items.ContainsKey("Tip"))
{
<tr>
2023-08-26 13:48:48 +02:00
<th>Tip</th>
2023-08-10 14:57:54 +03:00
<td class="text-end">@Model.Items["Tip"]</td>
</tr>
}
@if (Model.Items.ContainsKey("Total"))
{
<tr style="border-top-width:3px">
2023-08-26 13:48:48 +02:00
<th>Total</th>
2023-08-10 14:57:54 +03:00
<td class="text-end">@Model.Items["Total"]</td>
</tr>
}
</tfoot>
}
else
{
foreach (var (key, value) in Model.Items)
{
<tr>
@if (value is string str)
{
if (!string.IsNullOrEmpty(key))
2023-05-08 11:02:13 +02:00
{
2023-08-26 13:48:48 +02:00
<th>@key</th>
2023-08-10 14:57:54 +03:00
}
<td style="white-space:pre-wrap">@* Explicitely remove whitespace at front here *@@if (IsValidURL(str)){<a href="@str" target="_blank" rel="noreferrer noopener">@str</a>}else {@str.Trim()}</td>
}
else if (value is Dictionary<string, object> { Count: > 0 } subItems)
{
<td colspan="2">
@{
@if (!string.IsNullOrEmpty(key))
{
2023-08-26 13:48:48 +02:00
Write(Html.Raw($"<h{Model.Level + 3} class=\"mb-3 fw-semibold\">"));
2023-08-10 14:57:54 +03:00
Write(key);
Write(Html.Raw($"</h{Model.Level + 3}>"));
}
}
<partial name="PosData" model="@((subItems, Model.Level + 1))" />
</td>
}
else if (value is IEnumerable<object> valueArray)
{
<td colspan="2">
@{
@if (!string.IsNullOrEmpty(key))
{
2023-08-26 13:48:48 +02:00
Write(Html.Raw($"<h{Model.Level + 3} class=\"mb-3 fw-semibold\">"));
2023-08-10 14:57:54 +03:00
Write(key);
Write(Html.Raw($"</h{Model.Level + 3}>"));
}
2023-05-08 11:02:13 +02:00
}
2023-08-10 14:57:54 +03:00
@foreach (var item in valueArray)
2023-05-08 11:02:13 +02:00
{
2023-08-10 14:57:54 +03:00
@if (item is Dictionary<string, object> { Count: > 0 } subItems2)
{
<partial name="PosData" model="@((subItems2, Model.Level + 1))" />
}
else
{
<partial name="PosData" model="@((new Dictionary<string, object> { { "", item } }, Model.Level + 1))" />
}
2023-05-08 11:02:13 +02:00
}
2023-08-10 14:57:54 +03:00
</td>
}
</tr>
}
2023-05-08 11:02:13 +02:00
}
</table>
2023-04-11 13:21:02 +09:00
}