import { __decorate, __metadata } from "tslib";
import '@material/mwc-button';
import '@operato/i18n/ox-i18n.js';
import '../../components/profile-component';
import { html } from 'lit';
import { customElement, query } from 'lit/decorators.js';
import { i18next } from '@operato/i18n';
import { AbstractAuthPage } from '../../components/abstract-auth-page';
let ForgotPassword = class ForgotPassword extends AbstractAuthPage {
    get pageName() {
        return 'forgot password';
    }
    get actionUrl() {
        return '/auth/forgot-password';
    }
    get formfields() {
        var _a;
        const email = ((_a = this.data) === null || _a === void 0 ? void 0 : _a.email) || '';
        return html `
      <input id="email" name="email" type="hidden" required .value=${email} />
      <div class="field">
        <mwc-textfield
          name="email"
          type="email"
          label=${String(i18next.t('label.email'))}
          .value=${email}
          required
          @input=${e => {
            this.emailInput.value = e.target.value;
        }}
        ></mwc-textfield>
      </div>
      <mwc-button id="submit-button" class="ui button" type="submit" raised @click=${e => this._onSubmit(e)}>
        <ox-i18n msgid="button.submit"></ox-i18n>
      </mwc-button>
    `;
    }
    get links() {
        return html `
      <a class="link" href="/auth/signin">
        <mwc-button><ox-i18n msgid="field.sign in"></ox-i18n></mwc-button>
      </a>
    `;
    }
    async submit() {
        var timer;
        var formData = new FormData(this.formEl);
        try {
            var controller = new AbortController();
            var signal = controller.signal;
            this.button.disabled = true;
            timer = setTimeout(() => {
                controller.abort();
                throw new Error('timeout');
            }, 30 * 1000);
            var response = await fetch('/auth/forgot-password', {
                credentials: 'include',
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json'
                },
                body: JSON.stringify(Object.fromEntries(formData.entries())),
                signal
            });
            this.showSnackbar({
                message: await response.text(),
                level: response.ok ? 'info' : 'error'
            });
        }
        catch (e) {
        }
        finally {
            this.button.disabled = false;
            clearTimeout(timer);
        }
    }
    showSnackbar({ message, level }) {
        super.showSnackbar({
            level,
            message
        });
    }
};
__decorate([
    query('#email'),
    __metadata("design:type", HTMLInputElement)
], ForgotPassword.prototype, "emailInput", void 0);
__decorate([
    query('#submit-button'),
    __metadata("design:type", HTMLInputElement)
], ForgotPassword.prototype, "button", void 0);
ForgotPassword = __decorate([
    customElement('forgot-password')
], ForgotPassword);
export { ForgotPassword };
//# sourceMappingURL=forgot-password.js.map