extends baseLayout

block body
    #profile.public-profile
        .public-user-info
            img.avatar(src=user.avatarUrl, alt="user avatar")
            p.username= user.username
            - if (user.supporterLength > 0)
                .supporter-badge.tooltip
                    i.fas.fa-user-astronaut
                    span.tooltip-text supporter for #{user.supporterLength} months
            - if (user.contributor)
                .contributor-badge.tooltip
                    i.fas.fa-user-ninja
                    span.tooltip-text contributor

        form(method="get", action="/users/" ~ user.username)
            .paste-search
                .label
                    label(for="search") search:
                input#search(type="text", placeholder="...", name="search", value=search, aria-label="paste search")
            input(type="submit")

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

            - if (pastes.length == 0)
                - if (search == "")
                    p.empty this user has no pastes visible on their profile
                - else
                    p.empty no pastes match the search query

            - 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")
                    .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
                    .info
                        p.created-at.tooltip
                            span.value
                            span.tooltip-text
                        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()}")
