import { h } from "@stencil/core";
import { checkPkgVersion } from "../../../utils/check-pkg-version";
import JustifiAnalytics from "../../../api/Analytics";
import { waitForConfig } from "../../config-provider/config-state";
import { StyledHost } from "../../../ui-components";
export class JustifiBankAccountForm {
    async componentWillLoad() {
        await waitForConfig();
        checkPkgVersion();
        this.analytics = new JustifiAnalytics(this);
    }
    disconnectedCallback() {
        var _a;
        (_a = this.analytics) === null || _a === void 0 ? void 0 : _a.cleanup();
    }
    async validate() {
        if (!this.bankAccountFormElement) {
            return false;
        }
        return this.bankAccountFormElement.validate();
    }
    async tokenize({ clientId, paymentMethodMetadata, account }) {
        if (!this.bankAccountFormElement) {
            return {
                error: {
                    message: 'Bank account form is not available.',
                },
            };
        }
        return this.bankAccountFormElement.tokenize({ clientId, paymentMethodMetadata, account });
    }
    render() {
        return (h(StyledHost, { key: '3c8a48f6060f14433ae94399fc48097cb138e301' }, h("bank-account-form", { key: '30cd40b60629f5c7f874194dd7641ee3737e8b69', ref: (el) => (this.bankAccountFormElement = el) })));
    }
    static get is() { return "justifi-bank-account-form"; }
    static get encapsulation() { return "shadow"; }
    static get methods() {
        return {
            "validate": {
                "complexType": {
                    "signature": "() => Promise<any>",
                    "parameters": [],
                    "references": {
                        "Promise": {
                            "location": "global",
                            "id": "global::Promise"
                        }
                    },
                    "return": "Promise<any>"
                },
                "docs": {
                    "text": "",
                    "tags": []
                }
            },
            "tokenize": {
                "complexType": {
                    "signature": "({ clientId, paymentMethodMetadata, account }: { clientId: string; paymentMethodMetadata: any; account?: string; }) => Promise<any>",
                    "parameters": [{
                            "name": "__0",
                            "type": "{ clientId: string; paymentMethodMetadata: any; account?: string; }",
                            "docs": ""
                        }],
                    "references": {
                        "Promise": {
                            "location": "global",
                            "id": "global::Promise"
                        }
                    },
                    "return": "Promise<any>"
                },
                "docs": {
                    "text": "",
                    "tags": []
                }
            }
        };
    }
}
