// SPDX-FileCopyrightText: 2024 John Livingston // // SPDX-License-Identifier: AGPL-3.0-only import { html } from 'lit' import { repeat } from 'lit/directives/repeat.js' import { __ } from 'i18n' function _tplPollInstructions (el, currentPoll) { if (currentPoll.over) { return html`` } // eslint-disable-next-line no-undef const i18nPollInstructions = __(LOC_poll_vote_instructions) return html`

${i18nPollInstructions}

` } function _tplPollEnd (el, currentPoll) { if (!currentPoll.endDate) { return html`` } // eslint-disable-next-line no-undef const i18nPollEnd = __(LOC_poll_end) return html`

${i18nPollEnd} ${currentPoll.endDate.toLocaleString()}

` } function _tplChoice (el, currentPoll, choice) { // eslint-disable-next-line no-undef const i18nChoiceN = __(LOC_poll_choice_n).replace('{{N}}', choice.choice) const votes = choice.votes const totalVotes = currentPoll.votes const percent = totalVotes ? (100 * votes / totalVotes).toFixed(2) : '0.00' return html` ${ currentPoll.over ? html`${i18nChoiceN}` : html` ` } ${choice.label}

${votes}/${totalVotes} (${percent}%)

` } export function tplPoll (el, currentPoll) { if (!currentPoll) { return html`` } return html`

${currentPoll.over ? html`` : '' } ${el.collapsed ? html` ` : html` ` } ${currentPoll.question}

${ el.collapsed ? '' : html` ${repeat(currentPoll.choices ?? [], (c) => c.choice, (c) => _tplChoice(el, currentPoll, c))}
${_tplPollInstructions(el, currentPoll)} ${_tplPollEnd(el, currentPoll)} ` }
` }