extends baseLayout

block body
    #profile
        include components/userinfo

        form(method="get", action="/user/profile")
            .paste-search
                .label
                    label(for="search") search:
                input#search(type="text", placeholder="...", name="search", value=search, aria-label="search pastes")
                input(type="hidden", name="tag", value=tag)
            input(type="submit")

        .tags-pastes

            .tags
                ul
                    - import std.uri : encodeComponent, decodeComponent;
                    li: a(href="/user/profile", class=tag==""?"selected":"") all
                    li: a(href="/user/profile?tag=untagged&search=" ~ search, class=tag=="untagged"?"selected":"") untagged
                    - foreach (t; tags)
                        - if (t == "untagged") //- in case an actual untagged tag exists
                            - continue;
                        li: a(href="/user/profile?tag=" ~ encodeComponent(t) ~ "&search=" ~ search, class=tag==decodeComponent(t)?"selected":"")= t

            .pastes
                - import pastemyst.paste : pasteLangStats, LangStat;
                - import pastemyst.db : findOneById;
                - import pastemyst.data : Paste;

                - if (pastes.length == 0)
                    p.empty no pastes found

                - foreach(paste; pastes)
                    - LangStat[] langStats;
                    - Paste properPaste;
                    - if (!paste.encrypted)
                        - properPaste = findOneById!Paste(paste.id).get();
                        - langStats = pasteLangStats(properPaste);
                    a.paste(href="/" ~ paste.id, class=langStats.length > 0 ? "" : "border-bottom")
                        .top
                            .title
                                - string pasteTitle;
                                - if (paste.encrypted)
                                    - pasteTitle = "(encrypted)";
                                - else
                                    - pasteTitle = properPaste.title;
                                - if (pasteTitle != "")
                                    p= pasteTitle
                                - else
                                    p.untitled (untitled)

                                .info-icons
                                    - if (paste.encrypted)
                                        span.tooltip
                                            i.fas.fa-key
                                            span.tooltip-text encrypted
                                    - if (paste.isPrivate)
                                        span.tooltip
                                            i.fas.fa-lock
                                            span.tooltip-text private
                                    - else if (paste.isPublic)
                                        span.tooltip
                                            i.fas.fa-eye
                                            span.tooltip-text on your public profile
                            .info
                                p.created-at.tooltip
                                    span.tooltip-text
                                    span.value
                                p.edited-at.tooltip
                                    span.tooltip-text
                                    span.value
                                p.expires-in
                        - if (langStats.length > 0)
                            include components/langBar

block scripts
    - import pastemyst.data : getVersion;

    script.
        var pastes = [];

    - foreach(p; pastes)
        script.
            var pastetmp = {'createdAt': '#{p.createdAt}', 'expiresIn': '#{cast(string) p.expiresIn}', 'deletesAt': #{p.deletesAt}};
            pastetmp.editedAt = 0;

        - if (!p.encrypted)
            - auto properPaste = findOneById!Paste(p.id).get();
            - if (properPaste.edits.length != 0)
                script.
                    pastetmp.editedAt = #{properPaste.edits[$-1].editedAt};

        script.
            pastes.push(pastetmp);

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