import { h } from '@stencil/core';
import { formDefinitions, TranslateService } from '@ema/core';
export class LoginForm {
    constructor() {
        this.submitLabel = 'LOGIN';
        this.forgotPasswordLabel = 'PASSWORD FORGOTTEN?';
        this.language = 'en';
        this.type = 'name-password';
        this.translate = TranslateService.instance;
    }
    componentWillLoad() {
        this.data = formDefinitions.loginForm.data.attributes;
        this.definitions = formDefinitions.loginForm.data.meta.definitions;
    }
    componentDidLoad() {
        // this.translate.registerTranslateComponents()
        this.host.getElementsByTagName('ema-form')[0].addEventListener('formSubmit', (event) => {
            this.loginHandler(event);
        });
    }
    componentDidUnload() {
        this.host.getElementsByTagName('ema-form')[0].removeEventListener('formSubmit', this.loginHandler);
    }
    loginHandler(event) {
        event.preventDefault();
        this.formSubmit.emit(event.detail);
    }
    alterForm(type) {
        if (type === 'email-password') {
            this.definitions.username.label = 'EMAIL ADDRESS';
            this.definitions.username.constraints = {
                email: {
                    message: "^" + this.translate.get('EMAIL ERROR')
                },
                presence: true,
            };
        }
    }
    render() {
        this.alterForm(this.type);
        return (h("ema-form", { "data-json": JSON.stringify(this.data), "definitions-json": JSON.stringify(this.definitions), language: this.language, "submit-label": this.submitLabel, "submit-error": this.submitError }));
    }
    static get is() { return "ema-login-form"; }
    static get originalStyleUrls() { return {
        "$": ["login-form.scss"]
    }; }
    static get styleUrls() { return {
        "$": ["login-form.css"]
    }; }
    static get properties() { return {
        "submitLabel": {
            "type": "string",
            "mutable": false,
            "complexType": {
                "original": "string",
                "resolved": "string",
                "references": {}
            },
            "required": false,
            "optional": false,
            "docs": {
                "tags": [],
                "text": ""
            },
            "attribute": "submit-label",
            "reflect": false,
            "defaultValue": "'LOGIN'"
        },
        "forgotPasswordLabel": {
            "type": "string",
            "mutable": false,
            "complexType": {
                "original": "string",
                "resolved": "string",
                "references": {}
            },
            "required": false,
            "optional": false,
            "docs": {
                "tags": [],
                "text": ""
            },
            "attribute": "forgot-password-label",
            "reflect": false,
            "defaultValue": "'PASSWORD FORGOTTEN?'"
        },
        "language": {
            "type": "string",
            "mutable": false,
            "complexType": {
                "original": "string",
                "resolved": "string",
                "references": {}
            },
            "required": false,
            "optional": false,
            "docs": {
                "tags": [],
                "text": ""
            },
            "attribute": "language",
            "reflect": false,
            "defaultValue": "'en'"
        },
        "type": {
            "type": "string",
            "mutable": false,
            "complexType": {
                "original": "string",
                "resolved": "string",
                "references": {}
            },
            "required": false,
            "optional": false,
            "docs": {
                "tags": [],
                "text": ""
            },
            "attribute": "type",
            "reflect": false,
            "defaultValue": "'name-password'"
        },
        "forgotPasswordUrl": {
            "type": "string",
            "mutable": false,
            "complexType": {
                "original": "string",
                "resolved": "string",
                "references": {}
            },
            "required": false,
            "optional": false,
            "docs": {
                "tags": [],
                "text": ""
            },
            "attribute": "forgot-password-url",
            "reflect": false
        },
        "submitError": {
            "type": "string",
            "mutable": false,
            "complexType": {
                "original": "string",
                "resolved": "string",
                "references": {}
            },
            "required": false,
            "optional": false,
            "docs": {
                "tags": [],
                "text": ""
            },
            "attribute": "submit-error",
            "reflect": false
        }
    }; }
    static get events() { return [{
            "method": "formSubmit",
            "name": "formSubmit",
            "bubbles": true,
            "cancelable": true,
            "composed": true,
            "docs": {
                "tags": [],
                "text": ""
            },
            "complexType": {
                "original": "any",
                "resolved": "any",
                "references": {}
            }
        }]; }
    static get elementRef() { return "host"; }
}
