extends baseLayout

block body
    #history
        - bool historyPage = true;
        include components/pasteHeader

        .block
            - import pastemyst.data;
            - import std.algorithm : reverse;
            - import std.array : array;
            - import std.conv : to;
            - Edit[] edits = paste.edits.reverse.array();
            - foreach (ulong i, Edit edit; edits)
                .edit
                    - if (i == 0 || edits[i-1].editId != edit.editId)
                        .edit-header
                            p ##{edit.editId} | edited at
                            span.editedAt= edit.editedAt
                            a.jump.tooltip(href="/" ~ paste.id ~ "/history/" ~ edit.editId.to!string())
                                span.jump jump
                                span.tooltip-text jump to this point in history

                    .subedit
                        .subedit-content
                            - if (edit.editType == EditType.title)
                                - auto nextTitle = getNextTitle(paste, edit);
                                .change.title-change
                                    span #{editTypeDescription(edit)}: 
                                    span.before= nextTitle.previous
                                    span.arrow ➝
                                    span.after= nextTitle.next
                            - if (edit.editType == EditType.pastyTitle)
                                - auto nextTitle = getNextPastyTitle(paste, edit);
                                .change.title-change
                                    span #{editTypeDescription(edit)}: 
                                    span.before= nextTitle.previous
                                    span.arrow ➝
                                    span.after= nextTitle.next
                            - if (edit.editType == EditType.pastyLanguage)
                                - auto nextLanguage = getNextPastyLanguage(paste, edit);
                                .change.title-change
                                    span #{editTypeDescription(edit)}: 
                                    span.before= nextLanguage.previous
                                    span.arrow ➝
                                    span.after= nextLanguage.next
                            - if (edit.editType == EditType.pastyContent)
                                - auto diff = getPastyDiff(edit);
                                .change.pasty-content-change
                                    span= editTypeDescription(edit)
                                    textarea.diff= diff
                            - if (edit.editType == EditType.pastyAdded)
                                - auto pasty = getAddedPasty(edit);
                                .change.pasty-added
                                    span= editTypeDescription(edit)
                                    .pasty-added-header
                                        - if (pasty.title != "")
                                            p.title= pasty.title
                                        - else
                                            p.title.untitled (untitled)
                                        span.lang= pasty.language
                                    .pasty-added-content
                                        textarea.added= pasty.code
                            - if (edit.editType == EditType.pastyRemoved)
                                - auto pasty = getRemovedPasty(edit);
                                .change.pasty-added.pasty-removed
                                    span= editTypeDescription(edit)
                                    .pasty-added-header
                                        - if (pasty.title != "")
                                            p.title= pasty.title
                                        - else
                                            p.title.untitled (untitled)
                                        span.lang= pasty.language
                                    .pasty-added-content
                                        textarea.added= pasty.code

block scripts
    - import pastemyst.data : getVersion;

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