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.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 properties() { return {
        "forgotPasswordLabel": {
            "type": String,
            "attr": "forgot-password-label"
        },
        "forgotPasswordUrl": {
            "type": String,
            "attr": "forgot-password-url"
        },
        "host": {
            "elementRef": true
        },
        "language": {
            "type": String,
            "attr": "language"
        },
        "submitError": {
            "type": String,
            "attr": "submit-error"
        },
        "submitLabel": {
            "type": String,
            "attr": "submit-label"
        },
        "type": {
            "type": String,
            "attr": "type"
        }
    }; }
    static get events() { return [{
            "name": "formSubmit",
            "method": "formSubmit",
            "bubbles": true,
            "cancelable": true,
            "composed": true
        }]; }
    static get style() { return "/**style-placeholder:ema-login-form:**/"; }
}
