import { h, Fragment, proxyCustomElement, HTMLElement, createEvent } from '@stencil/core/internal/client';
import { E as ErrorState } from './utils.js';
import { B as BusinessService } from './business.service.js';
import { m as makeGetBusiness } from './get-business.js';
import { C as ComponentErrorSeverity, a as ComponentErrorCodes } from './Plaid.js';
import { J as JustifiAnalytics } from './Analytics.js';
import { c as checkPkgVersion } from './check-pkg-version.js';
import { S as StyledHost } from './styled-host.js';
import { d as defineCustomElement$5 } from './justifi-details2.js';
import './event-types.js';
import './justifi-radio-list-item2.js';
import { S as Skeleton } from './skeleton.js';
import { d as defineCustomElement$7 } from './additional-questions-details2.js';
import { d as defineCustomElement$6 } from './core-info-details2.js';
import { d as defineCustomElement$4 } from './legal-address-details2.js';
import { d as defineCustomElement$3 } from './owner-details2.js';
import { d as defineCustomElement$2 } from './representative-details2.js';

const BusinessDetailsLoading = () => {
    const Block = () => (h("div", { class: "mt-5" }, h(Skeleton, { width: "40%", height: "1.5rem" }), h("hr", null), h("div", { class: "row g-3" }, h("div", { class: "col-12 col-md-6" }, h(Skeleton, null), h(Skeleton, null), h(Skeleton, null)), h("div", { class: "col-12 col-md-6" }, h(Skeleton, null), h(Skeleton, null), h(Skeleton, null)))));
    return (h(Fragment, null, h(Block, null), h(Block, null), h(Block, null), h(Block, null)));
};

const JustifiBusinessDetails$1 = /*@__PURE__*/ proxyCustomElement(class JustifiBusinessDetails extends HTMLElement {
    constructor(registerHost) {
        super();
        if (registerHost !== false) {
            this.__registerHost();
        }
        this.__attachShadow();
        this.errorEvent = createEvent(this, "error-event", 7);
        this.loading = true;
    }
    componentWillLoad() {
        checkPkgVersion();
        this.analytics = new JustifiAnalytics(this);
        this.initializeGetBusiness();
    }
    disconnectedCallback() {
        var _a;
        (_a = this.analytics) === null || _a === void 0 ? void 0 : _a.cleanup();
    }
    ;
    propChanged() {
        this.initializeGetBusiness();
    }
    initializeGetBusiness() {
        if (this.businessId && this.authToken) {
            this.getBusiness = makeGetBusiness({
                id: this.businessId,
                authToken: this.authToken,
                service: new BusinessService(),
            });
            this.fetchData();
        }
        else {
            this.errorMessage = 'Invalid business id or auth token';
            this.errorEvent.emit({
                errorCode: ComponentErrorCodes.MISSING_PROPS,
                message: this.errorMessage,
                severity: ComponentErrorSeverity.ERROR,
            });
        }
    }
    updateOnPropChange() {
        if (this.getBusiness) {
            this.fetchData();
        }
    }
    fetchData() {
        this.loading = true;
        this.getBusiness({
            onSuccess: ({ business }) => {
                this.business = business;
                this.errorMessage = null;
            },
            onError: ({ error, code, severity }) => {
                this.errorMessage = error;
                this.errorEvent.emit({
                    errorCode: code,
                    message: error,
                    severity,
                });
            },
            final: () => {
                this.loading = false;
            },
        });
    }
    render() {
        return (h(StyledHost, { key: '7ce48e6905cdbbf8f94470913ecfa3ef8dbb76c7' }, this.loading && h(BusinessDetailsLoading, { key: '7c3439e0c247436cd7951d3bdc32e7672c9f8447' }), !this.loading && this.errorMessage && ErrorState(this.errorMessage), !this.loading && !this.errorMessage && this.business && (h("justifi-details", { key: 'bf57dacf2067f2704014ce3e002958e3306bba73', errorMessage: this.errorMessage }, h("div", { key: '46d19a178ba0d33aa21a4f3900128e3e905731a9', slot: 'detail-sections' }, h("core-info-details", { key: 'ac217a4cfe6b45810a85ca320760b7331f76e60b', business: this.business }), h("legal-address-details", { key: '1fc1a196a43bcf5f9eafd09bfe74c8bb7c409797', legalAddress: this.business.legal_address }), h("representative-details", { key: '1e0833606b129f69a05946726172963cbec05189', representative: this.business.representative }), h("owner-details", { key: 'c974111dc67a8961ef6435c34843ca927ad8a7e5', owners: this.business.owners }), h("additional-questions-details", { key: '0951d284a373457e98a1dafc80231ec3ee057e0a', additionalQuestions: this.business.additional_questions }))))));
    }
    static get watchers() { return {
        "businessId": ["propChanged"],
        "authToken": ["propChanged"],
        "getBusiness": ["updateOnPropChange"]
    }; }
}, [257, "justifi-business-details", {
        "businessId": [1, "business-id"],
        "authToken": [1, "auth-token"],
        "getBusiness": [32],
        "business": [32],
        "loading": [32],
        "errorMessage": [32]
    }, undefined, {
        "businessId": ["propChanged"],
        "authToken": ["propChanged"],
        "getBusiness": ["updateOnPropChange"]
    }]);
function defineCustomElement$1() {
    if (typeof customElements === "undefined") {
        return;
    }
    const components = ["justifi-business-details", "additional-questions-details", "core-info-details", "justifi-details", "legal-address-details", "owner-details", "representative-details"];
    components.forEach(tagName => { switch (tagName) {
        case "justifi-business-details":
            if (!customElements.get(tagName)) {
                customElements.define(tagName, JustifiBusinessDetails$1);
            }
            break;
        case "additional-questions-details":
            if (!customElements.get(tagName)) {
                defineCustomElement$7();
            }
            break;
        case "core-info-details":
            if (!customElements.get(tagName)) {
                defineCustomElement$6();
            }
            break;
        case "justifi-details":
            if (!customElements.get(tagName)) {
                defineCustomElement$5();
            }
            break;
        case "legal-address-details":
            if (!customElements.get(tagName)) {
                defineCustomElement$4();
            }
            break;
        case "owner-details":
            if (!customElements.get(tagName)) {
                defineCustomElement$3();
            }
            break;
        case "representative-details":
            if (!customElements.get(tagName)) {
                defineCustomElement$2();
            }
            break;
    } });
}
defineCustomElement$1();

const JustifiBusinessDetails = JustifiBusinessDetails$1;
const defineCustomElement = defineCustomElement$1;

export { JustifiBusinessDetails, defineCustomElement };
