extends baseLayout

block body
    #paste
        - bool historyPage = false;
        include components/pasteHeader

        .paste-pasties
            -foreach(i, p; paste.pasties)
                .pasty
                    .pasty-header
                        -if(p.title != "")
                            p.title= p.title
                        -else
                            p.title.untitled (untitled)
                        .right
                            span.lang= p.language
                            a.copy copy
                            - if (!paste.isPrivate && !paste.encrypted)
                                - static if (is(typeof(previousRevision)) && previousRevision)
                                    - import std.conv : to;
                                    a.raw(href="/raw/" ~ paste.id ~ "/" ~ p.id ~ "/" ~ currentEditId.to!string()) raw
                                - else
                                    a.raw(href="/raw/" ~ paste.id ~ "/" ~ p.id) raw
                    .pasty-content
                        - if (p.language == "Markdown" || p.language == "GitHub Flavored Markdown")
                            .markdown-rendered
                                - import commonmarkd;
                                |!= convertMarkdownToHTML(p.code, MarkdownFlag.tablesExtension | MarkdownFlag.noHTML)
                                textarea.hidden=p.code
                        - else
                            textarea=p.code

        .paste-meta
            - if (paste.ownerId == session.userId && paste.tags.length > 0)
                p.tags
                    - import std.uri : encodeComponent;
                    span.highlight tags:
                    span.value
                        - foreach (t; paste.tags)
                            a.tag(href="/user/profile?tag=" ~ encodeComponent(t))= t
            p.created-at
                span.highlight created at:
                span.value
            -import pastemyst.data : ExpiresIn;
            -if(paste.expiresIn != ExpiresIn.never)
                p.expires-in
                    span.highlight expires in:
                    span.value
            -if(paste.edits.length != 0)
                p.edited-at
                    span.highlight last edited at:
                    span.value
                p
                    - import pastemyst.db : getNumberOfEdits;
                    span.highlight edits: 
                    span.value= getNumberOfEdits(paste)
            - if (paste.ownerId != "" && (paste.ownerId == session.userId || paste.isPublic))
                - import pastemyst.db : findOneById;
                - import pastemyst.data : User;
                - const user = findOneById!User(paste.ownerId).get();
                p.pasted-by
                    span.highlight pasted by:
                    span.value
                        - if (paste.ownerId == session.userId)
                            span you
                        - else if (paste.isPublic)
                            a(href="/users/" ~ user.username)= user.username
            p.stats
                - import pastemyst.paste : getPasteStats;
                - auto stats = getPasteStats(paste);
                span.highlight stats:
                span.value  #{stats[0]} lines, #{stats[1]} words, #{stats[2]}

block scripts
    - import pastemyst.data : getVersion;

    script.
        var createdAt = #{paste.createdAt};
        var expiresIn = "#{cast(string) paste.expiresIn}";
        var deletesAt = #{paste.deletesAt};
        var isEdited = #{paste.edits.length != 0};
        var editedAt = 0;
        var langs = [];

    -foreach(p; paste.pasties)
        script.
            langs.push("#{p.language}");

    -if(paste.edits.length != 0)
        script.
            editedAt = #{paste.edits[$-1].editedAt};

    script(type="module", src="/static/scripts/pages/paste.js?v=#{getVersion()}")

    script(src="/static/scripts/libs/highlight.pack.js?v=#{getVersion()}")

    script.
        hljs.initHighlightingOnLoad();
