import { css, html } from 'lit' import { property } from 'lit/decorators.js' import { when } from 'lit/directives/when.js' import { UsBaseElement } from '../base/UsBaseElement' import { customElementIfNotExist } from '../../utils/customElementIfNotExist' import { localizeManager, localized } from '../../dependencies' import { dispatchCustomEvent } from '../../utils/dispatchCustomEvent' import type { IFeedbackReason } from './model/IFeedbackReason' import type { IFeedbackReasonSendEvent } from './model/IFeedbackReasonSendEvent' import style_css from './styles.pcss' import '../popup/UsPopup' import '../loader/UsLoader' import '../footer/UsFooter' import '../form/input/UsInput' declare global { interface HTMLElementTagNameMap { 'us-feedback-popup': USFeedbackPopup } } @customElementIfNotExist('us-feedback-popup') @localized() export class USFeedbackPopup extends UsBaseElement { static styles = [ UsBaseElement.styles, css([style_css] as TemplateStringsArray | any), ] @property({ type: Array }) reasons: IFeedbackReason[] = [] @property({ type: String }) reasonText = '' @property({ type: String }) description = '' @property({ type: String }) reasonLabel = '' @property({ type: Boolean }) loading = false @property({ type: Boolean }) overlay = false @property({ type: Boolean }) transparent = false @property({ type: Boolean }) show = false @property({ type: Boolean }) showReasonText = false @property({ type: String }) headerTitle = '' maxReasonTextLength = 800 render() { return html`
${when(this.loading, () => html` `, () => html` `)}
${when(!this.loading, () => html` `)}
` } renderReasons() { return html`
${this.reasons.map(checkbox => html` `)}
` } handleReasonCheckboxChange({ target }) { const id = target.checkboxSettings.id || target.renderRoot.activeElement.id this.reasons = this.reasons.map((item) => { if (item.id === id) item.checked = target.checked return item }) const chengedReason = this.reasons.find(reason => reason.id) dispatchCustomEvent('changedReason', chengedReason, this, false, false) } handleDescriptionInput(event: InputEvent) { const target = event.target as HTMLInputElement this.reasonText = target.value } isSendButtonDisabled(): boolean { return !this.reasons.some(reason => reason.checked) || (this.showReasonText && this.reasonText.length > this.maxReasonTextLength) } handleClose() { this.reasonText = '' dispatchCustomEvent('close', true, this, false, false) } handleSend() { const message: IFeedbackReasonSendEvent = { selectedReasons: this.reasons.filter(reason => reason.checked), reasonText: this.reasonText, } this.reasonText = '' dispatchCustomEvent('send', message, this, false, false) } }