import { h, F as Fragment, r as registerInstance, c as createEvent } from './index-CV0Pyo1O.js';
import { E as ErrorState } from './utils-CX6puxwf.js';
import { B as BusinessService } from './business.service-BpvtCKI5.js';
import { m as makeGetBusiness } from './get-business-C8F558a1.js';
import { C as ComponentErrorSeverity, b as ComponentErrorCodes } from './Plaid-DxSkT8pY.js';
import { J as JustifiAnalytics } from './Analytics-C76Y5Pqf.js';
import { c as checkPkgVersion } from './check-pkg-version-D5BxTNyL.js';
import { S as StyledHost } from './styled-host-D84RBv1W.js';
import './event-types-CZfYo5-1.js';
import { S as Skeleton } from './skeleton-BEHo2ypu.js';
import './parts-CPKMvyV_.js';
import './Api-BulOmiMS.js';
import './config-state-kKn89dp1.js';
import './index-cDVGjRkU.js';
import './utils-C25uIOK0.js';
import './dinero-HXpYMWUU.js';
import './Pagination-CLHwhyvu.js';
import './Business-BcNb9bVO.js';
import './utils-CVYvs2hZ.js';
import './package-CqcLgdsl.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 = class {
    constructor(hostRef) {
        registerInstance(this, hostRef);
        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"]
    }; }
};

export { JustifiBusinessDetails as justifi_business_details };
