import { html, LitElement, css, TemplateResult } from 'lit'; import { Config } from './Config.js'; /* eslint-disable */ import { property } from 'lit/decorators.js'; /* eslint-enable */ export class HonorlockElementsElement extends LitElement { @property({ type: Config }) configs: Config[] = window.HonorlockElements.getConfigurations(); static styles = css` iframe { background-color: white; border: 0; } #error-wrapper { box-sizing: border-box; position: relative; max-width: 100%; width: 600px; height: 800px; background: #f7f8f9; box-shadow: 0 0 24px rgba(21, 38, 81, 0.15); font-family: 'Open Sans', sans-serif; } #error-wrapper * { box-sizing: inherit; } #error-header { height: 64px; background: #2272ce; display: flex; align-items: center; justify-content: center; } #error-header-honorlock-text { margin-left: 0.625rem; } #error-body { display: flex; flex-direction: column; align-items: flex-start; padding: 32px 32px 44px; gap: 8px; position: absolute; max-width: 100%; width: 344px; height: auto; left: 50%; top: 50%; transform: translate(-50%, -50%); background: #ffffff; box-shadow: 0 0 11px rgba(21, 38, 81, 0.05); border-radius: 8px; } #error-body-header { display: flex; align-items: center; justify-content: center; margin-left: auto; margin-right: auto; } #error-body-header h1 { margin: 0; font-style: normal; font-weight: 700; font-size: 48px; line-height: 64px; color: #282828; } #error-body-errors { display: flex; flex-direction: column; justify-content: center; align-items: flex-start; padding: 0; gap: 4px; } #error-body-errors-header { display: flex; align-items: center; text-align: center; margin-left: auto; margin-right: auto; margin-bottom: 4px; } #error-body-errors-header h2 { margin: 0; color: #282828; font-style: normal; font-weight: 600; font-size: 16px; line-height: 24px; } .error-list-wrapper { display: flex; align-items: center; justify-content: center; } .error-list-message { max-width: 90%; font-style: normal; font-weight: 400; font-size: 14px; line-height: 24px; margin-top: 0; margin-bottom: 0; margin-left: 12px; flex: none; order: 1; flex-grow: 0; align-items: center; color: #424242; } `; render() { const { key } = this.dataset; const { config } = this.configs.find( conf => conf.config.key === (key ?? 'default') ) as Config; const endPoint = `https://${config.host}/widget/launch`; const url = `${endPoint}/${config.context.type}/${ config.context.id }/?token=${config.token}&showHeader=${config.showHeader}&showLivechat=${ config.showLivechat }${ config.defaultSessionViewerOrientation ? `&defaultSessionViewerOrientation=${config.defaultSessionViewerOrientation}` : '' }`; const validation = window.HonorlockElements.getValidation(); const errorToDisplay = config.debug === true ? validation.errors : [ 'Honorlock is not configured correctly. Please contact your software integration administrator.', ]; if (validation.errors.length > 0) { return HonorlockElementsElement.renderTheErrorView(errorToDisplay); } return html` `; } private static renderTheErrorView(errors: Array): TemplateResult<1> { let list: string = ''; errors.forEach((item: string) => { list += `

${item}

`; }); const validationWrapper = document.createElement('div'); validationWrapper.id = 'error-body-errors'; validationWrapper.innerHTML = list; return html`

Oh no!

The Honorlock widget failed to load.

${validationWrapper}
`; } } declare global { interface Window { HonorlockElements: any; } }