<commit_before>const {li, div, img, a, span, h3, p} = require('../../modules/tags')
const {timeAgo} = require('../../modules/auxiliaries')
const icon = require('./icon.tmpl')
const previewCard = require('./preview_card.tmpl')
const previewUnit = require('./preview_unit.tmpl')
const previewSubject = require('./preview_subject.tmpl')

const renderProposal = (data) => {
    if (!data.kind === 'proposal') { return }
    const entityVersions = data.entityVersionsFull || []
    return div(
        {className: 'post__proposal'},
        entityVersions.map((version) => {
            const {entityKind} = version
            if (entityKind === 'card') {
                return previewCard(Object.assign({}, version, {
                    unit: { name: version.unit_id },
                    requires: version.require_ids.map(id => ({id}))
                }))
            }
            if (entityKind === 'unit') {
                return previewUnit(Object.assign({}, version, {
                    requires: version.require_ids.map(id => ({id}))
                }))
            }
            if (entityKind === 'subject') {
                return previewSubject(version)
            }
            return null
        })
    )
}

const voteResponse = (response) => {
    if(!response) { return }
    return [
        span(
            {
                className: `post__vote--${response ? 'good' : 'bad'}`
            },
            icon(response ? 'good' : 'bad'),
            response ? ' Yes' : ' No'
        ),
        ' '
    ]
}

module.exports = (data, currentUserID) => {
    const topicId = data.topic_id
    return li(
        {
            id: data.id,
            className: 'post',
        },
        div(
            {className: 'post__avatar'},
            a(
                {href: `/users/${data.user_id}`},
                img({
                    src: data.user.avatar || '',
                    width: 48,
                    height: 48
                })
            )
        ),
        div(
            {className: 'post__content'},
            div({className: 'post__when'}, timeAgo(data.created)),
            a(
                {
                    className: 'post__name',
                    href: `/users/${data.user_id}`,
                },
                data.user.name || '???'
            ),
            div(
                data.replies_to_id ? a(
                    {
                        className: 'post__in-reply',
                        href: `/topics/${data.topic_id}#${data.replies_to_id}`
                    },
                    icon('reply'),
                    ' In Reply'
                ) : null,
                data.replies_to_id ? ' ' : null,
                data.kind === 'proposal' ? h3('Proposal: ' + data.name) : null,
                voteResponse(data.response),
                data.body
            ),
            data.kind === 'proposal' ? renderProposal(data) : null,
            data.kind === 'proposal' ? p(a(
                {href: '/create'},
                icon('create'),
                ' Create another proposal'
            )) : null,
            div(
                {className: 'post__footer'},
                currentUserID === data.user_id ? a(
                    {href: `/topics/${topicId}/posts/${data.id}/update`},
                    icon('update'),
                    ' Edit'
                ) : a(
                    {href: `/topics/${topicId}/posts/create?` +
                           `replies_to_id=${data.id}`},
                    icon('reply'),
                    ' Reply'
                ),
                /* PP@ data.kind === 'proposal' ? a(
                    {href: `/topics/${topicId}/posts/create?` +
                           `replies_to_id=${data.id}&kind=vote`},
                    icon('vote'),
                    ' Vote'
                ) : null, */
                a(
                    {href: `/topics/${data.topicID}#${data.id}`},<commit_msg>Move link<commit_after>const {li, div, img, a, span, h3} = require('../../modules/tags')
const {timeAgo} = require('../../modules/auxiliaries')
const icon = require('./icon.tmpl')
const previewCard = require('./preview_card.tmpl')
const previewUnit = require('./preview_unit.tmpl')
const previewSubject = require('./preview_subject.tmpl')

const renderProposal = (data) => {
    if (!data.kind === 'proposal') { return }
    const entityVersions = data.entityVersionsFull || []
    return div(
        {className: 'post__proposal'},
        entityVersions.map((version) => {
            const {entityKind} = version
            if (entityKind === 'card') {
                return previewCard(Object.assign({}, version, {
                    unit: { name: version.unit_id },
                    requires: version.require_ids.map(id => ({id}))
                }))
            }
            if (entityKind === 'unit') {
                return previewUnit(Object.assign({}, version, {
                    requires: version.require_ids.map(id => ({id}))
                }))
            }
            if (entityKind === 'subject') {
                return previewSubject(version)
            }
            return null
        })
    )
}

const voteResponse = (response) => {
    if(!response) { return }
    return [
        span(
            {
                className: `post__vote--${response ? 'good' : 'bad'}`
            },
            icon(response ? 'good' : 'bad'),
            response ? ' Yes' : ' No'
        ),
        ' '
    ]
}

module.exports = (data, currentUserID) => {
    const topicId = data.topic_id
    return li(
        {
            id: data.id,
            className: 'post',
        },
        div(
            {className: 'post__avatar'},
            a(
                {href: `/users/${data.user_id}`},
                img({
                    src: data.user.avatar || '',
                    width: 48,
                    height: 48
                })
            )
        ),
        div(
            {className: 'post__content'},
            div({className: 'post__when'}, timeAgo(data.created)),
            a(
                {
                    className: 'post__name',
                    href: `/users/${data.user_id}`,
                },
                data.user.name || '???'
            ),
            div(
                data.replies_to_id ? a(
                    {
                        className: 'post__in-reply',
                        href: `/topics/${data.topic_id}#${data.replies_to_id}`
                    },
                    icon('reply'),
                    ' In Reply'
                ) : null,
                data.replies_to_id ? ' ' : null,
                data.kind === 'proposal' ? h3('Proposal: ' + data.name) : null,
                voteResponse(data.response),
                data.body
            ),
            data.kind === 'proposal' ? renderProposal(data) : null,
            div(
                {className: 'post__footer'},
                currentUserID === data.user_id ? a(
                    {href: `/topics/${topicId}/posts/${data.id}/update`},
                    icon('update'),
                    ' Edit'
                ) : a(
                    {href: `/topics/${topicId}/posts/create?` +
                           `replies_to_id=${data.id}`},
                    icon('reply'),
                    ' Reply'
                ),
                /* PP@ data.kind === 'proposal' ? a(
                    {href: `/topics/${topicId}/posts/create?` +
                           `replies_to_id=${data.id}&kind=vote`},
                    icon('vote'),
                    ' Vote'
                ) : null, */
                data.kind === 'proposal' ? a(
                    {href: '/create'},
                    icon('create'),
                    ' Create Another Proposal'
                ) : null,
                a(
                    {href: `/topics/${data.topicID}#${data.id}`},
{'fraction_non_alphanumeric': 0.1483862834089763, 'fraction_numerical': 0.0015128593040847202, 'mean_word_length': 1.1527815468113976, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1997579', 'n_tokens_mistral': 2189, 'n_tokens_neox': 2098, 'n_words': 373}