'use strict';

var index = require('./index-p7cvUYAE.js');
var utils = require('./utils-8RGQVADu.js');
var business_service = require('./business.service-BIHpEqmf.js');
var getBusiness = require('./get-business-DaaeRffw.js');
var Plaid = require('./Plaid-CPESyiiV.js');
var Analytics = require('./Analytics-C6KBHEIP.js');
var checkPkgVersion = require('./check-pkg-version-B9EoYyZR.js');
var styledHost = require('./styled-host-Ch0-dxF-.js');
require('./event-types-YOY5TKUN.js');
var skeleton = require('./skeleton-DvRCiQlA.js');
require('./parts-BXshb_S-.js');
require('./Api-D9vOcUw4.js');
require('./config-state-BIgGhhe9.js');
require('./index-W-zoNiyM.js');
require('./utils-CYONRFR6.js');
require('./dinero-BwNN_k7x.js');
require('./Pagination-Dediz133.js');
require('./Business-oBifyXkW.js');
require('./utils-BsnepLy6.js');
require('./package-YyJzVqrh.js');

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

const JustifiBusinessDetails = class {
    constructor(hostRef) {
        index.registerInstance(this, hostRef);
        this.errorEvent = index.createEvent(this, "error-event", 7);
        this.loading = true;
    }
    componentWillLoad() {
        checkPkgVersion.checkPkgVersion();
        this.analytics = new Analytics.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 = getBusiness.makeGetBusiness({
                id: this.businessId,
                authToken: this.authToken,
                service: new business_service.BusinessService(),
            });
            this.fetchData();
        }
        else {
            this.errorMessage = 'Invalid business id or auth token';
            this.errorEvent.emit({
                errorCode: Plaid.ComponentErrorCodes.MISSING_PROPS,
                message: this.errorMessage,
                severity: Plaid.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 (index.h(styledHost.StyledHost, { key: '7ce48e6905cdbbf8f94470913ecfa3ef8dbb76c7' }, this.loading && index.h(BusinessDetailsLoading, { key: '7c3439e0c247436cd7951d3bdc32e7672c9f8447' }), !this.loading && this.errorMessage && utils.ErrorState(this.errorMessage), !this.loading && !this.errorMessage && this.business && (index.h("justifi-details", { key: 'bf57dacf2067f2704014ce3e002958e3306bba73', errorMessage: this.errorMessage }, index.h("div", { key: '46d19a178ba0d33aa21a4f3900128e3e905731a9', slot: 'detail-sections' }, index.h("core-info-details", { key: 'ac217a4cfe6b45810a85ca320760b7331f76e60b', business: this.business }), index.h("legal-address-details", { key: '1fc1a196a43bcf5f9eafd09bfe74c8bb7c409797', legalAddress: this.business.legal_address }), index.h("representative-details", { key: '1e0833606b129f69a05946726172963cbec05189', representative: this.business.representative }), index.h("owner-details", { key: 'c974111dc67a8961ef6435c34843ca927ad8a7e5', owners: this.business.owners }), index.h("additional-questions-details", { key: '0951d284a373457e98a1dafc80231ec3ee057e0a', additionalQuestions: this.business.additional_questions }))))));
    }
    static get watchers() { return {
        "businessId": ["propChanged"],
        "authToken": ["propChanged"],
        "getBusiness": ["updateOnPropChange"]
    }; }
};

exports.justifi_business_details = JustifiBusinessDetails;
