@using System
@using System.Threading.Tasks

@inherits RazorBlade.HtmlTemplate

@functions {
    public required ExportContext Context { get; init; }

    public required string ThemeName { get; init; }
}

@{
    string Themed(string darkVariant, string lightVariant) =>
        string.Equals(ThemeName, "Dark", StringComparison.OrdinalIgnoreCase)
            ? darkVariant
            : lightVariant;

    string GetFontUrl(string style, int weight) =>
        $"https://cdn.jsdelivr.net/gh/Tyrrrz/DiscordFonts@master/ggsans-{style}-{weight}.woff2";

    ValueTask<string> ResolveAssetUrlAsync(string url) =>
        Context.ResolveAssetUrlAsync(url, CancellationToken);

    string FormatDate(DateTimeOffset instant, string format = "g") =>
        Context.FormatDate(instant, format);

    async ValueTask<string> FormatMarkdownAsync(string markdown) =>
        Context.Request.ShouldFormatMarkdown
            ? await HtmlMarkdownVisitor.FormatAsync(Context, markdown, true, CancellationToken)
            : markdown;
}

<!DOCTYPE html>
<html lang="en">

<head>
    <title>@Context.Request.Guild.Name - @Context.Request.Channel.Name</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width">

    @* Styling *@
    <style>
        @@font-face {
            src: url("@await ResolveAssetUrlAsync(GetFontUrl("normal", 400))");
            font-family: gg sans;
            font-weight: 400;
            font-style: normal;
        }

        @@font-face {
            src: url("@await ResolveAssetUrlAsync(GetFontUrl("normal", 500))");
            font-family: gg sans;
            font-weight: 500;
            font-style: normal;
        }

        @@font-face {
            src: url("@await ResolveAssetUrlAsync(GetFontUrl("normal", 600))");
            font-family: gg sans;
            font-weight: 600;
            font-style: normal;
        }

        @@font-face {
            src: url("@await ResolveAssetUrlAsync(GetFontUrl("normal", 700))");
            font-family: gg sans;
            font-weight: 700;
            font-style: normal;
        }

        @@font-face {
            src: url("@await ResolveAssetUrlAsync(GetFontUrl("normal", 800))");
            font-family: gg sans;
            font-weight: 800;
            font-style: normal;
        }

        @@font-face {
            src: url("@await ResolveAssetUrlAsync(GetFontUrl("italic", 400))");
            font-family: gg sans;
            font-weight: 400;
            font-style: italic;
        }

        @@font-face {
            src: url("@await ResolveAssetUrlAsync(GetFontUrl("italic", 500))");
            font-family: gg sans;
            font-weight: 500;
            font-style: italic;
        }

        @@font-face {
            src: url("@await ResolveAssetUrlAsync(GetFontUrl("italic", 600))");
            font-family: gg sans;
            font-weight: 600;
            font-style: italic;
        }

        @@font-face {
            src: url("@await ResolveAssetUrlAsync(GetFontUrl("italic", 700))");
            font-family: gg sans;
            font-weight: 700;
            font-style: italic;
        }

        @@font-face {
            src: url("@await ResolveAssetUrlAsync(GetFontUrl("italic", 800))");
            font-family: gg sans;
            font-weight: 800;
            font-style: italic;
        }

        html, body {
            margin: 0;
            padding: 0;
            background-color: @Themed("#36393e", "#ffffff");
            color: @Themed("#dcddde", "#23262a");
            font-family: "gg sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
            font-size: 17px;
            font-weight: @Themed("400", "500");
            scroll-behavior: smooth;
        }

        a {
            color: @Themed("#00aff4", "#0068e0");
            text-decoration: none;
        }

        a:hover {
            text-decoration: underline;
        }

        img {
            object-fit: contain;
            image-rendering: high-quality;
            image-rendering: -webkit-optimize-contrast;
        }

        .preamble {
            display: grid;
            grid-template-columns: auto 1fr;
            max-width: 100%;
            padding: 1rem;
        }

        .preamble__guild-icon-container {
            grid-column: 1;
        }

        .preamble__guild-icon {
            max-width: 88px;
            max-height: 88px;
        }

        .preamble__entries-container {
            grid-column: 2;
            margin-left: 1rem;
        }

        .preamble__entry {
            margin-bottom: 0.15rem;
            color: @Themed("#ffffff", "#2f3136");
            font-size: 1.4rem;
        }

        .preamble__entry--small {
            font-size: 1rem;
        }

        .chatlog {
            padding: 1rem 0;
            width: 100%;
            border-top: 1px solid @Themed("rgba(255, 255, 255, 0.1)", "#eceeef");
            border-bottom: 1px solid @Themed("rgba(255, 255, 255, 0.1)", "#eceeef");
        }

        .chatlog__message-group {
            margin-bottom: 1rem;
        }

        .chatlog__message-container {
            background-color: transparent;
            transition: background-color 1s ease;
        }

        .chatlog__message-container--highlighted {
            background-color: @Themed("rgba(114, 137, 218, 0.2)", "rgba(114, 137, 218, 0.2)");
        }

        .chatlog__message-container--pinned {
            background-color: @Themed("rgba(249, 168, 37, 0.05)", "rgba(249, 168, 37, 0.05)");
        }

        .chatlog__message {
            display: grid;
            grid-template-columns: auto 1fr;
            padding: 0.15rem 0;
            direction: ltr;
            unicode-bidi: bidi-override;
        }

        .chatlog__message:hover {
            background-color: @Themed("#32353b", "#fafafa");
        }

        .chatlog__message:hover .chatlog__short-timestamp {
            display: block;
        }

        .chatlog__message-aside {
            grid-column: 1;
            width: 72px;
            padding: 0.15rem 0.15rem 0 0.15rem;
            text-align: center;
        }

        .chatlog__reply-symbol {
            height: 10px;
            margin: 6px 4px 4px 36px;
            border-left: 2px solid @Themed("#4f545c", "#c7ccd1");
            border-top: 2px solid @Themed("#4f545c", "#c7ccd1");
            border-radius: 8px 0 0 0;
        }

        .chatlog__avatar {
            width: 40px;
            height: 40px;
            border-radius: 50%;
        }

        .chatlog__short-timestamp {
            display: none;
            color: @Themed("#a3a6aa", "#5e6772");
            font-size: 0.75rem;
            font-weight: 500;
            direction: ltr;
            unicode-bidi: bidi-override;
        }

        .chatlog__message-primary {
            grid-column: 2;
            min-width: 0;
        }

        .chatlog__reply {
            display: flex;
            margin-bottom: 0.15rem;
            align-items: center;
            color: @Themed("#b5b6b8", "#5f5f60");
            font-size: 0.875rem;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
        }

        .chatlog__reply-avatar {
            width: 16px;
            height: 16px;
            margin-right: 0.25rem;
            border-radius: 50%;
        }

        .chatlog__reply-author {
            margin-right: 0.3rem;
            font-weight: 600;
        }

        .chatlog__reply-content {
            overflow: hidden;
            text-overflow: ellipsis;
        }

        .chatlog__reply-link {
            cursor: pointer;
        }

        .chatlog__reply-link * {
            display: inline;
            pointer-events: none;
        }

        .chatlog__reply-link .chatlog__markdown-quote {
            display: inline;
        }

        .chatlog__reply-link .chatlog__markdown-pre {
            display: inline;
        }

        .chatlog__reply-link:hover {
            color: @Themed("#ffffff", "#2f3136");
        }

        .chatlog__reply-link:hover *:not(.chatlog__markdown-spoiler) {
            color: inherit;
        }

        .chatlog__reply-edited-timestamp {
            margin-left: 0.25rem;
            color: @Themed("#a3a6aa", "#5e6772");
            font-size: 0.75rem;
            font-weight: 500;
            direction: ltr;
            unicode-bidi: bidi-override;
        }

        .chatlog__forwarded {
            display: flex;
            flex-direction: column;
            margin-bottom: 0.15rem;
            padding: 0.5rem;
            border-left: 4px solid @Themed("#4f545c", "#c7ccd1");
            border-radius: 4px;
            background-color: @Themed("rgba(46, 48, 54, 0.3)", "rgba(249, 249, 249, 0.3)");
        }

        .chatlog__forwarded-header {
            display: flex;
            align-items: center;
            margin-bottom: 0.25rem;
            color: @Themed("#b5b6b8", "#5f5f60");
            font-size: 0.75rem;
            font-weight: 600;
        }

        .chatlog__forwarded-icon {
            width: 16px;
            height: 16px;
            margin-right: 0.25rem;
        }

        .chatlog__forwarded-content {
            color: @Themed("#dcddde", "#2e3338");
            font-size: 0.95rem;
        }

        .chatlog__forwarded-attachments {
            margin-top: 0.3rem;
        }

        .chatlog__forwarded-attachment {
            max-width: 300px;
            max-height: 200px;
            border-radius: 3px;
        }

        .chatlog__forwarded-timestamp {
            margin-top: 0.25rem;
            color: @Themed("#a3a6aa", "#5e6772");
            font-size: 0.75rem;
        }

        .chatlog__system-notification-icon {
            width: 18px;
            height: 18px;
        }

        .chatlog__system-notification-author {
            font-weight: @Themed("500", "600");
            color: @Themed("#ffffff", "#2f3136");
        }

        .chatlog__system-notification-content {
            color: @Themed("#96989d", "#5e6772")
        }

        .chatlog__system-notification-link {
            font-weight: 500;
            color: @Themed("#ffffff", "#2f3136");
        }

        .chatlog__system-notification-timestamp {
            margin-left: 0.3rem;
            color: @Themed("#a3a6aa", "#5e6772");
            font-size: 0.75rem;
            font-weight: 500;
            direction: ltr;
            unicode-bidi: bidi-override;
        }

        .chatlog__system-notification-timestamp a {
            color: inherit;
        }

        .chatlog__header {
            margin-bottom: 0.1rem;
        }

        .chatlog__author {
            font-weight: @Themed("500", "600");
            color: @Themed("#ffffff", "#2f3136");
        }

        .chatlog__author-tag {
            position: relative;
            top: -0.1rem;
            margin-left: 0.3rem;
            padding: 0.05rem 0.3rem;
            border-radius: 3px;
            background-color: #5865F2;
            color: #ffffff;
            font-size: 0.625rem;
            font-weight: 500;
            line-height: 1.3;
        }

        .chatlog__timestamp {
            margin-left: 0.3rem;
            color: @Themed("#a3a6aa", "#5e6772");
            font-size: 0.75rem;
            font-weight: 500;
            direction: ltr;
            unicode-bidi: bidi-override;
        }

        .chatlog__timestamp a {
            color: inherit;
        }

        .chatlog__content {
            padding-right: 1rem;
            font-size: 0.95rem;
            word-wrap: break-word;
        }

        .chatlog__edited-timestamp {
            margin-left: 0.15rem;
            color: @Themed("#a3a6aa", "#5e6772");
            font-size: 0.75rem;
            font-weight: 500;
        }

        .chatlog__attachment {
            position: relative;
            width: fit-content;
            margin-top: 0.3rem;
            border-radius: 3px;
            overflow: hidden;
        }

        .chatlog__attachment--hidden {
            cursor: pointer;
            box-shadow: 0 0 1px 1px rgba(0, 0, 0, 0.1);
        }

        .chatlog__attachment--hidden * {
            pointer-events: none;
        }

        .chatlog__attachment-spoiler-caption {
            display: none;
            position: absolute;
            left: 50%;
            top: 50%;
            z-index: 999;
            padding: 0.4rem 0.8rem;
            border-radius: 20px;
            transform: translate(-50%, -50%);
            background-color: rgba(0, 0, 0, 0.9);
            color: #dcddde;
            font-size: 0.9rem;
            font-weight: 600;
            letter-spacing: 0.05rem;
        }

        .chatlog__attachment--hidden .chatlog__attachment-spoiler-caption {
            display: block;
        }

        .chatlog__attachment--hidden:hover .chatlog__attachment-spoiler-caption {
            color: #fff;
        }

        .chatlog__attachment-media {
            max-width: 45vw;
            max-height: 500px;
            vertical-align: top;
            border-radius: 3px;
        }

        .chatlog__attachment--hidden .chatlog__attachment-media {
            filter: blur(44px);
        }

        .chatlog__attachment-generic {
            max-width: 520px;
            width: 100%;
            height: 40px;
            padding: 10px;
            border: 1px solid @Themed("#292b2f", "#ebedef");
            border-radius: 3px;
            background-color: @Themed("#2f3136", "#f2f3f5");
            overflow: hidden;
        }

        .chatlog__attachment--hidden .chatlog__attachment-generic {
            filter: blur(44px);
        }

        .chatlog__attachment-generic-icon {
            float: left;
            width: 30px;
            height: 100%;
            margin-right: 10px;
        }

        .chatlog__attachment-generic-size {
            color: #72767d;
            font-size: 12px;
        }

        .chatlog__attachment-generic-name {
            overflow: hidden;
            white-space: nowrap;
            text-overflow: ellipsis;
        }

        .chatlog__embed {
            display: flex;
            margin-top: 0.3rem;
            max-width: 520px;
        }

        .chatlog__embed-color-pill {
            flex-shrink: 0;
            width: 0.25rem;
            border-top-left-radius: 3px;
            border-bottom-left-radius: 3px;
        }

        .chatlog__embed-color-pill--default {
            background-color: @Themed("#202225", "rgba(227, 229, 232, 1)");
        }

        .chatlog__embed-content-container {
            display: flex;
            flex-direction: column;
            padding: 0.5rem 0.6rem;
            border: 1px solid @Themed("rgba(46, 48, 54, 0.6)", "rgba(204, 204, 204, 0.3)");
            border-top-right-radius: 3px;
            border-bottom-right-radius: 3px;
            background-color: @Themed("rgba(46, 48, 54, 0.3)", "rgba(249, 249, 249, 0.3)");
        }

        .chatlog__embed-content {
            display: flex;
            width: 100%;
        }

        .chatlog__embed-text {
            flex: 1;
        }

        .chatlog__embed-author-container {
            display: flex;
            margin-bottom: 0.5rem;
            align-items: center;
        }

        .chatlog__embed-author-icon {
            width: 20px;
            height: 20px;
            margin-right: 0.5rem;
            border-radius: 50%;
        }

        .chatlog__embed-author {
            color: @Themed("#ffffff", "#4f545c");
            font-size: 0.875rem;
            font-weight: 600;
            direction: ltr;
            unicode-bidi: bidi-override;
        }

        .chatlog__embed-author-link {
            color: @Themed("#ffffff", "#4f545c");
        }

        .chatlog__embed-title {
            margin-bottom: 0.5rem;
            color: @Themed("#ffffff", "#4f545c");
            font-size: 0.875rem;
            font-weight: 600;
        }

        .chatlog__embed-description {
            color: @Themed("#dcddde", "#2e3338");
            font-weight: 500;
            font-size: 0.85rem;
        }

        .chatlog__embed-fields {
            display: flex;
            flex-wrap: wrap;
            gap: 0 0.5rem;
        }

        .chatlog__embed-field {
            flex: 0;
            min-width: 100%;
            max-width: 506px;
            padding-top: 0.6rem;
            font-size: 0.875rem;
        }

        .chatlog__embed-field--inline {
            flex: 1;
            flex-basis: auto;
            min-width: 50px;
        }

        .chatlog__embed-field-name {
            margin-bottom: 0.2rem;
            color: @Themed("#ffffff", "#36393e");
            font-weight: 600;
        }

        .chatlog__embed-field-value {
            color: @Themed("#dcddde", "#2e3338");
            font-weight: 500;
        }

        .chatlog__embed-thumbnail {
            flex: 0;
            max-width: 80px;
            max-height: 80px;
            margin-left: 1.2rem;
            border-radius: 3px;
        }

        .chatlog__embed-images {
            display: grid;
            margin-top: 0.6rem;
            grid-template-columns: repeat(2, 1fr);
            gap: 0.25rem;
        }

        .chatlog__embed-images--single {
            display: block;
        }

        .chatlog__embed-image {
            object-fit: cover;
            object-position: center;
            max-width: 500px;
            max-height: 400px;
            width: 100%;
            height: 100%;
            border-radius: 3px;
        }

        .chatlog__embed-footer {
            margin-top: 0.6rem;
            color: @Themed("#dcddde", "#2e3338");
        }

        .chatlog__embed-footer-icon {
            width: 20px;
            height: 20px;
            margin-right: 0.2rem;
            border-radius: 50%;
            vertical-align: middle;
        }

        .chatlog__embed-footer-text {
            vertical-align: middle;
            font-size: 0.75rem;
            font-weight: 500;
        }

        .chatlog__embed-invite-container {
            min-width: 320px;
            padding: 0.6rem 0.7rem;
            border: 1px solid @Themed("rgba(46, 48, 54, 0.6)", "rgba(204, 204, 204, 0.3)");
            border-radius: 3px;
            background-color: @Themed("rgba(46, 48, 54, 0.3)", "rgba(249, 249, 249, 0.3)");
        }

        .chatlog__embed-invite-title {
            margin: 0 0 0.8rem 0;
            color: @Themed("#b9bbbe", "#4f5660");
            font-size: 0.75rem;
            font-weight: 700;
            text-transform: uppercase;
        }

        .chatlog__embed-invite {
            display: flex;
        }

        .chatlog__embed-invite-guild-icon {
            width: 50px;
            height: 50px;
            border-radius: 0.85rem;
        }

        .chatlog__embed-invite-info {
            margin-left: 1rem;
        }

        .chatlog__embed-invite-guild-name {
            color: @Themed("#ffffff", "#36393e");
            font-weight: 600;
        }

        .chatlog__embed-invite-guild-name a {
            color: inherit;
        }

        .chatlog__embed-invite-channel-icon {
            width: 18px;
            height: 18px;
            vertical-align: bottom;
        }

        .chatlog__embed-invite-channel-name {
            font-size: 0.9rem;
            font-weight: 600;
        }

        .chatlog__embed-generic-image {
            object-fit: contain;
            object-position: left;
            max-width: 45vw;
            max-height: 500px;
            vertical-align: top;
            border-radius: 3px;
        }

        .chatlog__embed-generic-video {
            object-fit: contain;
            object-position: left;
            max-width: 45vw;
            max-height: 500px;
            vertical-align: top;
            border-radius: 3px;
        }

        .chatlog__embed-generic-gifv {
            object-fit: contain;
            object-position: left;
            max-width: 45vw;
            max-height: 500px;
            vertical-align: top;
            border-radius: 3px;
        }

        .chatlog__embed-spotify {
            border: 0;
        }
        
        .chatlog__embed-twitch {
            border: 0;
        }

        .chatlog__embed-youtube-container {
            margin-top: 0.6rem;
        }

        .chatlog__embed-youtube-thumbnail {
            max-width: 400px;
            max-height: 225px;
            border-radius: 3px;
            cursor: pointer;
        }

        .chatlog__sticker {
            width: 180px;
            height: 180px;
        }

        .chatlog__sticker--media {
            max-width: 100%;
            max-height: 100%;
        }

        .chatlog__reactions {
            display: flex;
        }

        .chatlog__reaction {
            display: flex;
            margin: 0.35rem 0.1rem 0.1rem 0;
            padding: 0.125rem 0.375rem;
            border: 1px solid transparent;
            border-radius: 8px;
            background-color: @Themed("#2f3136", "#f2f3f5");
            align-items: center;
        }

        .chatlog__reaction:hover {
            border: 1px solid @Themed("hsla(0,0%,100%,.2)", "rgba(0, 0, 0, 0.2)");
            background-color: @Themed("transparent", "white");
        }

        .chatlog__reaction-count {
            min-width: 9px;
            margin-left: 0.35rem;
            color: @Themed("#b9bbbe", "#4f5660");
            font-size: 0.875rem;
        }

        .chatlog__reaction:hover .chatlog__reaction-count {
            color: @Themed("#dcddde", "#2e3338");
        }

        .chatlog__markdown {
            max-width: 100%;
            line-height: 1.3;
            overflow-wrap: break-word;
        }

        .chatlog__markdown h1 {
            margin: 1rem 0 0.5rem;
            color: @Themed("#f2f3f5", "#060607");
            font-size: 1.5rem;
            line-height: 1;
        }

        .chatlog__markdown h2 {
            margin: 1rem 0 0.5rem;
            color: @Themed("#f2f3f5", "#060607");
            font-size: 1.25rem;
            line-height: 1;
        }

        .chatlog__markdown h3 {
            margin: 1rem 0 0.5rem;
            color: @Themed("#f2f3f5", "#060607");
            font-size: 1rem;
            line-height: 1;
        }

        .chatlog__markdown h1:first-child, h2:first-child, h3:first-child {
            margin-top: 0.5rem;
        }

        .chatlog__markdown ul, ol {
            margin: 0 0 0 1rem;
            padding: 0;
        }

        .chatlog__markdown-preserve {
            white-space: pre-wrap;
        }

        .chatlog__markdown-spoiler {
            background-color: @Themed("rgba(255, 255, 255, 0.1)", "rgba(0, 0, 0, 0.1)");
            padding: 0 2px;
            border-radius: 3px;
        }

        .chatlog__markdown-spoiler--hidden {
            cursor: pointer;
            background-color: @Themed("#202225", "#b9bbbe");
            color: rgba(0, 0, 0, 0);
        }

        .chatlog__markdown-spoiler--hidden:hover {
            background-color: @Themed("rgba(32, 34, 37, 0.8)", "rgba(185, 187, 190, 0.8)");
        }

        .chatlog__markdown-spoiler--hidden::selection {
            color: rgba(0, 0, 0, 0);
        }

        .chatlog__markdown-quote {
            display: flex;
            margin: 0.05rem 0;
        }

        .chatlog__markdown-quote-border {
            margin-right: 0.5rem;
            border: 2px solid @Themed("#4f545c", "#c7ccd1");
            border-radius: 3px;
        }

        .chatlog__markdown-pre {
            background-color: @Themed("#2f3136", "#f9f9f9");
            font-family: "Consolas", "Courier New", Courier, monospace;
            font-size: 0.85rem;
            text-decoration: inherit;
        }

        .chatlog__markdown-pre--multiline {
            display: block;
            margin-top: 0.25rem;
            padding: 0.5rem;
            border: 2px solid @Themed("#282b30", "#f3f3f3");
            border-radius: 5px;
            color: @Themed("#b9bbbe", "#657b83");
        }

        .chatlog__markdown-pre--multiline.hljs {
            background-color: @Themed("#2f3136", "#f9f9f9");
            color: @Themed("#b9bbbe", "#657b83");
        }

        .chatlog__markdown-pre--inline {
            display: inline-block;
            padding: 2px;
            border-radius: 3px;
        }

        .chatlog__markdown-mention {
            border-radius: 3px;
            padding: 0 2px;
            background-color: @Themed("rgba(88, 101, 242, .3)", "rgba(88, 101, 242, .15)");
            color: @Themed("#dee0fc", "#505cdc");
            font-weight: 500;
        }

        .chatlog__markdown-mention:hover {
            background-color: #5865f2;
            color: #ffffff
        }

        .chatlog__markdown-timestamp {
            background-color: @Themed("rgba(255, 255, 255, 0.1)", "rgba(0, 0, 0, 0.1)");
            padding: 0 2px;
            border-radius: 3px;
        }

        .chatlog__emoji {
            width: 1.325rem;
            height: 1.325rem;
            margin: 0 0.06rem;
            vertical-align: -0.4rem;
        }

        .chatlog__emoji--small {
            width: 1rem;
            height: 1rem;
        }

        .chatlog__emoji--large {
            width: 2.8rem;
            height: 2.8rem;
        }

        .postamble {
            padding: 1.25rem;
        }

        .postamble__entry {
            color: @Themed("#ffffff", "#2f3136");
        }
    </style>

    @* Syntax highlighting *@
    <link rel="stylesheet" href="@await ResolveAssetUrlAsync($"https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.15.6/styles/solarized-{ThemeName.ToLowerInvariant()}.min.css")">
    <script src="@await ResolveAssetUrlAsync("https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.15.6/highlight.min.js")"></script>
    <script>
        document.addEventListener('DOMContentLoaded', () => {
            document.querySelectorAll('.chatlog__markdown-pre--multiline').forEach(e => hljs.highlightBlock(e));
        });
    </script>

    @* Lottie animation support *@
    <script src="@await ResolveAssetUrlAsync("https://cdnjs.cloudflare.com/ajax/libs/lottie-web/5.8.1/lottie.min.js")"></script>
    <script>
        document.addEventListener('DOMContentLoaded', () => {
            document.querySelectorAll('.chatlog__sticker--media[data-source]').forEach(e => {
                const anim = lottie.loadAnimation({
                    container: e,
                    renderer: 'svg',
                    loop: true,
                    autoplay: true,
                    path: e.getAttribute('data-source')
                });

                anim.addEventListener(
                    'data_failed',
                    () => e.innerHTML = '<strong>[Sticker cannot be rendered]</strong>'
                );
            });
        });
    </script>

    @* Scripts *@
    <script>
        function scrollToMessage(event, id) {
            const element = document.getElementById('chatlog__message-container-' + id);
            if (!element)
                return;

            event.preventDefault();
            element.classList.add('chatlog__message-container--highlighted');

            window.scrollTo({
                top: element.getBoundingClientRect().top - document.body.getBoundingClientRect().top - (window.innerHeight / 2),
                behavior: 'smooth'
            });

            window.setTimeout(
                () => element.classList.remove('chatlog__message-container--highlighted'),
                2000
            );
        }

        function showSpoiler(event, element) {
            if (!element)
                return;

            if (element.classList.contains('chatlog__attachment--hidden')) {
                event.preventDefault();
                element.classList.remove('chatlog__attachment--hidden');
            }

            if (element.classList.contains('chatlog__markdown-spoiler--hidden')) {
                event.preventDefault();
                element.classList.remove('chatlog__markdown-spoiler--hidden');
            }
        }
    </script>

    @* Icons *@
    <svg style="display: none" xmlns="http://www.w3.org/2000/svg">
        <defs>
            <symbol id="attachment-icon" viewBox="0 0 720 960">
                <path fill="#f4f5fb" d="M50,935a25,25,0,0,1-25-25V50A25,25,0,0,1,50,25H519.6L695,201.32V910a25,25,0,0,1-25,25Z" />
                <path fill="#7789c4" d="M509.21,50,670,211.63V910H50V50H509.21M530,0H50A50,50,0,0,0,0,50V910a50,50,0,0,0,50,50H670a50,50,0,0,0,50-50h0V191Z" />
                <path fill="#f4f5fb" d="M530,215a25,25,0,0,1-25-25V50a25,25,0,0,1,16.23-23.41L693.41,198.77A25,25,0,0,1,670,215Z" />
                <path fill="#7789c4" d="M530,70.71,649.29,190H530V70.71M530,0a50,50,0,0,0-50,50V190a50,50,0,0,0,50,50H670a50,50,0,0,0,50-50Z" />
            </symbol>
            <symbol id="join-icon" viewBox="0 0 18 18">
                <path fill="#3ba55c" d="m0 8h14.2l-3.6-3.6 1.4-1.4 6 6-6 6-1.4-1.4 3.6-3.6h-14.2" />
            </symbol>
            <symbol id="leave-icon" viewBox="0 0 18 18">
                <path fill="#ed4245" d="m3.8 8 3.6-3.6-1.4-1.4-6 6 6 6 1.4-1.4-3.6-3.6h14.2v-2" />
            </symbol>
            <symbol id="call-icon" viewBox="0 0 18 18">
                <path fill="#3ba55c" fill-rule="evenodd" d="M17.7163041 15.36645368c-.0190957.02699568-1.9039523 2.6680735-2.9957762 2.63320406-3.0676659-.09785935-6.6733809-3.07188394-9.15694343-5.548738C3.08002193 9.9740657.09772497 6.3791404 0 3.3061316v-.024746C0 2.2060575 2.61386252.3152347 2.64082114.2972376c.7110335-.4971705 1.4917101-.3149497 1.80959713.1372281.19320342.2744561 2.19712724 3.2811005 2.42290565 3.6489167.09884826.1608492.14714912.3554431.14714912.5702838 0 .2744561-.07975258.5770327-.23701117.8751101-.1527655.2902036-.65262318 1.1664385-.89862055 1.594995.2673396.3768148.94804468 1.26429792 2.351016 2.66357424 1.39173858 1.39027775 2.28923588 2.07641807 2.67002628 2.34187563.4302146-.2452108 1.3086162-.74238132 1.5972981-.89423205.5447887-.28682915 1.0907006-.31944893 1.4568885-.08661115.3459689.2182151 3.3383754 2.21027167 3.6225641 2.41611376.2695862.19234426.4144887.5399137.4144887.91672846 0 .2969525-.089862.61190215-.2808189.88523346" />
            </symbol>
            <symbol id="pencil-icon" viewBox="0 0 18 18">
                <path fill="#99aab5" d="m0 14.25v3.75h3.75l11.06-11.06-3.75-3.75zm17.71-10.21c.39-.39.39-1.02 0-1.41l-2.34-2.34c-.39-.39-1.02-.39-1.41 0l-1.83 1.83 3.75 3.75z" />
            </symbol>
            <symbol id="pin-icon" viewBox="0 0 18 18">
                <path fill="#b9bbbe" d="m16.908 8.39684-8.29587-8.295827-1.18584 1.184157 1.18584 1.18584-4.14834 4.1475v.00167l-1.18583-1.18583-1.185 1.18583 3.55583 3.55502-4.740831 4.74 1.185001 1.185 4.74083-4.74 3.55581 3.555 1.185-1.185-1.185-1.185 4.1475-4.14836h.0009l1.185 1.185z" />
            </symbol>
            <symbol id="channel-icon" viewBox="0 0 24 24">
                <path fill="#b9bbbe" d="M5.88657 21C5.57547 21 5.3399 20.7189 5.39427 20.4126L6.00001 17H2.59511C2.28449 17 2.04905 16.7198 2.10259 16.4138L2.27759 15.4138C2.31946 15.1746 2.52722 15 2.77011 15H6.35001L7.41001 9H4.00511C3.69449 9 3.45905 8.71977 3.51259 8.41381L3.68759 7.41381C3.72946 7.17456 3.93722 7 4.18011 7H7.76001L8.39677 3.41262C8.43914 3.17391 8.64664 3 8.88907 3H9.87344C10.1845 3 10.4201 3.28107 10.3657 3.58738L9.76001 7H15.76L16.3968 3.41262C16.4391 3.17391 16.6466 3 16.8891 3H17.8734C18.1845 3 18.4201 3.28107 18.3657 3.58738L17.76 7H21.1649C21.4755 7 21.711 7.28023 21.6574 7.58619L21.4824 8.58619C21.4406 8.82544 21.2328 9 20.9899 9H17.41L16.35 15H19.7549C20.0655 15 20.301 15.2802 20.2474 15.5862L20.0724 16.5862C20.0306 16.8254 19.8228 17 19.5799 17H16L15.3632 20.5874C15.3209 20.8261 15.1134 21 14.8709 21H13.8866C13.5755 21 13.3399 20.7189 13.3943 20.4126L14 17H8.00001L7.36325 20.5874C7.32088 20.8261 7.11337 21 6.87094 21H5.88657ZM9.41045 9L8.35045 15H14.3504L15.4104 9H9.41045Z" />
            </symbol>
            <symbol id="thread-icon" viewBox="0 0 24 24">
                <path fill="#b9bbbe" d="M5.43309 21C5.35842 21 5.30189 20.9325 5.31494 20.859L5.99991 17H2.14274C2.06819 17 2.01168 16.9327 2.02453 16.8593L2.33253 15.0993C2.34258 15.0419 2.39244 15 2.45074 15H6.34991L7.40991 9H3.55274C3.47819 9 3.42168 8.93274 3.43453 8.85931L3.74253 7.09931C3.75258 7.04189 3.80244 7 3.86074 7H7.75991L8.45234 3.09903C8.46251 3.04174 8.51231 3 8.57049 3H10.3267C10.4014 3 10.4579 3.06746 10.4449 3.14097L9.75991 7H15.7599L16.4523 3.09903C16.4625 3.04174 16.5123 3 16.5705 3H18.3267C18.4014 3 18.4579 3.06746 18.4449 3.14097L17.7599 7H21.6171C21.6916 7 21.7481 7.06725 21.7353 7.14069L21.4273 8.90069C21.4172 8.95811 21.3674 9 21.3091 9H17.4099L17.0495 11.04H15.05L15.4104 9H9.41035L8.35035 15H10.5599V17H7.99991L7.30749 20.901C7.29732 20.9583 7.24752 21 7.18934 21H5.43309Z" />
                <path fill="#b9bbbe" d="M13.4399 12.96C12.9097 12.96 12.4799 13.3898 12.4799 13.92V20.2213C12.4799 20.7515 12.9097 21.1813 13.4399 21.1813H14.3999C14.5325 21.1813 14.6399 21.2887 14.6399 21.4213V23.4597C14.6399 23.6677 14.8865 23.7773 15.0408 23.6378L17.4858 21.4289C17.6622 21.2695 17.8916 21.1813 18.1294 21.1813H22.5599C23.0901 21.1813 23.5199 20.7515 23.5199 20.2213V13.92C23.5199 13.3898 23.0901 12.96 22.5599 12.96H13.4399Z" />
            </symbol>
            <symbol id="forward-icon" viewBox="0 0 24 24">
                <path fill="#b9bbbe" d="M13 4L21 12L13 20V15C8 15 4 17 1 22C2 16 6 10 13 9V4Z" />
            </symbol>
        </defs>
    </svg>
</head>
<body>

<div class="preamble">
    <div class="preamble__guild-icon-container">
        <img class="preamble__guild-icon" src="@await ResolveAssetUrlAsync(Context.Request.Channel.IconUrl ?? Context.Request.Guild.IconUrl)" alt="Guild icon" loading="lazy">
    </div>
    <div class="preamble__entries-container">
        <div class="preamble__entry">@Context.Request.Guild.Name</div>
        <div class="preamble__entry">@Context.Request.Channel.GetHierarchicalName()</div>

        @if (!string.IsNullOrWhiteSpace(Context.Request.Channel.Topic))
        {
            <div class="preamble__entry preamble__entry--small">@Html.Raw(await FormatMarkdownAsync(Context.Request.Channel.Topic))</div>
        }

        @if (Context.Request.After is not null || Context.Request.Before is not null)
        {
            <div class="preamble__entry preamble__entry--small">
                @if (Context.Request.After is not null && Context.Request.Before is not null)
                {
                    @($"Between {FormatDate(Context.Request.After.Value.ToDate())} and {FormatDate(Context.Request.Before.Value.ToDate())}")
                }
                else if (Context.Request.After is not null)
                {
                    @($"After {FormatDate(Context.Request.After.Value.ToDate())}")
                }
                else if (Context.Request.Before is not null)
                {
                    @($"Before {FormatDate(Context.Request.Before.Value.ToDate())}")
                }
            </div>
        }
    </div>
</div>

@* Preamble cuts off at this point *@
<!--wmm:ignore-->
<div class="chatlog">
<!--/wmm:ignore-->