'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

const index = require('./index-ceff47a0.js');
const index_esm_min = require('./index.esm.min-1101deb1.js');

const bpSdkErrorsCss = "";
const BpSdkErrorsStyle0 = bpSdkErrorsCss;

const BpSdkErrors = class {
    constructor(hostRef) {
        index.registerInstance(this, hostRef);
        this.answerId = undefined;
        this.questionId = undefined;
        this.min = undefined;
        this.minDate = undefined;
        this.max = undefined;
        this.maxDate = undefined;
        this.fieldType = undefined;
        this.pattern = undefined;
        this.errors = [];
        this.errorText = undefined;
        this.errorMessages = undefined;
        this.useExternal = false;
    }
    transformError(error) {
        switch (error) {
            case index_esm_min.M.MaximumValue:
            case index_esm_min.M.MinimumValue:
                if (index_esm_min.ye.includes(this.fieldType)) {
                    return this.errorMessages.value(this.min, this.max);
                }
                else {
                    return this.errorMessages.length(this.min, this.max);
                }
            case index_esm_min.M.MinimumDate:
            case index_esm_min.M.MaximumDate:
                return this.errorMessages.date(this.minDate, this.maxDate);
            case index_esm_min.M.Required:
                return this.errorMessages.required();
            case index_esm_min.M.Pattern:
                return this.errorMessages.pattern();
        }
        return error;
    }
    resetState() { }
    connectedCallback() {
        this.resetState();
    }
    componentWillLoad() {
        this.useExternal = !!customElements.get('bp-sdk-external-errors');
        customElements.whenDefined('bp-sdk-external-errors').then(() => {
            this.useExternal = true;
        });
    }
    render() {
        return [this.useExternal && this.renderExternal(), !this.useExternal && this.renderInternal()];
    }
    renderExternal() {
        return (index.h("bp-sdk-external-errors", { answerId: this.answerId, errorMessages: this.errorMessages, errors: this.errors, errorText: this.errorText, fieldType: this.fieldType, maxDate: this.maxDate, max: this.max, minDate: this.minDate, min: this.min, pattern: this.pattern, questionId: this.questionId }));
    }
    renderInternal() {
        return (index.h("div", { class: "bp-sdk-errors__container" }, this.errorText && (index.h("span", { "aria-live": "polite", id: `bp-sdk-error-${this.answerId}-text`, class: `bp-sdk-errors-text bp-sdk-errors-text-${this.answerId}` }, this.errorText)), !this.errorText && (index.h("ul", { class: "bp-sdk-errors__list" }, this.errors.map((error) => (index.h("li", { "aria-live": "polite", id: `bp-sdk-errors__${this.answerId}-${error}`, class: `bp-sdk-errors__list-item bp-sdk-errors__list-item-${this.answerId}` }, this.transformError(error))))))));
    }
};
BpSdkErrors.style = BpSdkErrorsStyle0;

const bpSdkErrorsContainerCss = "";
const BpSdkErrorsContainerStyle0 = bpSdkErrorsContainerCss;

const BpSdkErrorsContainer = class {
    constructor(hostRef) {
        index.registerInstance(this, hostRef);
        this.answerId = undefined;
        this.questionId = undefined;
        this.min = undefined;
        this.minDate = undefined;
        this.max = undefined;
        this.maxDate = undefined;
        this.fieldType = undefined;
        this.pattern = undefined;
        this.errors = [];
        this.errorText = undefined;
        this.errorMessages = BpSdkErrorsContainer.DEFAULT_ERROR_MESSAGES;
        this.useExternal = false;
    }
    resetState() { }
    connectedCallback() {
        this.resetState();
    }
    componentWillLoad() {
        this.useExternal = !!customElements.get('bp-sdk-external-errors-container');
        customElements.whenDefined('bp-sdk-external-errors-container').then(() => {
            this.useExternal = true;
        });
    }
    render() {
        return [this.useExternal && this.renderExternal(), !this.useExternal && this.renderInternal()];
    }
    renderExternal() {
        return (index.h("bp-sdk-external-errors-container", { answerId: this.answerId, errorText: this.errorText, errorMessages: this.errorMessages, errors: this.errors, fieldType: this.fieldType, maxDate: this.maxDate, max: this.max, minDate: this.minDate, min: this.min, pattern: this.pattern, questionId: this.questionId }));
    }
    renderInternal() {
        return (index.h("bp-sdk-errors", { answerId: this.answerId, questionId: this.questionId, fieldType: this.fieldType, min: this.min, max: this.max, minDate: this.minDate, maxDate: this.maxDate, pattern: this.pattern, errorMessages: this.errorMessages, errors: this.errors, errorText: this.errorText }));
    }
};
BpSdkErrorsContainer.DEFAULT_ERROR_MESSAGES = {
    value: (min, max) => {
        if (min != null && max != null) {
            return `Please select a value in range of ${min} to ${max}.`;
        }
        else if (min != null) {
            return `Please select a value of ${min} or larger.`;
        }
        else {
            return `Please select a value of ${min} or smaller.`;
        }
    },
    length: (min, max) => {
        if (min != null && min === max) {
            return `Please rephrase your answer in ${min} characters.`;
        }
        else if (min != null && max != null) {
            return `Please rephrase your answer in ${min}-${max} characters.`;
        }
        else if (min != null) {
            return `Please rephrase your answer in more than ${min} characters.`;
        }
        else {
            return `Please rephrase your answer in less than ${max} characters.`;
        }
    },
    date: (min, max) => {
        if (min != null && max != null) {
            const range = min === max ? `of ${min}` : `between ${min} and ${max}`;
            return `Please select a date ${range}.`;
        }
        else if (min != null) {
            return `Please select a date after ${min}.`;
        }
        else {
            return `Please select a date before ${max}.`;
        }
    },
    required: () => 'An answer is required for this question.',
    pattern: () => 'Input does not look correct',
};
BpSdkErrorsContainer.style = BpSdkErrorsContainerStyle0;

exports.bp_sdk_errors = BpSdkErrors;
exports.bp_sdk_errors_container = BpSdkErrorsContainer;
