import { __decorate, __metadata } from "tslib";
import '@material/mwc-button';
import '@material/mwc-textfield';
import '@operato/lottie-player';
import '../components/profile-component';
import '@operato/i18n/ox-i18n.js';
import '@operato/i18n/ox-i18n-selector.js';
import '@operato/layout/ox-snack-bar.js';
import { css, html, nothing } from 'lit';
import { property, query } from 'lit/decorators.js';
import { i18next } from '@operato/i18n';
import { isSafari } from '@operato/utils';
import { AUTH_STYLE_SIGN } from '../auth-style-sign';
import { generatePasswordPatternHelp, generatePasswordPatternRegExp } from '../utils/password-rule';
import { AbstractAuthPage } from './abstract-auth-page';
export class AbstractPasswordReset extends AbstractAuthPage {
    constructor() {
        super(...arguments);
        this.passwordPattern = '';
        this.passwordHelp = '';
    }
    render() {
        var { icon, title, description } = this.applicationMeta;
        const { disableUserFavoredLanguage, languages } = this.data || {};
        return html `
      <div class="wrap">
        <div class="auth-brand">
          <img src=${icon} />
          <strong class="name">${title}</strong>
          <span class="welcome-msg">${description}</span>
        </div>

        <div class="auth-form">
          <h3><ox-i18n msgid="title.${this.title}"></ox-i18n></h3>
          <form
            id="form"
            action="${this.actionUrl}"
            method="post"
            @keypress=${e => {
            if (e.key == 'Enter')
                this._onSubmit(e);
        }}
          >
            <input name="token" type="hidden" .value=${this.token || ''} required />
            <div class="field">
              <mwc-textfield
                name="password"
                type="password"
                label=${String(i18next.t('label.password'))}
                .pattern=${this.passwordPattern}
                helper=${this.passwordHelp}
                helperPersistent
                @input=${e => {
            var val = e.target.value;
            this.confirmPass.setAttribute('pattern', val.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '[$&]'));
        }}
                required
              ></mwc-textfield>
            </div>

            <div class="field">
              <mwc-textfield
                id="confirm-password"
                name="confirm-password"
                type="password"
                label=${String(i18next.t('field.confirm password'))}
                required
              ></mwc-textfield>
            </div>

            <mwc-button id="submit-button" type="submit" raised @click=${e => this._onSubmit(e)}>
              <ox-i18n msgid="${this.submitButtonLabel}"></ox-i18n>
            </mwc-button>

            ${!disableUserFavoredLanguage
            ? html ` <div id="locale-area">
                  <label for="locale-selector"><mwc-icon>language</mwc-icon></label>
                  <ox-i18n-selector
                    id="locale-selector"
                    value=${i18next.language || 'en-US'}
                    .languages=${languages}
                    @change=${e => {
                var locale = e.detail;
                if (!locale)
                    return;
                i18next.changeLanguage(locale);
            }}
                  ></ox-i18n-selector>
                </div>`
            : nothing}
          </form>
        </div>
      </div>
      <ox-snack-bar id="snackbar" level="error" .message=${this.message}></ox-snack-bar>

      ${isSafari()
            ? html ``
            : html `
            <div class="lottie-container">
              <lottie-player autoplay loop src="../../assets/images/background-animation.json"></lottie-player>
            </div>
          `}
    `;
    }
    updated(changed) {
        super.updated(changed);
        if (changed.has('data')) {
            this.token = this.data.token;
        }
        if (changed.has('message')) {
            if (!this.message) {
                this.hideSnackbar();
            }
            else {
                this.showSnackbar({
                    timer: -1
                });
            }
        }
    }
    languageUpdated() {
        this.passwordPattern = generatePasswordPatternRegExp(this.data.passwordRule).source;
        this.passwordHelp = generatePasswordPatternHelp(this.data.passwordRule);
    }
    async submit() {
        this.formEl.submit();
    }
}
AbstractPasswordReset.styles = [
    css `
      :host {
        position: relative;
        overflow: hidden;

        display: flex;
        flex-direction: row;

        width: 100vw;
        height: 100vh;
        height: 100dvh;
      }

      @media print {
        :host {
          width: 100%;
          height: 100%;
          min-height: 100vh;
          min-height: 100dvh;
        }
      }
    `,
    AUTH_STYLE_SIGN
];
__decorate([
    property({ type: Object }),
    __metadata("design:type", Object)
], AbstractPasswordReset.prototype, "data", void 0);
__decorate([
    property({ type: String }),
    __metadata("design:type", String)
], AbstractPasswordReset.prototype, "token", void 0);
__decorate([
    query('#confirm-password'),
    __metadata("design:type", HTMLElement)
], AbstractPasswordReset.prototype, "confirmPass", void 0);
//# sourceMappingURL=abstract-password-reset.js.map