| 
									
										
										
										
											2023-10-23 16:13:02 +02:00
										 |  |  | import { | 
					
						
							|  |  |  |   customElement, | 
					
						
							|  |  |  |   type TemplateResult, | 
					
						
							|  |  |  |   state, | 
					
						
							|  |  |  |   html, | 
					
						
							|  |  |  |   property, | 
					
						
							| 
									
										
										
										
											2025-06-19 11:39:16 +00:00
										 |  |  |   css, | 
					
						
							|  |  |  |   cssManager, | 
					
						
							| 
									
										
										
										
											2023-10-23 16:13:02 +02:00
										 |  |  | } from '@design.estate/dees-element'; | 
					
						
							| 
									
										
										
										
											2025-06-19 11:39:16 +00:00
										 |  |  | import * as domtools from '@design.estate/dees-domtools'; | 
					
						
							|  |  |  | import { DeesInputBase } from './dees-input-base.js'; | 
					
						
							| 
									
										
										
										
											2023-10-23 16:13:02 +02:00
										 |  |  | import * as ibantools from 'ibantools'; | 
					
						
							|  |  |  | import { demoFunc } from './dees-input-iban.demo.js'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @customElement('dees-input-iban') | 
					
						
							| 
									
										
										
										
											2025-06-19 11:39:16 +00:00
										 |  |  | export class DeesInputIban extends DeesInputBase<DeesInputIban> { | 
					
						
							| 
									
										
										
										
											2023-10-23 16:13:02 +02:00
										 |  |  |   // STATIC
 | 
					
						
							|  |  |  |   public static demo = demoFunc; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // INSTANCE
 | 
					
						
							|  |  |  |   @state() | 
					
						
							|  |  |  |   enteredString: string = ''; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   @state() | 
					
						
							|  |  |  |   enteredIbanIsValid: boolean = false; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   @property({ | 
					
						
							|  |  |  |     type: String, | 
					
						
							|  |  |  |   }) | 
					
						
							|  |  |  |   public value = ''; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-06-19 11:39:16 +00:00
										 |  |  |   public static styles = [ | 
					
						
							|  |  |  |     ...DeesInputBase.baseStyles, | 
					
						
							|  |  |  |     cssManager.defaultStyles, | 
					
						
							|  |  |  |     css`
 | 
					
						
							|  |  |  |       /* IBAN input specific styles can go here */ | 
					
						
							|  |  |  |     `,
 | 
					
						
							|  |  |  |   ]; | 
					
						
							| 
									
										
										
										
											2023-10-23 16:13:02 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   public render(): TemplateResult { | 
					
						
							|  |  |  |     return html`
 | 
					
						
							| 
									
										
										
										
											2025-06-19 11:39:16 +00:00
										 |  |  |       <div class="input-wrapper"> | 
					
						
							|  |  |  |         <dees-label .label=${this.label || 'IBAN'} .description=${this.description}></dees-label> | 
					
						
							|  |  |  |         <dees-input-text | 
					
						
							|  |  |  |           .value=${this.value} | 
					
						
							|  |  |  |           .disabled=${this.disabled} | 
					
						
							|  |  |  |           .required=${this.required} | 
					
						
							|  |  |  |           .placeholder=${'DE89 3704 0044 0532 0130 00'} | 
					
						
							|  |  |  |           @input=${(eventArg: InputEvent) => { | 
					
						
							|  |  |  |             this.validateIban(eventArg); | 
					
						
							|  |  |  |           }} | 
					
						
							|  |  |  |         ></dees-input-text> | 
					
						
							|  |  |  |       </div> | 
					
						
							| 
									
										
										
										
											2023-10-23 16:13:02 +02:00
										 |  |  |     `;
 | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-06-19 11:39:16 +00:00
										 |  |  |   public firstUpdated(_changedProperties: Map<string | number | symbol, unknown>) { | 
					
						
							|  |  |  |     super.firstUpdated(_changedProperties); | 
					
						
							|  |  |  |     const deesInputText = this.shadowRoot.querySelector('dees-input-text') as any; | 
					
						
							|  |  |  |     if (deesInputText && deesInputText.changeSubject) { | 
					
						
							|  |  |  |       deesInputText.changeSubject.subscribe(() => { | 
					
						
							|  |  |  |         this.changeSubject.next(this); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2023-10-23 16:13:02 +02:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   public async validateIban(eventArg: InputEvent): Promise<void> { | 
					
						
							|  |  |  |     const inputElement: HTMLInputElement = eventArg.target as HTMLInputElement; | 
					
						
							|  |  |  |     let enteredString = inputElement?.value; | 
					
						
							|  |  |  |     enteredString = enteredString || ''; | 
					
						
							|  |  |  |     if (this.enteredString !== enteredString) { | 
					
						
							|  |  |  |       this.enteredString = ibantools.friendlyFormatIBAN(enteredString) || ''; | 
					
						
							|  |  |  |       if (inputElement) { | 
					
						
							|  |  |  |         inputElement.value = this.enteredString; | 
					
						
							|  |  |  |         this.value = this.enteredString; | 
					
						
							|  |  |  |         this.changeSubject.next(this); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     this.enteredIbanIsValid = ibantools.isValidIBAN(this.enteredString.replace(/ /g, '')); | 
					
						
							|  |  |  |     const deesInputText = this.shadowRoot.querySelector('dees-input-text'); | 
					
						
							|  |  |  |     deesInputText.validationText = `IBAN is valid: ${this.enteredIbanIsValid}`; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2025-06-19 11:39:16 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   public getValue(): string { | 
					
						
							|  |  |  |     return this.value; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   public setValue(value: string): void { | 
					
						
							|  |  |  |     this.value = value; | 
					
						
							|  |  |  |     this.enteredString = ibantools.friendlyFormatIBAN(value) || ''; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2023-10-23 16:13:02 +02:00
										 |  |  | } |