import { h } from "@stencil/core";
export class BpSdkErrorsContainer {
    constructor() {
        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 (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 (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 }));
    }
    static get is() { return "bp-sdk-errors-container"; }
    static get originalStyleUrls() {
        return {
            "$": ["bp-sdk-errors-container.css"]
        };
    }
    static get styleUrls() {
        return {
            "$": ["bp-sdk-errors-container.css"]
        };
    }
    static get properties() {
        return {
            "answerId": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "Answer id"
                },
                "attribute": "answer-id",
                "reflect": false
            },
            "questionId": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "Question Id"
                },
                "attribute": "question_id",
                "reflect": false
            },
            "min": {
                "type": "number",
                "mutable": false,
                "complexType": {
                    "original": "number",
                    "resolved": "number",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "minimum value"
                },
                "attribute": "min_value",
                "reflect": false
            },
            "minDate": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "minimum date"
                },
                "attribute": "min_date",
                "reflect": false
            },
            "max": {
                "type": "number",
                "mutable": false,
                "complexType": {
                    "original": "number",
                    "resolved": "number",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "maximum value"
                },
                "attribute": "max_value",
                "reflect": false
            },
            "maxDate": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "maximum date"
                },
                "attribute": "max_date",
                "reflect": false
            },
            "fieldType": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "field type"
                },
                "attribute": "field_type",
                "reflect": false
            },
            "pattern": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "Regex pattern to match"
                },
                "attribute": "pattern",
                "reflect": false
            },
            "errors": {
                "type": "unknown",
                "mutable": false,
                "complexType": {
                    "original": "string[]",
                    "resolved": "string[]",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "Error messages"
                },
                "defaultValue": "[]"
            },
            "errorText": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "Error text"
                },
                "attribute": "error_text",
                "reflect": false
            },
            "errorMessages": {
                "type": "unknown",
                "mutable": false,
                "complexType": {
                    "original": "IErrorMessages",
                    "resolved": "IErrorMessages",
                    "references": {
                        "IErrorMessages": {
                            "location": "import",
                            "path": "@boldpenguin/sdk-types",
                            "id": "../sdk-types/dist/types.d.ts::IErrorMessages"
                        }
                    }
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "Error messages function map"
                },
                "defaultValue": "BpSdkErrorsContainer.DEFAULT_ERROR_MESSAGES"
            }
        };
    }
    static get states() {
        return {
            "useExternal": {}
        };
    }
}
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',
};
