import { __esDecorate, __runInitializers } from "tslib";
import { bound } from '../../decorators/bound.js';
import { html, nothing } from 'lit';
import { DEFAULT_PASSWORD_CONFIG } from '@api-client/core/modeling/definitions/Password.js';
import { SemanticType } from '@api-client/core/modeling/Semantics.js';
import { live } from 'lit/directives/live.js';
import { renderHelp } from '../../help/render.js';
import { ifDefined } from 'lit/directives/if-defined.js';
import { TaxonomyDialog } from './TaxonomyDialog.js';
/**
 * A class that generates a dialog that allows the user to configure the taxonomy of a password.
 */
let PasswordTaxonomy = (() => {
    let _classSuper = TaxonomyDialog;
    let _instanceExtraInitializers = [];
    let _render_decorators;
    return class PasswordTaxonomy extends _classSuper {
        static {
            const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
            _render_decorators = [bound];
            __esDecorate(this, null, _render_decorators, { kind: "method", name: "render", static: false, private: false, access: { has: obj => "render" in obj, get: obj => obj.render }, metadata: _metadata }, null, _instanceExtraInitializers);
            if (_metadata) Object.defineProperty(this, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
        }
        domainElement = __runInitializers(this, _instanceExtraInitializers);
        static title = `Configure Password Taxonomy`;
        constructor(domainElement) {
            let config;
            const semantic = domainElement.semantics.find((s) => s.id === SemanticType.Password);
            if (semantic && semantic.config) {
                config = structuredClone(semantic.config);
            }
            else {
                config = {};
            }
            super(config);
            this.domainElement = domainElement;
        }
        formCallback(event) {
            const semantic = this.domainElement.semantics.find((s) => s.id === SemanticType.Password);
            if (semantic) {
                semantic.config = this.config;
            }
            else {
                this.domainElement.semantics.push({
                    id: SemanticType.Password,
                    config: this.config,
                });
            }
            this.domainElement.domain.notifyChange();
            return super.formCallback(event);
        }
        render() {
            return html `
      <div class="checkbox-group">
        ${this.renderRequireSpecialChars()} ${this.renderRequireNumbers()} ${this.renderRequireUppercase()}
        ${this.renderRequireLowercase()} ${this.renderPreventReuse()}
      </div>
      <div class="input-group">${this.renderReuseCountInput()} ${this.renderMaxAgeInput()}</div>
    `;
        }
        renderRequireSpecialChars() {
            const enabled = this.config?.requireSpecialChars ?? false;
            return html `
      <div class="row">
        <div class="input checkbox metadata">
          <ui-checkbox
            id="require-special-chars"
            .checked="${enabled}"
            name="requireSpecialChars"
            @change="${this.handleBooleanChange}"
          ></ui-checkbox>
          <div class="label">
            <label for="require-special-chars" class="body-medium">Require Special Characters</label>
            <span class="body-small meta">Users must add special characters in their passwords.</span>
          </div>
        </div>
        ${renderHelp('taxonomy', 'password:requireSpecialChars')}
      </div>
    `;
        }
        renderRequireNumbers() {
            const enabled = this.config?.requireNumbers ?? DEFAULT_PASSWORD_CONFIG.requireNumbers;
            return html `
      <div class="row">
        <div class="input checkbox metadata">
          <ui-checkbox
            id="require-numbers"
            .checked="${enabled}"
            name="requireNumbers"
            @change="${this.handleBooleanChange}"
          ></ui-checkbox>
          <div class="label">
            <label for="require-numbers" class="body-medium">Require Numbers</label>
            <span class="body-small meta">Users must add numbers to their passwords.</span>
          </div>
        </div>
        ${renderHelp('taxonomy', 'password:requireNumbers')}
      </div>
    `;
        }
        renderRequireUppercase() {
            const enabled = this.config?.requireUppercase ?? DEFAULT_PASSWORD_CONFIG.requireUppercase;
            return html `
      <div class="row">
        <div class="input checkbox metadata">
          <ui-checkbox
            id="require-uppercase"
            .checked="${enabled}"
            name="requireUppercase"
            @change="${this.handleBooleanChange}"
          ></ui-checkbox>
          <div class="label">
            <label for="require-uppercase" class="body-medium">Require Uppercase Letters</label>
            <span class="body-small meta">Users must add uppercase letters to their passwords.</span>
          </div>
        </div>
        ${renderHelp('taxonomy', 'password:requireUppercase')}
      </div>
    `;
        }
        renderRequireLowercase() {
            const enabled = this.config?.requireLowercase ?? DEFAULT_PASSWORD_CONFIG.requireLowercase;
            return html `
      <div class="row">
        <div class="input checkbox metadata">
          <ui-checkbox
            id="require-lowercase"
            .checked="${enabled}"
            name="requireLowercase"
            @change="${this.handleBooleanChange}"
          ></ui-checkbox>
          <div class="label">
            <label for="require-lowercase" class="body-medium">Require Lowercase Letters</label>
            <span class="body-small meta">Users must add lowercase letters to their passwords.</span>
          </div>
        </div>
        ${renderHelp('taxonomy', 'password:requireLowercase')}
      </div>
    `;
        }
        renderPreventReuse() {
            const enabled = this.config?.preventReuse ?? DEFAULT_PASSWORD_CONFIG.preventReuse;
            return html `
      <div class="row">
        <div class="input checkbox metadata">
          <ui-checkbox
            id="prevent-reuse"
            .checked="${enabled}"
            name="preventReuse"
            @change="${this.handleBooleanChange}"
          ></ui-checkbox>
          <div class="label">
            <label for="prevent-reuse" class="body-medium">Prevent Reuse</label>
            <span class="body-small meta">Prevents users from reusing old passwords.</span>
          </div>
        </div>
        ${renderHelp('taxonomy', 'password:preventReuse')}
      </div>
    `;
        }
        renderReuseCountInput() {
            const enabled = this.config?.preventReuse ?? DEFAULT_PASSWORD_CONFIG.preventReuse;
            if (!enabled) {
                return nothing;
            }
            const value = this.config?.preventReuseCount ?? DEFAULT_PASSWORD_CONFIG.preventReuseCount;
            return html `
      <div class="row input-row">
        <ui-outlined-text-field
          class="input"
          name="preventReuseCount"
          .value="${live(String(value))}"
          label="Reuse count history"
          required
          min="1"
          type="number"
          @change="${this.handleTextChange}"
          supportingText="Number of previous passwords to remember."
        ></ui-outlined-text-field>
        ${renderHelp('taxonomy', 'password:preventReuseCount')}
      </div>
    `;
        }
        renderMaxAgeInput() {
            const info = 'Maximum age of password in days before requiring change.';
            const value = this.config?.maxAge ?? DEFAULT_PASSWORD_CONFIG.maxAge;
            return html `
      <div class="row input-row">
        <ui-outlined-text-field
          class="input"
          name="maxAge"
          value="${ifDefined(value)}"
          label="Max age (in days)"
          min="0"
          type="number"
          @change="${this.handleTextChange}"
          .supportingText="${info}"
        ></ui-outlined-text-field>
        ${renderHelp('taxonomy', 'password:maxAge')}
      </div>
    `;
        }
    };
})();
export { PasswordTaxonomy };
//# sourceMappingURL=PasswordTaxonomy.js.map