import { proxyCustomElement, HTMLElement, createEvent, h, Host } from '@stencil/core/internal/client';
import { t as translate, a as tooltipIconSvg, g as getTranslations } from './tooltipIcon.js';
import { d as defineCustomElement$b } from './checkbox-group-input2.js';
import { d as defineCustomElement$a } from './checkbox-input2.js';
import { d as defineCustomElement$9 } from './date-input2.js';
import { d as defineCustomElement$8 } from './email-input2.js';
import { d as defineCustomElement$7 } from './number-input2.js';
import { d as defineCustomElement$6 } from './password-input2.js';
import { d as defineCustomElement$5 } from './radio-input2.js';
import { d as defineCustomElement$4 } from './select-input2.js';
import { d as defineCustomElement$3 } from './tel-input2.js';
import { d as defineCustomElement$2 } from './text-input2.js';

const toggleCheckboxInputCss = "*,*::before,*::after{padding:0;margin:0;box-sizing:border-box}.togglecheckbox{font-family:\"Roboto\";font-style:normal;font-size:15px}.togglecheckbox__wrapper{position:relative}.togglecheckbox__wrapper--flex{display:flex;gap:10px;align-items:baseline}.togglecheckbox__wrapper--relative{position:relative;display:inline}.togglecheckbox__input{transform:scale(1.307, 1.307);margin-left:2px;accent-color:var(--emfe-w-login-color-primary, var(--emfe-w-color-primary, #D0046C))}.togglecheckbox__label{font-style:inherit;font-family:inherit;font-weight:400;font-size:16px;color:var(--emfe-w-registration-typography, var(--emfe-w-color-black, #000000));line-height:1.5;cursor:pointer;padding:0}.togglecheckbox__label-text{font-size:16px}.togglecheckbox__label a{color:var(--emfe-w-login-color-primary, var(--emfe-w-color-primary, #D0046C))}.togglecheckbox__error-message{position:absolute;top:calc(100% + 5px);left:0;color:var(--emfe-w-color-error, var(--emfe-w-color-red, #ed0909))}.togglecheckbox__tooltip-icon{width:16px;height:auto}.togglecheckbox__tooltip{position:absolute;top:0;right:0;background-color:var(--emfe-w-color-white, #FFFFFF);border:1px solid var(--emfe-w-color-gray-100, #E6E6E6);color:var(--emfe-w-registration-typography, var(--emfe-w-color-black, #000000));padding:10px;border-radius:5px;opacity:0;transition:opacity 0.3s ease-in-out;z-index:10}.togglecheckbox__tooltip.visible{opacity:1}.togglecheckbox__fields-wrapper{margin-top:40px;display:flex;flex-direction:column;gap:40px}.hidden{display:none}";

const ToggleCheckboxInput = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement {
  constructor() {
    super();
    this.__registerHost();
    this.__attachShadow();
    this.sendValidityState = createEvent(this, "sendValidityState", 7);
    this.sendInputValue = createEvent(this, "sendInputValue", 7);
    /**
     * Default value for the input.
     */
    this.defaultValue = '';
    /**
     * Client custom styling via inline style
     */
    this.clientStyling = '';
    this.limitStylingAppends = false;
    this.showTooltip = false;
    this.value = '';
    this.setClientStyling = () => {
      let sheet = document.createElement('style');
      sheet.innerHTML = this.clientStyling;
      this.stylingContainer.prepend(sheet);
    };
  }
  validityStateHandler(inputStateEvent) {
    this.sendValidityState.emit(inputStateEvent);
  }
  valueHandler(inputValueEvent) {
    this.sendInputValue.emit(inputValueEvent);
  }
  handleClickOutside(event) {
    if (event.composedPath()[0] === this.tooltipIconReference)
      return;
    if (event.composedPath()[0] !== this.tooltipReference)
      this.showTooltip = false;
  }
  componentDidRender() {
    // start custom styling area
    if (!this.limitStylingAppends && this.stylingContainer) {
      if (this.clientStyling)
        this.setClientStyling();
      this.limitStylingAppends = true;
    }
    // end custom styling area
  }
  handleClick() {
    this.showFields = this.checkboxReference.checked;
    this.errorMessage = this.setErrorMessage();
    this.isValid = this.setValidity();
  }
  setValidity() {
    return this.checkboxReference.validity.valid;
  }
  setErrorMessage() {
    if (this.checkboxReference.validity.valueMissing) {
      return translate('requiredError', this.language);
    }
  }
  renderLabel() {
    return (h("label", { class: 'togglecheckbox__label', htmlFor: `${this.name}__input` }, h("div", { class: 'togglecheckbox__label-text', innerHTML: `${this.displayName} ${this.validation.mandatory ? '*' : ''}` })));
  }
  renderTooltip() {
    if (this.showTooltip) {
      return (h("div", { class: `togglecheckbox__tooltip ${this.showTooltip ? 'visible' : ''}`, ref: (el) => this.tooltipReference = el, innerHTML: this.tooltip }));
    }
    return null;
  }
  render() {
    return h("div", { class: `togglecheckbox__wrapper  ${this.name}__input`, ref: el => this.stylingContainer = el }, h("div", { class: 'togglecheckbox__wrapper--flex' }, h("input", { class: 'togglecheckbox__input', type: "checkbox", id: `${this.name}__input`, ref: (el) => this.checkboxReference = el, name: this.name, checked: this.defaultValue === "true", readOnly: this.autofilled, required: this.validation.mandatory, value: this.value, onClick: () => this.handleClick() }), this.renderLabel()), h("small", { class: 'togglecheckbox__error-message' }, this.errorMessage), h("div", { class: 'togglecheckbox__wrapper--relative' }, this.tooltip &&
      h("img", { class: 'togglecheckbox__tooltip-icon', src: tooltipIconSvg, alt: "", ref: (el) => this.tooltipIconReference = el, onClick: () => this.showTooltip = !this.showTooltip }), this.renderTooltip()), h("div", { class: `togglecheckbox__fields-wrapper ${this.showFields ? '' : 'hidden'}` }, this.options.map(subfield => {
      return h("general-input", { type: subfield.inputType, name: subfield.name, displayName: subfield.displayName, validation: subfield.validate, action: subfield.action || null, defaultValue: subfield.defaultValue, autofilled: subfield.autofill, emitValue: this.emitValue, language: this.language, "client-styling": this.clientStyling, tooltip: subfield.tooltip, placeholder: subfield.placeholder == null ? '' : subfield.placeholder });
    })));
  }
  static get style() { return toggleCheckboxInputCss; }
}, [1, "toggle-checkbox-input", {
    "name": [513],
    "displayName": [513, "display-name"],
    "defaultValue": [513, "default-value"],
    "options": [16],
    "autofilled": [516],
    "tooltip": [513],
    "validation": [16],
    "language": [513],
    "emitValue": [516, "emit-value"],
    "clientStyling": [513, "client-styling"],
    "errorMessage": [32],
    "isValid": [32],
    "limitStylingAppends": [32],
    "showTooltip": [32],
    "showFields": [32]
  }, [[4, "click", "handleClickOutside"]]]);
function defineCustomElement$1() {
  if (typeof customElements === "undefined") {
    return;
  }
  const components = ["toggle-checkbox-input", "checkbox-group-input", "checkbox-input", "date-input", "email-input", "general-input", "number-input", "password-input", "radio-input", "select-input", "tel-input", "text-input", "toggle-checkbox-input"];
  components.forEach(tagName => { switch (tagName) {
    case "toggle-checkbox-input":
      if (!customElements.get(tagName)) {
        customElements.define(tagName, ToggleCheckboxInput);
      }
      break;
    case "checkbox-group-input":
      if (!customElements.get(tagName)) {
        defineCustomElement$b();
      }
      break;
    case "checkbox-input":
      if (!customElements.get(tagName)) {
        defineCustomElement$a();
      }
      break;
    case "date-input":
      if (!customElements.get(tagName)) {
        defineCustomElement$9();
      }
      break;
    case "email-input":
      if (!customElements.get(tagName)) {
        defineCustomElement$8();
      }
      break;
    case "general-input":
      if (!customElements.get(tagName)) {
        defineCustomElement();
      }
      break;
    case "number-input":
      if (!customElements.get(tagName)) {
        defineCustomElement$7();
      }
      break;
    case "password-input":
      if (!customElements.get(tagName)) {
        defineCustomElement$6();
      }
      break;
    case "radio-input":
      if (!customElements.get(tagName)) {
        defineCustomElement$5();
      }
      break;
    case "select-input":
      if (!customElements.get(tagName)) {
        defineCustomElement$4();
      }
      break;
    case "tel-input":
      if (!customElements.get(tagName)) {
        defineCustomElement$3();
      }
      break;
    case "text-input":
      if (!customElements.get(tagName)) {
        defineCustomElement$2();
      }
      break;
    case "toggle-checkbox-input":
      if (!customElements.get(tagName)) {
        defineCustomElement$1();
      }
      break;
  } });
}

const generalInputCss = ":host{display:block;height:100%}";

const GeneralInput = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement {
  constructor() {
    super();
    this.__registerHost();
    this.__attachShadow();
    /**
     * Type the general-input should take. Can take the default HTML input values.
     */
    this.type = 'text';
    /**
     * Client custom styling via inline style
     */
    this.clientStyling = '';
    /**
     * Translations via URL
     */
    this.translationUrl = '';
  }
  connectedCallback() {
    if (this.translationUrl) {
      getTranslations(this.translationUrl);
    }
  }
  renderInput() {
    var _a;
    switch ((_a = this.type) === null || _a === void 0 ? void 0 : _a.toLowerCase()) {
      case 'text':
        return h("text-input", { name: this.name, displayName: this.displayName, validation: this.validation, defaultValue: this.defaultValue, autofilled: this.autofilled, emitValue: this.emitValue, language: this.language, isDuplicateInput: this.isDuplicateInput, "client-styling": this.clientStyling, tooltip: this.tooltip, placeholder: this.placeholder });
      case 'email':
        return h("email-input", { name: this.name, displayName: this.displayName, validation: this.validation, defaultValue: this.defaultValue, autofilled: this.autofilled, emitValue: this.emitValue, language: this.language, isDuplicateInput: this.isDuplicateInput, "client-styling": this.clientStyling, tooltip: this.tooltip, placeholder: this.placeholder });
      case 'number':
        return h("number-input", { name: this.name, displayName: this.displayName, validation: this.validation, defaultValue: this.defaultValue, autofilled: this.autofilled, emitValue: this.emitValue, language: this.language, "client-styling": this.clientStyling, tooltip: this.tooltip, placeholder: this.placeholder });
      case 'checkbox':
        return h("checkbox-input", { name: this.name, displayName: this.displayName, validation: this.validation, emitValue: this.emitValue, defaultValue: this.defaultValue, autofilled: this.autofilled, language: this.language, "client-styling": this.clientStyling, tooltip: this.tooltip });
      case 'checkboxgroup':
        return h("checkbox-group-input", { name: this.name, displayName: this.displayName, validation: this.validation, defaultValue: this.defaultValue, autofilled: this.autofilled, emitValue: this.emitValue, language: this.language, "client-styling": this.clientStyling, tooltip: this.tooltip, options: this.options });
      case 'togglecheckbox':
        return h("toggle-checkbox-input", { name: this.name, displayName: this.displayName, validation: this.validation, defaultValue: this.defaultValue, autofilled: this.autofilled, emitValue: this.emitValue, language: this.language, "client-styling": this.clientStyling, tooltip: this.tooltip, options: this.options });
      case 'datetime':
        return h("date-input", { name: this.name, displayName: this.displayName, validation: this.validation, defaultValue: this.defaultValue, autofilled: this.autofilled, emitValue: this.emitValue, language: this.language, "client-styling": this.clientStyling, tooltip: this.tooltip, placeholder: this.placeholder, dateFormat: this.dateFormat });
      case 'password':
        return h("password-input", { name: this.name, displayName: this.displayName, validation: this.validation, defaultValue: this.defaultValue, autofilled: this.autofilled, emitValue: this.emitValue, language: this.language, isDuplicateInput: this.isDuplicateInput, "client-styling": this.clientStyling, tooltip: this.tooltip, placeholder: this.placeholder });
      case 'radio':
        return h("radio-input", { name: this.name, displayName: this.displayName, optionsGroup: this.options, validation: this.validation, emitValue: this.emitValue, language: this.language, "client-styling": this.clientStyling });
      case 'tel':
        return h("tel-input", { name: this.name, action: this.action, displayName: this.displayName, validation: this.validation, defaultValue: this.defaultValue, emitValue: this.emitValue, language: this.language, autofilled: this.autofilled, "client-styling": this.clientStyling, tooltip: this.tooltip, placeholder: this.placeholder });
      case 'dropdown':
        return h("select-input", { name: this.name, action: this.action, defaultValue: this.defaultValue, displayName: this.displayName, options: this.options, validation: this.validation, emitValue: this.emitValue, autofilled: this.autofilled, language: this.language, "client-styling": this.clientStyling, tooltip: this.tooltip, placeholder: this.placeholder });
      default:
        return h("p", null, "The ", this.type, " input type is not valid");
    }
  }
  render() {
    return (h(Host, { class: `general-input--${this.name}` }, this.renderInput()));
  }
  static get style() { return generalInputCss; }
}, [1, "general-input", {
    "type": [513],
    "name": [513],
    "displayName": [513, "display-name"],
    "placeholder": [513],
    "action": [513],
    "validation": [16],
    "options": [520],
    "language": [513],
    "autofilled": [516],
    "tooltip": [513],
    "defaultValue": [520, "default-value"],
    "emitValue": [516, "emit-value"],
    "isDuplicateInput": [516, "is-duplicate-input"],
    "clientStyling": [520, "client-styling"],
    "dateFormat": [513, "date-format"],
    "translationUrl": [513, "translation-url"]
  }]);
function defineCustomElement() {
  if (typeof customElements === "undefined") {
    return;
  }
  const components = ["general-input", "checkbox-group-input", "checkbox-input", "date-input", "email-input", "general-input", "number-input", "password-input", "radio-input", "select-input", "tel-input", "text-input", "toggle-checkbox-input"];
  components.forEach(tagName => { switch (tagName) {
    case "general-input":
      if (!customElements.get(tagName)) {
        customElements.define(tagName, GeneralInput);
      }
      break;
    case "checkbox-group-input":
      if (!customElements.get(tagName)) {
        defineCustomElement$b();
      }
      break;
    case "checkbox-input":
      if (!customElements.get(tagName)) {
        defineCustomElement$a();
      }
      break;
    case "date-input":
      if (!customElements.get(tagName)) {
        defineCustomElement$9();
      }
      break;
    case "email-input":
      if (!customElements.get(tagName)) {
        defineCustomElement$8();
      }
      break;
    case "general-input":
      if (!customElements.get(tagName)) {
        defineCustomElement();
      }
      break;
    case "number-input":
      if (!customElements.get(tagName)) {
        defineCustomElement$7();
      }
      break;
    case "password-input":
      if (!customElements.get(tagName)) {
        defineCustomElement$6();
      }
      break;
    case "radio-input":
      if (!customElements.get(tagName)) {
        defineCustomElement$5();
      }
      break;
    case "select-input":
      if (!customElements.get(tagName)) {
        defineCustomElement$4();
      }
      break;
    case "tel-input":
      if (!customElements.get(tagName)) {
        defineCustomElement$3();
      }
      break;
    case "text-input":
      if (!customElements.get(tagName)) {
        defineCustomElement$2();
      }
      break;
    case "toggle-checkbox-input":
      if (!customElements.get(tagName)) {
        defineCustomElement$1();
      }
      break;
  } });
}

export { GeneralInput as G, ToggleCheckboxInput as T, defineCustomElement$1 as a, defineCustomElement as d };
