// SPDX-FileCopyrightText: 2024 John Livingston // // SPDX-License-Identifier: AGPL-3.0-only // FIXME: @stylistic/indent is buggy with strings literrals. /* eslint-disable @stylistic/indent */ import type { ChannelConfigurationElement } from '../channel-configuration' import type { DynamicFormHeader, DynamicFormSchema } from '../../../lib/elements/dynamic-table-form' import { ptTr } from '../../../lib/directives/translation' import { html, TemplateResult } from 'lit' import { classMap } from 'lit/directives/class-map.js' export function tplChannelConfiguration (el: ChannelConfigurationElement): TemplateResult { const tableHeaderList: Record = { forbiddenWords: { entries: { colName: ptTr(LOC_LIVECHAT_CONFIGURATION_CHANNEL_FORBIDDEN_WORDS_LABEL), description: ptTr(LOC_LIVECHAT_CONFIGURATION_CHANNEL_FORBIDDEN_WORDS_DESC2) }, regexp: { colName: ptTr(LOC_LIVECHAT_CONFIGURATION_CHANNEL_FORBIDDEN_WORDS_REGEXP_LABEL), description: ptTr(LOC_LIVECHAT_CONFIGURATION_CHANNEL_FORBIDDEN_WORDS_REGEXP_DESC) }, applyToModerators: { colName: ptTr(LOC_LIVECHAT_CONFIGURATION_APPLYTOMODERATORS_LABEL), description: ptTr(LOC_LIVECHAT_CONFIGURATION_APPLYTOMODERATORS_DESC) }, label: { colName: ptTr(LOC_LIVECHAT_CONFIGURATION_CHANNEL_FORBIDDEN_WORDS_LABEL_LABEL), description: ptTr(LOC_LIVECHAT_CONFIGURATION_CHANNEL_FORBIDDEN_WORDS_LABEL_DESC) }, reason: { colName: ptTr(LOC_LIVECHAT_CONFIGURATION_CHANNEL_RETRACTATION_REASON_LABEL), description: ptTr(LOC_LIVECHAT_CONFIGURATION_CHANNEL_RETRACTATION_REASON_DESC) }, comments: { colName: ptTr(LOC_LIVECHAT_CONFIGURATION_CHANNEL_FORBIDDEN_WORDS_COMMENTS_LABEL), description: ptTr(LOC_LIVECHAT_CONFIGURATION_CHANNEL_FORBIDDEN_WORDS_COMMENTS_DESC) } }, quotes: { messages: { colName: ptTr(LOC_LIVECHAT_CONFIGURATION_CHANNEL_QUOTE_LABEL2), description: ptTr(LOC_LIVECHAT_CONFIGURATION_CHANNEL_QUOTE_DESC2) }, delay: { colName: ptTr(LOC_LIVECHAT_CONFIGURATION_CHANNEL_QUOTE_DELAY_LABEL), description: ptTr(LOC_LIVECHAT_CONFIGURATION_CHANNEL_QUOTE_DELAY_DESC) } }, commands: { command: { colName: ptTr(LOC_LIVECHAT_CONFIGURATION_CHANNEL_COMMAND_CMD_LABEL), description: ptTr(LOC_LIVECHAT_CONFIGURATION_CHANNEL_COMMAND_CMD_DESC) }, message: { colName: ptTr(LOC_LIVECHAT_CONFIGURATION_CHANNEL_COMMAND_MESSAGE_LABEL), description: ptTr(LOC_LIVECHAT_CONFIGURATION_CHANNEL_COMMAND_MESSAGE_DESC) } } } const tableSchema: Record = { forbiddenWords: { entries: { inputType: 'tags', default: [], separator: '\n' }, regexp: { inputType: 'checkbox', default: false }, applyToModerators: { inputType: 'checkbox', default: false }, label: { inputType: 'text', default: '' }, reason: { inputType: 'text', default: '' }, comments: { inputType: 'textarea', default: '' } }, quotes: { messages: { inputType: 'textarea', default: [], separator: '\n' }, delay: { inputType: 'number', default: 10 } }, commands: { command: { inputType: 'text', default: '' }, message: { inputType: 'text', default: '' } } } return html` ${el.channelConfiguration?.channel.displayName} ${el.channelConfiguration?.channel.name} ${ptTr(LOC_LIVECHAT_CONFIGURATION_CHANNEL_DESC)} { if (event?.target && el.channelConfiguration) { let value: string | undefined = (event.target as HTMLTextAreaElement).value if (value === '') { value = undefined } el.channelConfiguration.configuration.terms = value } el.requestUpdate('channelConfiguration') } } > ${el.renderFeedback('peertube-livechat-terms-feedback', 'terms')} { if (event?.target && el.channelConfiguration) { el.channelConfiguration.configuration.mute.anonymous = (event.target as HTMLInputElement).checked } el.requestUpdate('channelConfiguration') } } value="1" ?checked=${el.channelConfiguration?.configuration.mute.anonymous} /> ${ptTr(LOC_LIVECHAT_CONFIGURATION_CHANNEL_MUTE_ANONYMOUS_LABEL)} ${ptTr(LOC_LIVECHAT_CONFIGURATION_CHANNEL_SLOW_MODE_LABEL)} { if (event?.target && el.channelConfiguration) { el.channelConfiguration.configuration.slowMode.duration = Number((event.target as HTMLInputElement).value) } el.requestUpdate('channelConfiguration') } } value="${el.channelConfiguration?.configuration.slowMode.duration ?? ''}" /> ${el.renderFeedback('peertube-livechat-slowmode-duration-feedback', 'slowMode.duration')} ${ptTr(LOC_MODERATION_DELAY)} { if (event?.target && el.channelConfiguration) { el.channelConfiguration.configuration.moderation.delay = Number((event.target as HTMLInputElement).value) } el.requestUpdate('channelConfiguration') } } value="${el.channelConfiguration?.configuration.moderation.delay ?? ''}" /> ${el.renderFeedback('peertube-livechat-moderation-delay-feedback', 'moderation.delay')} { if (event?.target && el.channelConfiguration) { el.channelConfiguration.configuration.moderation.anonymize = (event.target as HTMLInputElement).checked } el.requestUpdate('channelConfiguration') } } value="1" ?checked=${el.channelConfiguration?.configuration.moderation.anonymize} /> ${ptTr(LOC_LIVECHAT_CONFIGURATION_CHANNEL_ANONYMIZE_MODERATION_LABEL)} { if (event?.target && el.channelConfiguration) { el.channelConfiguration.configuration.bot.enabled = (event.target as HTMLInputElement).checked } el.requestUpdate('channelConfiguration') } } value="1" ?checked=${el.channelConfiguration?.configuration.bot.enabled} /> ${ptTr(LOC_LIVECHAT_CONFIGURATION_CHANNEL_ENABLE_BOT_LABEL)} ${!el.channelConfiguration?.configuration.bot.enabled ? '' : html` ${ptTr(LOC_LIVECHAT_CONFIGURATION_CHANNEL_BOT_NICKNAME)} { if (event?.target && el.channelConfiguration) { el.channelConfiguration.configuration.bot.nickname = (event.target as HTMLInputElement).value } el.requestUpdate('channelConfiguration') } } value="${el.channelConfiguration?.configuration.bot.nickname ?? ''}" /> ${el.renderFeedback('peertube-livechat-bot-nickname-feedback', 'bot.nickname')} { if (event?.target && el.channelConfiguration) { el.channelConfiguration.configuration.bot.forbidSpecialChars.enabled = (event.target as HTMLInputElement).checked } el.requestUpdate('channelConfiguration') } } value="1" ?checked=${el.channelConfiguration?.configuration.bot.forbidSpecialChars.enabled} /> ${ptTr(LOC_LIVECHAT_CONFIGURATION_CHANNEL_SPECIAL_CHARS_LABEL)} ${!el.channelConfiguration?.configuration.bot.forbidSpecialChars.enabled ? '' : html` ${ptTr(LOC_LIVECHAT_CONFIGURATION_CHANNEL_SPECIAL_CHARS_TOLERANCE_LABEL)} { if (event?.target && el.channelConfiguration) { el.channelConfiguration.configuration.bot.forbidSpecialChars.tolerance = Number((event.target as HTMLInputElement).value) } el.requestUpdate('channelConfiguration') } } value="${el.channelConfiguration?.configuration.bot.forbidSpecialChars.tolerance ?? '0'}" /> ${ptTr(LOC_LIVECHAT_CONFIGURATION_CHANNEL_SPECIAL_CHARS_TOLERANCE_DESC)} ${el.renderFeedback('peertube-livechat-forbid-special-chars-tolerance-feedback', 'bot.forbidSpecialChars.tolerance') } ${ptTr(LOC_LIVECHAT_CONFIGURATION_CHANNEL_RETRACTATION_REASON_LABEL)} { if (event?.target && el.channelConfiguration) { el.channelConfiguration.configuration.bot.forbidSpecialChars.reason = (event.target as HTMLInputElement).value } el.requestUpdate('channelConfiguration') } } value="${el.channelConfiguration?.configuration.bot.forbidSpecialChars.reason ?? ''}" /> ${ptTr(LOC_LIVECHAT_CONFIGURATION_CHANNEL_RETRACTATION_REASON_DESC)} ${el.renderFeedback('peertube-livechat-forbid-special-chars-reason-feedback', 'bot.forbidSpecialChars.reason') } { if (event?.target && el.channelConfiguration) { el.channelConfiguration.configuration.bot.forbidSpecialChars.applyToModerators = (event.target as HTMLInputElement).checked } el.requestUpdate('channelConfiguration') } } value="1" ?checked=${el.channelConfiguration?.configuration.bot.forbidSpecialChars.applyToModerators} /> ${ptTr(LOC_LIVECHAT_CONFIGURATION_APPLYTOMODERATORS_LABEL)} ${ptTr(LOC_LIVECHAT_CONFIGURATION_APPLYTOMODERATORS_DESC)} ` } { el.resetValidation(e) if (el.channelConfiguration) { el.channelConfiguration.configuration.bot.forbiddenWords = e.detail el.requestUpdate('channelConfiguration') } } } .formName=${'forbidden-words'} > { el.resetValidation(e) if (el.channelConfiguration) { el.channelConfiguration.configuration.bot.quotes = e.detail el.requestUpdate('channelConfiguration') } } } .formName=${'quote'} > { el.resetValidation(e) if (el.channelConfiguration) { el.channelConfiguration.configuration.bot.commands = e.detail el.requestUpdate('channelConfiguration') } } } .formName=${'command'} > `} ${ptTr(LOC_CANCEL)} ${ptTr(LOC_SAVE)} ` }
${ptTr(LOC_LIVECHAT_CONFIGURATION_CHANNEL_DESC)}