import type { TemplateResult } from 'lit' import { css, html, nothing } from 'lit' import { property } from 'lit/decorators.js' import { when } from 'lit/directives/when.js' import { customElementIfNotExist } from '../../../utils/customElementIfNotExist' import { UsBaseElement } from '../../base/UsBaseElement' import { ActionTypes } from '../models/IDetailedActions' import type { IAction, IDetailedActions } from '../models/IDetailedActions' import { localizeManager } from '../../../dependencies' import { dispatchCustomEvent } from '../../../upswot-components' import UsDetailedActions_css from './detailedActions.pcss' declare global { interface HTMLElementTagNameMap { 'us-detailed-actions': UsDetailedActions } } @customElementIfNotExist('us-detailed-actions') export class UsDetailedActions extends UsBaseElement { static styles = [ UsBaseElement.styles, css([UsDetailedActions_css] as TemplateStringsArray | any), ] @property({ type: String }) widgetView = '' @property({ type: Boolean }) readonly = false @property({ type: Boolean }) disabled = false @property({ type: Object }) actions: IDetailedActions = {} as IDetailedActions defaultActionsStates: IDetailedActions = { active: { state: false, display: false, disabled: false }, ignore: { state: false, display: false, disabled: false }, delete: { display: false, disabled: false }, edit: { display: false, disabled: false }, } render() { if (!this.actions) return null const actionsProps: IDetailedActions = { ...this.defaultActionsStates, ...this.actions } const actions: (symbol | TemplateResult<1>)[] = [] // The render order of actions is set in enum (ActionTypes) Object.values(ActionTypes).forEach((actionType: ActionTypes) => { const action = actionsProps[actionType] as IAction actions.push(this.renderAction(action, actionType)) }) return html`
${description}