import { LitElement, css, html } from 'lit' import { property, query, state } from 'lit/decorators.js' import type { DirectiveResult } from 'lit/directive' import type { ClassMapDirective } from 'lit/directives/class-map.js' import { classMap } from 'lit/directives/class-map.js' import { ifDefined } from 'lit/directives/if-defined.js' import { when } from 'lit/directives/when.js' import { localizeManager, localized } from '../../dependencies' import { customElementIfNotExist } from '../../utils/customElementIfNotExist' import { UsBaseElement } from '../base/UsBaseElement' import { ETextVariant } from './model/ETextVariant' import type { IPolicyProp } from './model/IPolicyProp' import type { TTextAlign } from './model/TTextAlign' import UsPolicy_css from './policy.pcss' import '../popup/UsPopup' declare global { interface HTMLElementTagNameMap { 'us-policy': UsPolicy } } @customElementIfNotExist('us-policy') @localized() export class UsPolicy extends LitElement implements IPolicyProp { static styles = [ UsBaseElement.styles, css([UsPolicy_css] as TemplateStringsArray | any), ] @property() textVariant = ETextVariant.DEFAULT @property() textAlign: TTextAlign = 'center' @property() buttonName = localizeManager.next() @property() url!: string @property() policy!: string @property() terms!: string @property({ type: Boolean }) openInPopup = false @property() popupWidth = '320px' @property() popupMaxHeight = '320px' @property({ type: Boolean }) inline = true @property({ type: String, attribute: 'data-testid', reflect: true }) dataTestId = 'policy' @state() modalName: 'policy' | 'terms' = 'policy' @state() showPopup = false @query('slot[name=popup]') slotPopup!: HTMLSlotElement render() { const linkToPolicy = this.policy || this.url const linkToTerms = this.terms || this.url const policyElement = this.getLinkElement('policy', linkToPolicy) const termsElement = this.getLinkElement('terms', linkToTerms) return html`