import { r as registerInstance, h, c as createEvent, g as getElement } from './index-77a9c9e7.js';
import { B as Te, a7 as WR, a8 as iN, a9 as sN, aa as QR, ab as BR, ac as VR, ad as _L, ae as tM, af as r6, M as Mh, ag as Nh, ah as Do, h as SL, u as up, b as me, ai as M, aj as H, ak as ce, al as cn, am as on, an as Fr, ao as No, ap as Gc, aq as De, ar as GH, as as fr, at as Fp, au as NR, av as IR, aw as TR } from './index.esm.min-db2d29e8.js';
import { s as store } from './redux-store.service-dc54f48e.js';
import { l, t, s as se, F, V, k, d, D } from './index.esm.min-9889e78b.js';
import { z as zh, c as $$, e as e$, v as v$, y as yw, k as ii, m as g1, s as s$, n as v1, o as aw } from './index.esm.min-cd800f97.js';
import { d as debounce_1 } from './debounce-acb9228c.js';
import { i as isEqual_1 } from './isEqual-064ed72d.js';
import './_commonjsHelpers-1789f0cf.js';

const bpSdkAccordionCss = "";
const BpSdkAccordionStyle0 = bpSdkAccordionCss;

const BpSdkAccordion = class {
    constructor(hostRef) {
        registerInstance(this, hostRef);
        this.mapStateToProps = (state) => {
            var _a;
            return {
                configOptions: Te(state),
                addressValidationStatus: WR(state, (_a = this.questionGroup.poolId) !== null && _a !== void 0 ? _a : this.questionGroup.groupId),
            };
        };
        this.questionGroup = undefined;
        this.startPanelExpanded = true;
        this.configOptions = undefined;
        this.addressValidationStatus = undefined;
        this.useExternal = false;
    }
    resetState() { }
    connectedCallback() {
        this.resetState();
        this.handleSubscriptions();
    }
    componentWillLoad() {
        this.useExternal = !!customElements.get('bp-sdk-external-accordion');
        customElements.whenDefined('bp-sdk-external-accordion').then(() => {
            this.useExternal = true;
        });
        this.handleSubscriptions();
    }
    handleSubscriptions() {
        if (this.storeUnsubscribe) {
            this.storeUnsubscribe();
        }
        store.mapStateToProps(this, this.mapStateToProps);
    }
    render() {
        return [this.useExternal && this.renderExternal(), !this.useExternal && this.renderInternal()];
    }
    renderExternal() {
        return (h("bp-sdk-external-accordion", { questionGroup: this.questionGroup, startPanelExpanded: this.startPanelExpanded, configOptions: this.configOptions, addressValidationStatus: this.addressValidationStatus }));
    }
    renderAnswer(answer) {
        var _a;
        const nestedGroupToRender = (_a = this.questionGroup.nestedGroupsWithAnswers) === null || _a === void 0 ? void 0 : _a.get(answer.id);
        return [
            !nestedGroupToRender && h("bp-sdk-dynamic-input-redux-container", { answer: answer, id: `bp-sdk-question-group__${answer.question.id}` }),
            nestedGroupToRender && h("bp-sdk-question-group-container", { questionGroup: nestedGroupToRender }),
        ];
    }
    renderInternal() {
        var _a, _b, _c, _d, _e;
        return (h("div", { class: "bp-sdk-accordion__container" }, !((_a = this.configOptions) === null || _a === void 0 ? void 0 : _a.hideNestedQuestionGroupLabels) && (h("bp-sdk-question-group-label", { labelId: (_b = this.questionGroup) === null || _b === void 0 ? void 0 : _b.groupId, label: ((_c = this.questionGroup) === null || _c === void 0 ? void 0 : _c.parentQuestionAnswer.value) || ((_d = this.questionGroup) === null || _d === void 0 ? void 0 : _d.parentQuestionAnswer.question.text) })), (_e = this.questionGroup) === null || _e === void 0 ? void 0 :
            _e.answers.map((answer) => this.renderAnswer(answer))));
    }
};
BpSdkAccordion.style = BpSdkAccordionStyle0;

const bpSdkAccumulationQuestionGroupCss = "[name='evanston_activity_inventory_percentage_total']{visibility:hidden}[name='evanston_activity_inventory_percentage_total']+bp-sdk-errors-container{display:none}";
const BpSdkAccumulationQuestionGroupStyle0 = bpSdkAccumulationQuestionGroupCss;

const BpSdkAccumulationQuestionGroup = class {
    constructor(hostRef) {
        registerInstance(this, hostRef);
        this.answers = [];
        this.label = undefined;
        this.labelledBy = undefined;
        this.warning = 'Percent of total operations must equal 100%';
        this.accumulator = undefined;
        this.buffer = undefined;
        this.showAccumulatorWarning = false;
        this.showAccumulatorErrors = false;
        this.useExternal = false;
    }
    onAnswersChange(answers) {
        this.accumulator = (answers || []).find((answer) => { var _a; return ((_a = answer === null || answer === void 0 ? void 0 : answer.question) === null || _a === void 0 ? void 0 : _a.reference_type) === l.Accumulator; });
    }
    onAccumulatorChange(accumulator) {
        const buffer = parseInt(accumulator === null || accumulator === void 0 ? void 0 : accumulator.value, 10);
        this.buffer = isNaN(buffer) ? undefined : buffer;
        this.showAccumulatorWarning = this.validateAccumulatorValue();
    }
    onAccumulatorErrorsChange({ detail }) {
        this.showAccumulatorErrors = detail.length > 0;
    }
    resetState() { }
    connectedCallback() {
        this.resetState();
    }
    componentWillLoad() {
        this.useExternal = !!customElements.get('bp-sdk-external-accumulation-question-group');
        customElements.whenDefined('bp-sdk-external-accumulation-question-group').then(() => {
            this.useExternal = true;
        });
        this.onAnswersChange(this.answers);
    }
    render() {
        return [this.useExternal && this.renderExternal(), !this.useExternal && this.renderInternal()];
    }
    renderExternal() {
        return (h("bp-sdk-external-accumulation-question-group", { answers: this.answers, label: this.label, labelledBy: this.labelledBy, warning: this.warning }));
    }
    shouldHideLabel(answer) {
        var _a, _b;
        return (((_a = answer === null || answer === void 0 ? void 0 : answer.question) === null || _a === void 0 ? void 0 : _a.field_type) === t.CheckBox || ((_b = answer === null || answer === void 0 ? void 0 : answer.question) === null || _b === void 0 ? void 0 : _b.reference_type) === l.Accumulator);
    }
    getAriaLabel(answer) {
        var _a;
        return ((_a = answer === null || answer === void 0 ? void 0 : answer.question) === null || _a === void 0 ? void 0 : _a.field_type) === t.CheckBox ? answer.question.text : undefined;
    }
    validateAccumulatorValue() {
        var _a;
        if ((_a = this.accumulator) === null || _a === void 0 ? void 0 : _a.value) {
            return this.buffer < this.accumulator.question.min_value || this.buffer > this.accumulator.question.max_value;
        }
        return false;
    }
    renderInternal() {
        var _a;
        return (h("div", { class: "bp-sdk-accumulation-question-group__container" }, h("div", { class: "bp-sdk-accumulation-question-group__wrapper" }, h("div", { class: "bp-sdk-accumulation-question-set__header" }, h("bp-sdk-progress", { label: "Question group progress", value: this.buffer }), h("div", null, ((_a = this.accumulator) === null || _a === void 0 ? void 0 : _a.value) && (h("h2", { "aria-live": "assertive", class: "bp-sdk-accumulation-question-set__value" }, this.accumulator.value, "%")), this.showAccumulatorErrors && h("h4", { class: "bp-sdk-accumulation-question-set__error" }, this.warning), this.showAccumulatorWarning && !this.showAccumulatorErrors && (h("h4", { class: "bp-sdk-accumulation-question-set__warning" }, this.warning)))), this.answers.map((answer) => (h("bp-sdk-dynamic-input-redux-container", { class: zh('', {
                'bp-sdk-indent': answer.question.reference_type === l.Indent,
            }), answer: answer, shouldHideLabel: this.shouldHideLabel(answer), "aria-label": this.getAriaLabel(answer), isAccumulatorAnswer: answer.question.reference_type === l.Accumulator }))))));
    }
    static get watchers() { return {
        "answers": ["onAnswersChange"],
        "accumulator": ["onAccumulatorChange"]
    }; }
};
BpSdkAccumulationQuestionGroup.style = BpSdkAccumulationQuestionGroupStyle0;

const bpSdkAccumulationQuestionGroupContainerCss = "";
const BpSdkAccumulationQuestionGroupContainerStyle0 = bpSdkAccumulationQuestionGroupContainerCss;

const BpSdkAccumulationQuestionGroupContainer = class {
    constructor(hostRef) {
        registerInstance(this, hostRef);
        this.answers = undefined;
        this.label = undefined;
        this.labelledBy = undefined;
        this.useExternal = false;
    }
    resetState() { }
    connectedCallback() {
        this.resetState();
    }
    componentWillLoad() {
        this.useExternal = !!customElements.get('bp-sdk-external-accumulation-question-group-container');
        customElements.whenDefined('bp-sdk-external-accumulation-question-group-container').then(() => {
            this.useExternal = true;
        });
    }
    render() {
        return [this.useExternal && this.renderExternal(), !this.useExternal && this.renderInternal()];
    }
    renderExternal() {
        return h("bp-sdk-external-accumulation-question-group-container", { answers: this.answers, label: this.label, labelledBy: this.labelledBy });
    }
    renderInternal() {
        return h("bp-sdk-accumulation-question-group", { answers: this.answers, label: this.label, labelledBy: this.labelledBy });
    }
};
BpSdkAccumulationQuestionGroupContainer.style = BpSdkAccumulationQuestionGroupContainerStyle0;

const bpSdkAddressGroupContainerCss = "";
const BpSdkAddressGroupContainerStyle0 = bpSdkAddressGroupContainerCss;

const BpSdkAddressGroupContainer = class {
    constructor(hostRef) {
        registerInstance(this, hostRef);
        this.mapStateToProps = (state) => {
            var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
            return {
                enableAddressValidation: iN(state),
                addressValidationOptions: sN(state),
                isValidationComplete: QR(state, (_b = (_a = this.questionGroup) === null || _a === void 0 ? void 0 : _a.poolId) !== null && _b !== void 0 ? _b : (_c = this.questionGroup) === null || _c === void 0 ? void 0 : _c.groupId),
                hasValidationOccurred: BR(state, (_e = (_d = this.questionGroup) === null || _d === void 0 ? void 0 : _d.poolId) !== null && _e !== void 0 ? _e : (_f = this.questionGroup) === null || _f === void 0 ? void 0 : _f.groupId),
                isAddressGroupValidationInitialized: VR(state, (_h = (_g = this.questionGroup) === null || _g === void 0 ? void 0 : _g.poolId) !== null && _h !== void 0 ? _h : (_j = this.questionGroup) === null || _j === void 0 ? void 0 : _j.groupId),
                isActiveAnswerInAddressGroup: _L(state, (_l = (_k = this.questionGroup) === null || _k === void 0 ? void 0 : _k.poolId) !== null && _l !== void 0 ? _l : (_m = this.questionGroup) === null || _m === void 0 ? void 0 : _m.groupId),
                isAddressValidationFeatureEnabled: tM(state, 'enable_address_validation'),
            };
        };
        this.questionGroup = undefined;
        this.answers = [];
        this.label = undefined;
        this.labelledBy = undefined;
        this.enableAddressValidation = false;
        this.addressValidationOptions = undefined;
        this.isValidationComplete = undefined;
        this.isAddressGroupValidationInitialized = undefined;
        this.isActiveAnswerInAddressGroup = undefined;
        this.hasValidationOccurred = undefined;
        this.isAddressValidationFeatureEnabled = undefined;
        this.useExternal = false;
        this.useAddressValidation = false;
    }
    onAddressValidationRequirementChange() {
        this.updateUseAddressValidation(this.questionGroup, this.enableAddressValidation, this.addressValidationOptions, this.isValidationComplete);
    }
    onSaveAnswer(event) {
        var _a, _b;
        if (this.hasValidationOccurred && this.isActiveAnswerInAddressGroup && $$(event.detail.answer, event.detail.new_value)) {
            this.setAddressValidationStatus({
                validationStatus: se.REQUIRED,
                addressValidationId: (_a = this.questionGroup.poolId) !== null && _a !== void 0 ? _a : this.questionGroup.groupId,
            });
            this.resetAddressValidation((_b = this.questionGroup.poolId) !== null && _b !== void 0 ? _b : this.questionGroup.groupId);
        }
    }
    onShouldInitialization() {
        var _a;
        if (this.useAddressValidation && this.isAddressGroupValidationInitialized === false) {
            this.initializeAddressValidation((_a = this.questionGroup.poolId) !== null && _a !== void 0 ? _a : this.questionGroup.groupId);
        }
    }
    handleSubscriptions() {
        if (this.storeUnsubscribe) {
            this.storeUnsubscribe();
        }
        store.mapDispatchToProps(this, {
            initializeAddressValidation: r6,
            setAddressValidationStatus: Mh,
            resetAddressValidation: Nh,
        });
        store.mapStateToProps(this, this.mapStateToProps);
    }
    resetState() {
        this.enableAddressValidation = false;
        this.useAddressValidation = false;
    }
    connectedCallback() {
        this.resetState();
        this.handleSubscriptions();
    }
    disconnectedCallback() {
        this.storeUnsubscribe && this.storeUnsubscribe();
    }
    componentWillLoad() {
        this.useExternal = !!customElements.get('bp-sdk-external-address-group-container');
        customElements.whenDefined('bp-sdk-external-address-group-container').then(() => {
            this.useExternal = true;
        });
    }
    updateUseAddressValidation(questionGroup, enableAddressValidation, addressValidationOptions, isValidationComplete) {
        this.useAddressValidation = Boolean(enableAddressValidation &&
            !isValidationComplete &&
            this.isAddressValidationFeatureEnabled &&
            questionGroup &&
            (questionGroup.group_type === F.ValidatedAddress ||
                // backward compat only, remove with content update to new group type
                (addressValidationOptions &&
                    this.shouldQuestionGroupValidateAddress(questionGroup.parentQuestionAnswer.question.code, addressValidationOptions))));
    }
    shouldQuestionGroupValidateAddress(parentQuestionCode, addressValidationOptions) {
        return (addressValidationOptions.includePartialQuestionCodes.some((includedPartial) => parentQuestionCode.includes(includedPartial)) &&
            !addressValidationOptions.excludePartialQuestionCodes.some((excludedPartial) => parentQuestionCode.includes(excludedPartial)));
    }
    render() {
        return [this.useExternal && this.renderExternal(), !this.useExternal && this.renderInternal()];
    }
    renderExternal() {
        var _a, _b, _c;
        return (h("bp-sdk-external-address-group", { answers: this.answers, label: this.label, labelledBy: this.labelledBy, useAddressValidation: this.useAddressValidation, addressValidationId: (_b = (_a = this.questionGroup) === null || _a === void 0 ? void 0 : _a.poolId) !== null && _b !== void 0 ? _b : (_c = this.questionGroup) === null || _c === void 0 ? void 0 : _c.groupId }));
    }
    renderInternal() {
        var _a, _b, _c;
        return (h("bp-sdk-address-group", { answers: this.answers, label: this.label, labelledBy: this.labelledBy, useAddressValidation: this.useAddressValidation, addressValidationId: (_b = (_a = this.questionGroup) === null || _a === void 0 ? void 0 : _a.poolId) !== null && _b !== void 0 ? _b : (_c = this.questionGroup) === null || _c === void 0 ? void 0 : _c.groupId }));
    }
    static get watchers() { return {
        "addressValidationOptions": ["onAddressValidationRequirementChange"],
        "questionGroup": ["onAddressValidationRequirementChange"],
        "enableAddressValidation": ["onAddressValidationRequirementChange"],
        "isValidationComplete": ["onAddressValidationRequirementChange"],
        "isAddressValidationFeatureEnabled": ["onAddressValidationRequirementChange"],
        "useAddressValidation": ["onShouldInitialization"],
        "isAddressGroupValidationInitialized": ["onShouldInitialization"]
    }; }
};
BpSdkAddressGroupContainer.style = BpSdkAddressGroupContainerStyle0;

const bpSdkCoverageGroupCss = "";
const BpSdkCoverageGroupStyle0 = bpSdkCoverageGroupCss;

const BpSdkCoverageGroup = class {
    constructor(hostRef) {
        registerInstance(this, hostRef);
        this.questionGroup = undefined;
        this.useExternal = false;
    }
    resetState() { }
    componentWillLoad() {
        this.useExternal = !!customElements.get('bp-sdk-external-coverage-group');
        customElements.whenDefined('bp-sdk-external-coverage-group').then(() => {
            this.useExternal = true;
        });
    }
    render() {
        return [this.useExternal && this.renderExternal(), !this.useExternal && this.renderInternal()];
    }
    renderExternal() {
        return h("bp-sdk-external-coverage-group", { questionGroup: this.questionGroup });
    }
    renderAnswer(answer) {
        var _a;
        const nestedGroupToRender = (_a = this.questionGroup.nestedGroupsWithAnswers) === null || _a === void 0 ? void 0 : _a.get(answer.id);
        return [
            !nestedGroupToRender && h("bp-sdk-dynamic-input-redux-container", { answer: answer, id: `bp-sdk-question-group__${answer.question.id}` }),
            nestedGroupToRender && h("bp-sdk-question-group-container", { questionGroup: nestedGroupToRender }),
        ];
    }
    renderInternal() {
        var _a, _b, _c;
        return (h("div", { class: "bp-sdk-coverage-group__container" }, h("bp-sdk-question-group-label", { labelId: (_a = this.questionGroup) === null || _a === void 0 ? void 0 : _a.groupId, label: (_b = this.questionGroup) === null || _b === void 0 ? void 0 : _b.parentQuestionAnswer.question.text }), (_c = this.questionGroup) === null || _c === void 0 ? void 0 :
            _c.answers.map((answer) => this.renderAnswer(answer))));
    }
};
BpSdkCoverageGroup.style = BpSdkCoverageGroupStyle0;

const bpSdkDriverGroupCss = "";
const BpSdkDriverGroupStyle0 = bpSdkDriverGroupCss;

const BpSdkDriverGroup = class {
    constructor(hostRef) {
        registerInstance(this, hostRef);
        this.deleteItem = createEvent(this, "deleteItem", 7);
        this.slotId = e$(8);
        this.onToggleExpansion = () => {
            this.isExpanded = !this.isExpanded;
        };
        this.onDeleteButtonClick = () => this.deleteItem.emit();
        this.group = undefined;
        this.canDelete = false;
        this.errors = {};
        this.isDriverValid = true;
        this.driverName = '';
        this.labelId = e$(8);
        this.useExternal = false;
        this.isExpanded = true;
    }
    onGroupChange(group) {
        this.updateDriverValidity(group, this.errors);
        this.updateDriverName(group);
    }
    onErrorsChange(errors) {
        this.updateDriverValidity(this.group, errors);
    }
    updateDriverName(group) {
        var _a, _b, _c, _d, _e, _f;
        if (!group) {
            return;
        }
        const firstName = (_b = (_a = v$('mqs_driver_first_name', group.answers)) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : '';
        const lastName = (_d = (_c = v$('mqs_driver_last_name', group.answers)) === null || _c === void 0 ? void 0 : _c.value) !== null && _d !== void 0 ? _d : '';
        let name = group.label;
        if (firstName && lastName) {
            name = `${firstName} ${lastName}`;
        }
        if ((_e = group.parentQuestionAnswer) === null || _e === void 0 ? void 0 : _e.value) {
            name = (_f = group.parentQuestionAnswer) === null || _f === void 0 ? void 0 : _f.value;
        }
        this.driverName = name || 'Driver';
    }
    updateDriverValidity(group, errors) {
        var _a;
        this.isDriverValid = yw(group) && !!((_a = group.answers) === null || _a === void 0 ? void 0 : _a.reduce((acc, answer) => { var _a; return acc && !((_a = errors[answer.question.id]) === null || _a === void 0 ? void 0 : _a.length); }, true));
    }
    resetState() {
        this.driverName = '';
        this.isDriverValid = true;
    }
    connectedCallback() {
        this.resetState();
    }
    componentWillLoad() {
        this.useExternal = !!customElements.get('bp-sdk-external-driver-group');
        customElements.whenDefined('bp-sdk-external-driver-group').then(() => {
            this.useExternal = true;
        });
        this.updateDriverValidity(this.group, this.errors);
        this.updateDriverName(this.group);
    }
    render() {
        return [this.useExternal && this.renderExternal(), !this.useExternal && this.renderInternal()];
    }
    renderExternal() {
        return h("bp-sdk-external-driver-group", { group: this.group, errors: this.errors, canDelete: this.canDelete });
    }
    renderInternal() {
        var _a;
        const iconName = this.isDriverValid ? 'person' : 'error-outline';
        return (h("div", { class: "bp-sdk-driver-group__container" }, h("bp-sdk-icon-container", { name: iconName }), h("span", { id: this.labelId, class: "bp-sdk-driver-group__name", slot: `${this.slotId}-label`, onClick: this.onToggleExpansion }, this.driverName), this.canDelete && (h("button", { type: "button", class: "bp-sdk-driver-group__delete-button", slot: `${this.slotId}-label--after`, onClick: this.onDeleteButtonClick }, "Delete")), h("bp-sdk-dynamic-input-list", { answers: (_a = this.group) === null || _a === void 0 ? void 0 : _a.answers, labelledBy: this.labelId })));
    }
    static get watchers() { return {
        "group": ["onGroupChange"],
        "errors": ["onErrorsChange"]
    }; }
};
BpSdkDriverGroup.style = BpSdkDriverGroupStyle0;

const bpSdkDriverQuestionPoolContainerCss = "";
const BpSdkDriverQuestionPoolContainerStyle0 = bpSdkDriverQuestionPoolContainerCss;

const BpSdkDriverQuestionPoolContainer = class {
    constructor(hostRef) {
        registerInstance(this, hostRef);
        this.deletePool = createEvent(this, "deletePool", 7);
        this.handleSubscriptions = () => {
            this.storeUnsubscribe && this.storeUnsubscribe();
            store.mapDispatchToProps(this, { removeQuestionPool: Do });
            this.storeUnsubscribe = store.mapStateToProps(this, this.mapStateToProps);
        };
        this.mapStateToProps = (state) => {
            return {
                applicationId: SL(state),
                config: up(state),
                questionSets: me(state),
            };
        };
        this.handleDeleteItem = () => {
            this.isDeleting = true;
            this.removeQuestionPool({
                answer_pool_id: this.questionPoolId,
                application_id: this.applicationId,
                config: this.config,
                callback: () => {
                    this.deletePool.emit(undefined);
                },
            });
            this.deletePool.emit(this.questionPoolId);
        };
        this.questionGroup = undefined;
        this.applicationId = undefined;
        this.config = undefined;
        this.questionSets = [];
        this.useExternal = false;
        this.questionPool = undefined;
        this.questionPoolId = undefined;
        this.isDeleting = false;
    }
    resetState() { }
    connectedCallback() {
        this.resetState();
        this.handleSubscriptions();
    }
    disconnectedCallback() {
        this.storeUnsubscribe && this.storeUnsubscribe();
    }
    onQuestionGroupChange(questionGroup) {
        this.questionPoolId = questionGroup === null || questionGroup === void 0 ? void 0 : questionGroup.poolId;
    }
    componentWillLoad() {
        this.useExternal = !!customElements.get('bp-sdk-external-driver-question-pool-container');
        customElements.whenDefined('bp-sdk-external-driver-question-pool-container').then(() => {
            this.useExternal = true;
        });
        this.handleSubscriptions();
        this.onQuestionGroupChange(this.questionGroup);
    }
    render() {
        return [this.useExternal && this.renderExternal(), !this.useExternal && this.renderInternal()];
    }
    renderExternal() {
        return (h("bp-sdk-external-driver-question-pool-container", { applicationId: this.applicationId, config: this.config, questionGroup: this.questionGroup, questionSets: this.questionSets }));
    }
    renderInternal() {
        return (h("div", { class: "bp-sdk-driver-question-pool-container__container" }, !this.isDeleting && !!this.questionPoolId && (h("bp-sdk-driver-group", { group: this.questionGroup, canDelete: true, onDeleteItem: this.handleDeleteItem }))));
    }
    get el() { return getElement(this); }
    static get watchers() { return {
        "questionGroup": ["onQuestionGroupChange"]
    }; }
};
BpSdkDriverQuestionPoolContainer.style = BpSdkDriverQuestionPoolContainerStyle0;

const bpSdkQuestionGroupLabelCss = "";
const BpSdkQuestionGroupLabelStyle0 = bpSdkQuestionGroupLabelCss;

const BpSdkQuestionGroupLabel = class {
    constructor(hostRef) {
        registerInstance(this, hostRef);
        this.labelId = undefined;
        this.label = undefined;
        this.useExternal = false;
    }
    componentWillLoad() {
        this.useExternal = !!customElements.get('bp-sdk-external-question-group-label');
        customElements.whenDefined('bp-sdk-external-question-group-label').then(() => {
            this.useExternal = true;
        });
    }
    render() {
        return [this.useExternal && this.renderExternal(), !this.useExternal && this.renderInternal()];
    }
    renderExternal() {
        return h("bp-sdk-external-question-group-label", { label: this.label, labelId: this.labelId });
    }
    renderInternal() {
        return (h("h2", { id: this.labelId, class: "bp-sdk-question-group__label" }, this.label));
    }
};
BpSdkQuestionGroupLabel.style = BpSdkQuestionGroupLabelStyle0;

const bpSdkStepperGroupCss = "";
const BpSdkStepperGroupStyle0 = bpSdkStepperGroupCss;

const BpSdkStepperGroup = class {
    constructor(hostRef) {
        registerInstance(this, hostRef);
        this.questionGroup = undefined;
        this.useExternal = false;
    }
    resetState() { }
    connectedCallback() {
        this.resetState();
    }
    componentWillLoad() {
        this.useExternal = !!customElements.get('bp-sdk-external-stepper-group');
        customElements.whenDefined('bp-sdk-external-stepper-group').then(() => {
            this.useExternal = true;
        });
    }
    render() {
        return [this.useExternal && this.renderExternal(), !this.useExternal && this.renderInternal()];
    }
    renderAnswers(questionGroup) {
        var _a;
        return (_a = questionGroup === null || questionGroup === void 0 ? void 0 : questionGroup.answers) === null || _a === void 0 ? void 0 : _a.map((answer) => {
            if (this.displayAsQuestionGroup(answer.id)) {
                const nestedGroup = this.questionGroup.nestedGroupsWithAnswers.get(answer.id);
                if (nestedGroup.answers.length > 0) {
                    return h("bp-sdk-stepper-group", { questionGroup: nestedGroup });
                }
                return h("bp-sdk-stepper-group", { questionGroup: this.questionGroup.nestedGroupsWithAnswers.get(answer.id) });
            }
            else {
                return (h("bp-sdk-dynamic-input-redux-container", { answer: answer, labelledBy: "", id: `bp-sdk-question-group__${answer.question.id}`, class: "bp-sdk-question-group__question-set" }));
            }
        });
    }
    renderExternal() {
        return h("bp-sdk-external-stepper-group", { questionGroup: this.questionGroup });
    }
    renderInternal() {
        return h("div", { class: "bp-sdk-stepper-group__container" }, this.renderAnswers(this.questionGroup));
    }
    displayAsQuestionGroup(id) {
        return this.questionGroup.nestedGroupsWithAnswers.has(id);
    }
};
BpSdkStepperGroup.style = BpSdkStepperGroupStyle0;

const bpSdkStepperGroupButtonCss = "";
const BpSdkStepperGroupButtonStyle0 = bpSdkStepperGroupButtonCss;

const BpSdkStepperGroupButton = class {
    constructor(hostRef) {
        registerInstance(this, hostRef);
        this.answer = undefined;
        this.direction = undefined;
        this.buttonDisabled = false;
        this.handleStepperButtonClick = undefined;
        this.useExternal = false;
    }
    resetState() { }
    componentWillLoad() {
        this.useExternal = !!customElements.get('bp-sdk-external-stepper-group-button');
        customElements.whenDefined('bp-sdk-external-stepper-group-button').then(() => {
            this.useExternal = true;
        });
    }
    render() {
        return [this.useExternal && this.renderExternal(), !this.useExternal && this.renderInternal()];
    }
    renderExternal() {
        return (h("bp-sdk-external-stepper-group-button", { answer: this.answer, direction: this.direction, buttonDisabled: this.buttonDisabled, handleStepperButtonClick: this.handleStepperButtonClick }));
    }
    renderInternal() {
        return (h("div", { class: "bp-sdk-stepper-group-button__container" }, this.answer && (h("button", { type: "button", class: "bp-sdk-stepper-group-button__button", disabled: this.buttonDisabled, onClick: () => this.handleStepperButtonClick(this.answer, this.direction) }, this.answer.question.text))));
    }
};
BpSdkStepperGroupButton.style = BpSdkStepperGroupButtonStyle0;

const bpSdkStepperGroupContainerCss = "";
const BpSdkStepperGroupContainerStyle0 = bpSdkStepperGroupContainerCss;

const BpSdkStepperGroupContainer = class {
    constructor(hostRef) {
        registerInstance(this, hostRef);
        this.handleStepperClick = (answerId) => {
            const index = this.questionGroup.answers.findIndex((answer) => answer.id === answerId);
            this.currentActiveStepper = index >= 0 ? index : 0;
        };
        this.handleButtonClick = (answerId, direction) => {
            if (direction === 'forward') {
                this.currentActiveStepper += 1;
            }
            else {
                this.currentActiveStepper -= 1;
            }
        };
        this.questionGroup = undefined;
        this.currentActiveStepper = 0;
        this.currentActiveStepperId = undefined;
        this.previousStep = null;
        this.nextStep = null;
        this.buttonDisable = false;
        this.useExternal = false;
    }
    onCurrentActiveStepChange(index) {
        var _a, _b, _c, _d, _e, _f;
        this.currentActiveStepperId = (_b = (_a = this.questionGroup) === null || _a === void 0 ? void 0 : _a.answers[index]) === null || _b === void 0 ? void 0 : _b.id;
        this.previousStep = (_d = (_c = this.questionGroup) === null || _c === void 0 ? void 0 : _c.answers[index - 1]) !== null && _d !== void 0 ? _d : null;
        this.nextStep = (_f = (_e = this.questionGroup) === null || _e === void 0 ? void 0 : _e.answers[index + 1]) !== null && _f !== void 0 ? _f : null;
        this.updateButtonDisabled();
    }
    onQuestionGroupChange(questionGroup) {
        var _a, _b;
        if (!!questionGroup) {
            this.currentActiveStepperId = (_b = (_a = this.questionGroup) === null || _a === void 0 ? void 0 : _a.answers[this.currentActiveStepper]) === null || _b === void 0 ? void 0 : _b.id;
            this.updateButtonDisabled();
        }
    }
    resetState() {
        var _a, _b;
        this.currentActiveStepper = 0;
        this.previousStep = null;
        this.nextStep = (_b = (_a = this.questionGroup) === null || _a === void 0 ? void 0 : _a.answers[this.currentActiveStepper + 1]) !== null && _b !== void 0 ? _b : null;
    }
    componentWillLoad() {
        this.useExternal = !!customElements.get('bp-sdk-external-stepper-group-container');
        customElements.whenDefined('bp-sdk-external-stepper-group-container').then(() => {
            this.useExternal = true;
        });
        this.onCurrentActiveStepChange(this.currentActiveStepper);
        this.onQuestionGroupChange(this.questionGroup);
    }
    render() {
        return [this.useExternal && this.renderExternal(), !this.useExternal && this.renderInternal()];
    }
    renderCurrentQuestionGroup(currentActiveStepperId) {
        var _a;
        const currentGroup = (_a = this.questionGroup) === null || _a === void 0 ? void 0 : _a.nestedGroupsWithAnswers.get(currentActiveStepperId);
        return (h("div", { class: "bp-sdk-stepper-group-container__current-group" }, h("bp-sdk-stepper-group", { questionGroup: currentGroup })));
    }
    renderExternal() {
        return h("bp-sdk-external-stepper-group-container", { questionGroup: this.questionGroup });
    }
    renderInternal() {
        return (h("div", { class: "bp-sdk-stepper-group-container__container" }, this.renderCurrentQuestionGroup(this.currentActiveStepperId), h("bp-sdk-stepper-group-button", { answer: this.previousStep, direction: "backward", buttonDisabled: false, handleStepperButtonClick: this.handleButtonClick }), h("bp-sdk-stepper-group-button", { answer: this.nextStep, direction: "forward", buttonDisabled: this.buttonDisable, handleStepperButtonClick: this.handleButtonClick })));
    }
    updateButtonDisabled() {
        var _a;
        if (!!this.currentActiveStepperId) {
            const group = (_a = this.questionGroup) === null || _a === void 0 ? void 0 : _a.nestedGroupsWithAnswers.get(this.currentActiveStepperId);
            const aggregateAnswers = [
                ...group.answers,
                ...group.answers.filter((answer) => {
                    if (group.nestedGroupsWithAnswers.has(answer.id)) {
                        return group.nestedGroupsWithAnswers.get(answer.id).answers;
                    }
                }),
            ];
            this.buttonDisable = !aggregateAnswers.every((answer) => { var _a; return !!answer.choice_id || ((_a = answer.choice_ids) === null || _a === void 0 ? void 0 : _a.length) > 0 || !!answer.value || !answer.required || answer.display_type === 'private'; });
        }
    }
    static get watchers() { return {
        "currentActiveStepper": ["onCurrentActiveStepChange"],
        "questionGroup": ["onQuestionGroupChange"]
    }; }
};
BpSdkStepperGroupContainer.style = BpSdkStepperGroupContainerStyle0;

const bpSdkVehiclePanelContainerCss = "";
const BpSdkVehiclePanelContainerStyle0 = bpSdkVehiclePanelContainerCss;

const BpSdkVehiclePanelContainer = class {
    constructor(hostRef) {
        registerInstance(this, hostRef);
        this.deleteItem = createEvent(this, "deleteItem", 7);
        this.saveAnswer = createEvent(this, "saveAnswer", 7);
        this.makeDisplayValue = '';
        this.handleSubscriptions = () => {
            this.storeUnsubscribe && this.storeUnsubscribe();
            store.mapDispatchToProps(this, {
                loadYears: M,
                loadMakes: H,
                loadModels: ce,
                loadConfigurations: cn,
                loadSingleQuestionSet: on,
                loadSingleApplicationForm: Fr,
                selectVehicle: No,
                resetSelectedVehicle: Gc,
                loadFullVehicleOptions: De,
                setVehicleSelection: GH,
                lazyLoadVehicleOptions: fr,
            });
            this.storeUnsubscribe = store.mapStateToProps(this, this.mapStateToProps);
        };
        this.mapStateToProps = (state) => {
            return {
                config: up(state),
                appFormId: state.application.form.id,
                yearOptions: Fp(state, this.questionGroupId),
                selectionStatus: NR(state, this.questionGroupId),
                vehicleInformation: IR(state, this.questionGroupId),
                vehicleSelection: TR(state, this.questionGroupId),
            };
        };
        this.loadOptions = debounce_1((selection) => {
            this.loadFullVehicleOptions({
                year: selection.yearId,
                makeId: selection.makeId,
                modelId: selection.modelId,
                config: this.config,
                questionGroupId: this.questionGroupId,
                type: this.type,
            });
            this.setVehicleSelection({
                questionGroupId: this.questionGroupId,
                selection,
            });
        }, 100);
        this.setOptions = debounce_1((selection) => {
            this.setVehicleSelection({
                questionGroupId: this.questionGroupId,
                selection: Object.assign({ configurationId: undefined, makeId: undefined, modelId: undefined, yearId: undefined }, selection),
            });
        }, 100);
        this.onVehicleSaveCallback = () => {
            this.isSaving = false;
            this.isEditing = false;
            this.onQuestionGroupChange(this.questionGroup);
        };
        this.editVehicle = (e) => {
            e.stopPropagation();
            this.onEdit();
        };
        this.deleteVehicle = () => {
            this.deleteItem.emit(this.code);
        };
        this.onOpen = () => {
            this.canEdit = true;
            this.isEditing = false;
            this.isExpanded = true;
        };
        this.onClose = () => {
            this.canEdit = false;
            this.isEditing = false;
            this.isExpanded = false;
        };
        this.code = undefined;
        this.answers = [];
        this.questionGroup = undefined;
        this.canDelete = false;
        this.appFormId = undefined;
        this.config = undefined;
        this.yearOptions = {};
        this.selectionStatus = undefined;
        this.shouldShowTrailers = false;
        this.isVehicleTrailer = false;
        this.vehicleInformation = {
            year: '',
            make: '',
            model: '',
            configuration: '',
        };
        this.canEdit = true;
        this.canSave = false;
        this.isEditing = false;
        this.isExpanded = true;
        this.isSaving = false;
        this.isValid = true;
        this.useExternal = false;
        this.vehicleSelection = undefined;
        this._currentYear = undefined;
        this._currentMakeId = undefined;
        this._currentModelId = undefined;
        this._currentConfigId = undefined;
        this.questionGroupId = undefined;
        this.type = undefined;
        this.tabIndex = 0;
        this.vehicleLabel = '';
    }
    resetState() {
        this.canEdit = true;
        this.canSave = false;
        this.isEditing = false;
        this.isExpanded = true;
        this.isValid = true;
        this.type = undefined;
        this.vehicleLabel = '';
        this.makeDisplayValue = '';
    }
    connectedCallback() {
        this.resetState();
        this.handleSubscriptions();
    }
    componentWillLoad() {
        this.useExternal = !!customElements.get('bp-sdk-external-vehicle-panel-container');
        customElements.whenDefined('bp-sdk-external-vehicle-panel-container').then(() => {
            this.useExternal = true;
        });
        this.onIsVehicleTrailerChanged(this.isVehicleTrailer);
        this.onTabChanged(this.tabIndex);
        this.onQuestionGroupChange(this.questionGroup);
    }
    handleTabChanged({ detail }) {
        if (this.useExternal) {
            return;
        }
        this.tabIndex = detail;
    }
    onTabChanged(tab) {
        this.updateType(tab, this.isVehicleTrailer);
    }
    onIsVehicleTrailerChanged(isVehicleTrailer) {
        this.updateType(this.tabIndex, isVehicleTrailer);
    }
    onVehicleSelctionChanged(selection) {
        if (!this._currentMakeId && selection.makeId) {
            this._currentMakeId = selection.makeId;
        }
        if (!this._currentModelId && selection.modelId) {
            this._currentModelId = selection.modelId;
        }
        if (!this._currentConfigId && selection.configurationId) {
            this._currentConfigId = selection.configurationId;
        }
    }
    updateType(tab, isVehicleTrailer) {
        if (this.useExternal) {
            return;
        }
        const type = isVehicleTrailer || this.isTrailerTab(tab) ? V.trailers : undefined;
        if (type !== this.type) {
            this.setVehicleSelection({
                questionGroupId: this.questionGroupId,
                selection: { yearId: undefined, modelId: undefined, makeId: undefined, configurationId: undefined },
            });
            this.populateVehicleOptions(this.questionGroup);
            this.type = type;
            this.fetchYears();
        }
    }
    isTrailerTab(tab) {
        var _a;
        const flow = ii(this.questionGroup);
        const trailerTab = flow === null || flow === void 0 ? void 0 : flow.question.choices.find((choice) => !!choice.value.match(/trailer/gi));
        const order = (_a = trailerTab === null || trailerTab === void 0 ? void 0 : trailerTab.order) !== null && _a !== void 0 ? _a : 2; // we know what order should be
        return tab === order;
    }
    populateVehicleOptions(questionGroup) {
        var _a, _b, _c, _d;
        const existingVehicleAnswer = (_a = questionGroup === null || questionGroup === void 0 ? void 0 : questionGroup.answers) === null || _a === void 0 ? void 0 : _a.find((ans) => ans.question.reference_type === l.CommercialAutoJson);
        if (!(existingVehicleAnswer === null || existingVehicleAnswer === void 0 ? void 0 : existingVehicleAnswer.value)) {
            return;
        }
        const vehicleJson = JSON.parse(existingVehicleAnswer.value);
        let year = Number(vehicleJson.year);
        let makeId = (_b = vehicleJson.make_id) === null || _b === void 0 ? void 0 : _b.toString();
        let modelId = (_c = vehicleJson.model_id) === null || _c === void 0 ? void 0 : _c.toString();
        let configurationId = (_d = vehicleJson.configuration_id) === null || _d === void 0 ? void 0 : _d.toString();
        let make = vehicleJson.make;
        let model = vehicleJson.model;
        let isFreeformTrailer = false;
        //account for fallthrough free-text values for trailers
        if (vehicleJson.category === 'Trailers') {
            if (!makeId) {
                makeId = vehicleJson.make;
                isFreeformTrailer = true;
            }
            if (!modelId) {
                modelId = vehicleJson.model;
                isFreeformTrailer = true;
            }
        }
        const isValidState = !Number.isNaN(year) && makeId && modelId && (configurationId || vehicleJson.category === 'Trailers');
        this._currentYear = year;
        this._currentMakeId = makeId;
        this._currentModelId = modelId;
        this._currentConfigId = configurationId;
        this.canSave = this.isVehicleInputComplete();
        if (isValidState && !isFreeformTrailer) {
            this.loadOptions({
                yearId: year,
                makeId,
                modelId,
                configurationId,
            });
        }
        else if (!isValidState && !Number.isNaN(year) && !!make && !!model) {
            this.lazyLoadVehicleOptions({
                year,
                make,
                model,
                config: this.config,
                questionGroupId: this.questionGroupId,
                type: this.type,
            });
        }
    }
    onQuestionGroupChange(questionGroup, oldQuestionGroup) {
        if (this.isSaving || isEqual_1(questionGroup, oldQuestionGroup)) {
            return;
        }
        this.questionGroupId = g1(questionGroup);
        const oldGroupId = g1(oldQuestionGroup);
        if (this.questionGroupId !== oldGroupId)
            this.populateVehicleOptions(questionGroup);
        this.handleSubscriptions();
        this.vehicleLabel = this.getVehicleLabel();
        this.canSave = this.isVehicleInputComplete();
    }
    onVehicleInformationChange(vehicleInformation) {
        this.isValid = !!(vehicleInformation.make && vehicleInformation.model && vehicleInformation.year);
    }
    onOptionsUpdate(updateEvent) {
        var _a;
        const data = updateEvent.detail;
        if (!(data === null || data === void 0 ? void 0 : data.value)) {
            return;
        }
        switch (data.type) {
            case k.Year:
                const currentYear = Number(data.value);
                if (!Number.isNaN(currentYear) && currentYear) {
                    this._currentYear = currentYear;
                    this._currentMakeId = undefined;
                    this._currentModelId = undefined;
                    this._currentConfigId = undefined;
                    this.setOptions({ yearId: currentYear });
                    this.fetchMakes();
                }
                break;
            case k.Make:
                this._currentMakeId = data.value;
                this._currentModelId = undefined;
                this._currentConfigId = undefined;
                this.setOptions({ makeId: this._currentMakeId, yearId: this._currentYear });
                if (!data.freeform)
                    this.fetchModels();
                // Needed for free-form answer flows for trailers
                this.makeDisplayValue = (_a = data.displayValue) !== null && _a !== void 0 ? _a : '';
                break;
            case k.Model:
                this._currentModelId = data.value;
                this._currentConfigId = undefined;
                this.setOptions({
                    modelId: this._currentModelId,
                    makeId: this._currentMakeId,
                    yearId: this._currentYear,
                });
                if (!data.freeform)
                    this.fetchConfigurations();
                break;
            case k.Configuration:
                this._currentConfigId = data.value;
                this.setOptions({
                    configurationId: this._currentConfigId,
                    modelId: this._currentModelId,
                    makeId: this._currentMakeId,
                    yearId: this._currentYear,
                });
                break;
        }
        this.vehicleLabel = this.getVehicleLabel();
        this.canSave = this.isVehicleInputComplete();
    }
    fetchYears() {
        this.loadYears({ config: this.config, questionGroupId: this.questionGroupId });
    }
    fetchMakes() {
        this.loadMakes({
            config: this.config,
            questionGroupId: this.questionGroupId,
            type: this.type,
            year: this._currentYear,
        });
    }
    fetchModels() {
        this.loadModels({
            config: this.config,
            questionGroupId: this.questionGroupId,
            type: this.type,
            year: this._currentYear,
            makeId: this._currentMakeId,
        });
    }
    fetchConfigurations() {
        this.loadConfigurations({
            config: this.config,
            questionGroupId: this.questionGroupId,
            type: this.type,
            year: this._currentYear,
            makeId: this._currentMakeId,
            modelId: this._currentModelId,
        });
    }
    onMakeDirty() {
        if (!this.isValid && !this.isEditing && this.canEdit) {
            this.onEdit();
            setTimeout(() => s$(), 200);
        }
    }
    onVinUpdate(event) {
        const answer = this.questionGroup.answers.find((ans) => ans.id === event.detail.answerId);
        if (answer != null) {
            this.saveAnswer.emit({ answer, new_value: event.detail.vin });
        }
    }
    onVehicleSave(saveEvent) {
        const flowType = saveEvent.detail;
        const isTrailerFlow = flowType === D.trailers;
        const type = isTrailerFlow ? D.trailers : undefined;
        const params = {
            answerPoolId: this.questionGroup.poolId,
            appId: this.appFormId,
            questionGroupId: this.questionGroup.groupId,
            configurationId: this._currentConfigId,
            flowType,
            config: this.config,
            type,
            callback: this.onVehicleSaveCallback,
        };
        if (flowType && (isTrailerFlow || this._currentConfigId)) {
            this.isSaving = true;
            if (isTrailerFlow && !this._currentConfigId) {
                /**
                 * The vehicle params support the free-form text flow. They will be ignored if params.configurationId is defined.
                 * In a free-form flow, PE uses the YMM values as-is, so we always need to pass them as the display values
                 * instead of as IDs.
                 *
                 * The year id always matches the display value, so we can use that in any scenario.
                 * If we are in a free-form flow, the model will always be a free-form answer. Therefore the id and display
                 * values will match, and we can send the model id.
                 * Make can be a dropdown option id or a free-form answer. If it is a dropdown option, the display value is the
                 * text value we need to send to PE. If it is a free-form answer, the display value will match the id, and either
                 * can be sent to PE. Therefore, we can safely choose the display value for either scenario.
                 */
                params.vehicle = {
                    yearId: this._currentYear,
                    makeId: this.makeDisplayValue,
                    modelId: this._currentModelId,
                };
            }
            this.selectVehicle(params);
        }
    }
    onVehicleResourceChange(vehicleSelectionState) {
        if (this.isEditing) {
            switch (vehicleSelectionState) {
                case d.Loaded:
                    this.resetSelectedVehicle({ questionGroupId: this.questionGroup.groupId });
                    break;
            }
        }
    }
    disconnectedCallback() {
        this.storeUnsubscribe && this.storeUnsubscribe();
    }
    onEdit() {
        if (!this.yearOptions) {
            this.fetchYears();
        }
        this.isEditing = true;
    }
    render() {
        return [this.useExternal && this.renderExternal(), !this.useExternal && this.renderInternal()];
    }
    renderExternal() {
        return (h("bp-sdk-external-vehicle-panel-container", { answers: this.answers, appFormId: this.appFormId, canDelete: this.canDelete, code: this.code, config: this.config, isVehicleTrailer: this.isVehicleTrailer, questionGroup: this.questionGroup, selectionStatus: this.selectionStatus, shouldShowTrailers: this.shouldShowTrailers, yearOptions: this.yearOptions, vehicleInformation: this.vehicleInformation, vehicleLabel: this.vehicleLabel }));
    }
    renderInternal() {
        return (h("bp-sdk-vehicle-panel", { answers: this.answers, canDelete: this.canDelete, canEdit: this.canEdit, canSave: this.canSave, code: this.code, handleClose: this.onClose, handleDelete: this.deleteVehicle, handleEdit: this.editVehicle, handleOpen: this.onOpen, isEditing: this.isEditing, isExpanded: this.isExpanded, isValid: this.isValid, questionGroup: this.questionGroup, isVehicleTrailer: this.isVehicleTrailer, shouldShowTrailers: this.shouldShowTrailers, vehicleInformation: this.vehicleInformation, vehicleLabel: this.vehicleLabel }));
    }
    getVehicleLabel() {
        var _a, _b, _c;
        // This is the anchor question. Its value should be the full vehicle name
        return (_c = (_b = (_a = this.questionGroup) === null || _a === void 0 ? void 0 : _a.parentQuestionAnswer) === null || _b === void 0 ? void 0 : _b.value) !== null && _c !== void 0 ? _c : '';
    }
    isVehicleInputComplete() {
        const hasTrailerValues = !!this._currentYear && !!this._currentMakeId && !!this._currentModelId;
        const canSaveTrailer = this.isVehicleTrailer && hasTrailerValues && (!!this._currentConfigId || this.isFreeFill());
        return canSaveTrailer || !!this._currentConfigId;
    }
    isFreeFill() {
        return isNaN(+this._currentModelId);
    }
    get el() { return getElement(this); }
    static get watchers() { return {
        "tabIndex": ["onTabChanged"],
        "isVehicleTrailer": ["onIsVehicleTrailerChanged"],
        "vehicleSelection": ["onVehicleSelctionChanged"],
        "questionGroup": ["onQuestionGroupChange"],
        "vehicleInformation": ["onVehicleInformationChange"],
        "selectionStatus": ["onVehicleResourceChange"]
    }; }
};
BpSdkVehiclePanelContainer.style = BpSdkVehiclePanelContainerStyle0;

const bpSdkVehicleQuestionPoolContainerCss = "";
const BpSdkVehicleQuestionPoolContainerStyle0 = bpSdkVehicleQuestionPoolContainerCss;

const BpSdkVehicleQuestionPoolContainer = class {
    constructor(hostRef) {
        registerInstance(this, hostRef);
        this.deletePool = createEvent(this, "deletePool", 7);
        this.handleSubscriptions = () => {
            this.storeUnsubscribe && this.storeUnsubscribe();
            store.mapDispatchToProps(this, { removeQuestionPool: Do });
            this.storeUnsubscribe = store.mapStateToProps(this, this.mapStateToProps);
        };
        this.mapStateToProps = (state) => {
            return {
                applicationId: SL(state),
                config: up(state),
            };
        };
        this.handleDeleteItem = () => {
            this.isDeleting = true;
            this.removeQuestionPool({
                answer_pool_id: this.questionPoolId,
                application_id: this.applicationId,
                config: this.config,
                callback: () => {
                    this.deletePool.emit(undefined);
                },
            });
            this.deletePool.emit(this.questionPoolId);
        };
        this.questionGroup = undefined;
        this.applicationId = undefined;
        this.config = undefined;
        this.useExternal = false;
        this.questionPool = undefined;
        this.questionPoolId = undefined;
        this.isDeleting = false;
    }
    resetState() { }
    connectedCallback() {
        this.resetState();
        this.handleSubscriptions();
    }
    disconnectedCallback() {
        this.storeUnsubscribe && this.storeUnsubscribe();
    }
    onQuestionGroupChange(questionGroup) {
        this.questionPoolId = questionGroup === null || questionGroup === void 0 ? void 0 : questionGroup.poolId;
    }
    componentWillLoad() {
        this.useExternal = !!customElements.get('bp-sdk-external-vehicle-question-pool-container');
        customElements.whenDefined('bp-sdk-external-vehicle-question-pool-container').then(() => {
            this.useExternal = true;
        });
        this.handleSubscriptions();
        this.onQuestionGroupChange(this.questionGroup);
    }
    render() {
        return [this.useExternal && this.renderExternal(), !this.useExternal && this.renderInternal()];
    }
    renderExternal() {
        return (h("bp-sdk-external-vehicle-question-pool-container", { applicationId: this.applicationId, config: this.config, questionGroup: this.questionGroup }));
    }
    renderInternal() {
        return (!this.isDeleting &&
            !!this.questionPoolId && (h("bp-sdk-vehicle-panel-container", { canDelete: true, isVehicleTrailer: v1(this.questionGroup), onDeleteItem: this.handleDeleteItem, questionGroup: this.questionGroup, answers: aw(this.questionGroup), shouldShowTrailers: this.questionGroup.order >= 1 || v1(this.questionGroup) })));
    }
    get el() { return getElement(this); }
    static get watchers() { return {
        "questionGroup": ["onQuestionGroupChange"]
    }; }
};
BpSdkVehicleQuestionPoolContainer.style = BpSdkVehicleQuestionPoolContainerStyle0;

export { BpSdkAccordion as bp_sdk_accordion, BpSdkAccumulationQuestionGroup as bp_sdk_accumulation_question_group, BpSdkAccumulationQuestionGroupContainer as bp_sdk_accumulation_question_group_container, BpSdkAddressGroupContainer as bp_sdk_address_group_container, BpSdkCoverageGroup as bp_sdk_coverage_group, BpSdkDriverGroup as bp_sdk_driver_group, BpSdkDriverQuestionPoolContainer as bp_sdk_driver_question_pool_container, BpSdkQuestionGroupLabel as bp_sdk_question_group_label, BpSdkStepperGroup as bp_sdk_stepper_group, BpSdkStepperGroupButton as bp_sdk_stepper_group_button, BpSdkStepperGroupContainer as bp_sdk_stepper_group_container, BpSdkVehiclePanelContainer as bp_sdk_vehicle_panel_container, BpSdkVehicleQuestionPoolContainer as bp_sdk_vehicle_question_pool_container };
