import { v4 as uuidv4 } from "uuid"; import defineComponentProperties from "./defineComponentProperties"; import kebabToCamelCase from "./kebabToCamelCase"; /* A read-only component that displays issued card data to the user */ class IssuedCard extends HTMLElement { static observedAttributes = ['oauth-token', 'account-id', 'issued-card-id']; static componentProps = ['oauthToken', 'accountID', 'issuedCardID']; private _drop: any; [key: string]: any; constructor() { super(); } handleMoovDropsInitialized = () => { if (!this.id) this.id = `moov-issued-card-${uuidv4()}`; if (!this.imperativeRef) this.imperativeRef = { current: null as any }; const initialPropValues = {} as Record; IssuedCard.componentProps.forEach((propName) => { if (propName in this) initialPropValues[propName] = this[propName]; }); const dropObject = window.drops.issuedCard(initialPropValues, this.id); this._drop = dropObject; } handleMoovJsLoaded = () => { document.removeEventListener("moov.moovJSLoaded", this.handleMoovJSLoaded); if (window.Moov && !window.drops) window.Moov("fake-token").drops().then(this.handleMoovDropsInitialized); } connectedCallback() { if (window.drops) this.handleMoovDropsInitialized(); if (window.Moov && !window.drops) this.handleMoovJsLoaded(); if (!window.Moov && !window.drops) document.addEventListener("moov.moovJSLoaded", this.handleMoovJsLoaded); } /** Callback fired when an observed attribute changes value */ attributeChangedCallback(name: string, oldValue: string, newValue: string) { if (oldValue === newValue) return; let propertyName = kebabToCamelCase(name); if (name === "account-id") propertyName = "accountID"; if (name === "issued-card-id") propertyName = "issuedCardID"; if (propertyName in this) this[propertyName] = newValue; } } defineComponentProperties(IssuedCard, IssuedCard.componentProps); export default IssuedCard;