import { css, html } from 'lit' import { property } from 'lit/decorators.js' import type { DirectiveClass, DirectiveResult } from 'lit/directive' import { classMap } from 'lit/directives/class-map.js' import { when } from 'lit/directives/when.js' import { customElementIfNotExist } from '../../utils/customElementIfNotExist' import { dispatchCustomEvent } from '../../utils/dispatchCustomEvent' import { UsBaseElement } from '../base/UsBaseElement' import { getWidgetViewClasses } from '../../utils/getWidgetViewClasses' import { redispatchEvent } from '../../upswot-components' import type { IDetailedInfo } from './models/IDetailedInfo' import UsDetailedInfo_css from './detailedInfo.pcss' import './detailedCard/DetailedCard' import './detailedList/DetailedList' import './detailedActions/DetailedActions' import '../popup/UsPopup' import '../loader/UsLoader' import '../../layouts/scrollLayout/ScrollLayout' import '../form/switch/UsSwitch' import '../button/UsButton' declare global { interface HTMLElementTagNameMap { 'us-detailed-info': UsDetailedInfo } } @customElementIfNotExist('us-detailed-info') export class UsDetailedInfo extends UsBaseElement implements IDetailedInfo { static styles = [ UsBaseElement.styles, css([UsDetailedInfo_css] as TemplateStringsArray | any), ] @property({ type: Boolean }) readonly = false @property({ type: Object }) detailedInfo: IDetailedInfo['detailedInfo'] = null @property({ type: String }) widgetView: IDetailedInfo['widgetView'] = 'vertical' @property({ type: String }) popupTitle: IDetailedInfo['popupTitle'] = '' @property({ type: Boolean }) isPopupShow: IDetailedInfo['isPopupShow'] = false @property({ type: Boolean }) isLoading: IDetailedInfo['isLoading'] = false get isIgnored(): boolean { if (this.detailedInfo && this.detailedInfo.actions) { const { ignore, active } = this.detailedInfo.actions const actionIgnoreState = (ignore && ignore.state) ?? false const actionActiveState = (active && active.state) ?? true return actionIgnoreState || !actionActiveState } return false } render() { return html`
${when(this.isLoading, () => html`
`, () => this.renderWrapperBlock())}
` } getDetailedInfoClasses(): DirectiveResult { const widgetViewClasses = getWidgetViewClasses(this.widgetView) return classMap({ 'detailed-info': true, ...widgetViewClasses, }) } renderWrapperBlock() { if (this.isVerticalOrHorizontalSmall()) { return html`
${this.renderDetailedCardBlock()}
${this.renderDetailedListBlock()}
${this.renderDetailedActionsBlock()}
` } else { return html`
${this.renderDetailedCardBlock()}
${this.renderDetailedListBlock()}
${this.renderDetailedActionsBlock()}
` } } renderDetailedCardBlock() { if (!this.detailedInfo) return null return html` ` } renderDetailedListBlock() { if (!this.detailedInfo) return null return html` ` } renderDetailedActionsBlock() { if (!this.detailedInfo || !this.detailedInfo.actions) return null return html` ` } handleAction(e: Event) { redispatchEvent(this, e) } isVerticalOrHorizontalSmall() { return this.widgetView.includes('vertical') || this.widgetView.includes('horizontal-small') } handlePopupHide() { dispatchCustomEvent('back', null, this, false, false) } }