import{h,Host}from"@stencil/core";import{state as errorState}from"../../../../store/notices/index";import{getAdditionalErrorMessages}from"../../../../store/notices/getters";import{currentFormState}from"../../../../store/form/getters";import{onChange}from"../../../../store/form/index";import{removeNotice}from"../../../../store/notices/mutations";export class ScCheckoutFormErrors{constructor(){this.removeStateListener=()=>{}}getAlertType(){switch(null==errorState?void 0:errorState.type){case"error":return"danger";case"default":return"primary";default:return null==errorState?void 0:errorState.type}}componentWillLoad(){this.removeStateListener=onChange("formState",(()=>{["finalizing","updating"].includes(currentFormState())&&removeNotice()}))}disconnectedCallback(){this.removeStateListener()}getTopLevelError(){var e;return"checkout.invalid"===(null==errorState?void 0:errorState.code)&&(null===(e=getAdditionalErrorMessages())||void 0===e?void 0:e.length)?"":null==errorState?void 0:errorState.message}render(){return!(null==errorState?void 0:errorState.message)||["finalizing","updating"].includes(currentFormState())?h(Host,{style:{display:"none"}}):h(Host,null,h("sc-alert",{type:this.getAlertType(),scrollOnOpen:!0,open:!!(null==errorState?void 0:errorState.message),closable:!!(null==errorState?void 0:errorState.dismissible)},!!this.getTopLevelError()&&h("span",{slot:"title",innerHTML:this.getTopLevelError()}),(getAdditionalErrorMessages()||[]).map(((e,r)=>h("div",{innerHTML:e,key:r})))),h("slot",null))}static get is(){return"sc-checkout-form-errors"}static get encapsulation(){return"shadow"}static get originalStyleUrls(){return{$:["sc-checkout-form-errors.scss"]}}static get styleUrls(){return{$:["sc-checkout-form-errors.css"]}}}