// #region Imports
import { html } from '../../../../Dom/Html';
import { Icons } from '../../../../Resources/Icons';
import { classMap, ifDefined, live, when } from '../../../Directives/Directives';
import { ifNonEmpty } from '../../../Directives/IfNonEmpty';
import { ifNonZero } from '../../../Directives/IfNonZero';
import { Appearance } from '../../../Types/Appearance';
import { Size } from '../../../Types/Size';
import { Variant } from '../../../Types/Variant';
// #endregion
/**
 * @public
 */
export function textBoxElementTemplate(e) {
    const formattedValue = () => e.formatter ? e.formatter(e.value) : e.value;
    return html `
        ${when(!e.disabled, () => html `
        <mosaik-focus-ring part="focusRing"
                           .variant="${e.invalid ? Variant.Danger : e.variant}"
                           .visible="${e.isFocused}"
                           .controlled="${'manual'}"
                           @connected="${(evt) => evt.target.attach(e)}"></mosaik-focus-ring>
        `)}
        <div part="prefix"
             ?hidden="${!e.hasSlotContent('prefix')}">
            <slot name="prefix"></slot>
        </div>
        <div part="inner"
             class="${classMap({ prefix: e.hasPrefix, suffix: e.hasSuffix })}">
            ${when(e.label, () => html `
            <label part="label"
                   for="input"
                   class="${classMap({ floating: e.value || e.isFocused })}">${e.label}</label>
            `)}
            ${when(e.multiline, () => html `
            <textarea part="input"
                      id="input"
                      name="${ifNonEmpty(e.name)}"
                      placeholder="${ifNonEmpty(e.isFocused || !e.label ? e.placeholder : '')}"
                      tabindex="${e.tabIndex}"
                      autocomplete="${ifDefined(e.autocomplete ? 'on' : 'off')}"
                      inputmode="${ifNonEmpty(e.keyboard)}"
                      rows="${e.multilineRows}"
                      spellcheck="${ifDefined(e.spellcheck ? 'true' : 'false')}"
                      aria-invalid="${ifDefined(e.invalid)}"
                      .value="${live(formattedValue())}"
                      ?readonly="${e.readonly}"
                      ?disabled="${e.disabled}"
                      ?required="${e.required}"
                      ?autofocus="${e.autofocus}"
                      @change="${(x) => e.onChange(x)}"
                      @input="${(x) => e.onInput(x)}"
                      @focus="${(x) => e.onFocus(x)}"
                      @blur="${(x) => e.onBlur(x)}"></textarea>
            `, () => html `
            <input part="input"
                   id="input"
                   name="${ifNonEmpty(e.name)}"
                   type="${ifNonEmpty(e.type)}"
                   pattern="${ifNonEmpty(e.pattern)}"
                   placeholder="${ifNonEmpty(e.isFocused || !e.label ? e.placeholder : '')}"
                   tabindex="${e.tabIndex}"
                   autocomplete="${ifDefined(e.autocomplete ? 'on' : 'off')}"
                   inputmode="${ifNonEmpty(e.keyboard)}"
                   minlength="${ifNonZero(e.minlength)}"
                   maxlength="${ifNonZero(e.maxlength)}"
                   spellcheck="${ifDefined(e.spellcheck ? 'true' : 'false')}"
                   aria-invalid="${ifDefined(e.invalid)}"
                   .value="${live(formattedValue())}"
                   ?readonly="${e.readonly}"
                   ?disabled="${e.disabled}"
                   ?required="${e.required}"
                   ?autofocus="${e.autofocus}"
                   @change="${(x) => e.onChange(x)}"
                   @input="${(x) => e.onInput(x)}"
                   @focus="${(x) => e.onFocus(x)}"
                   @blur="${(x) => e.onBlur(x)}"/>
            `)}
        </div>
        ${when(e.isBusy, () => html `
        <mosaik-progress-ring part="progressRing"
                              .thickness="${'2px'}"
                              .radius="${'12px'}"
                              .variant="${e.variant}"
                              .isIndeterminate="${true}"
                              ?disabled="${e.disabled}"></mosaik-progress-ring>
        `)}
        ${when(e?.isClearableFn ? e?.isClearableFn() : !e.disabled && !e.readonly && e.value && e.isClearable && !e.isBusy, () => html `
        <mosaik-button part="clear"
                       tabindex="-1"
                       .appearance="${Appearance.Plain}"
                       .icon="${Icons.clear}"
                       .size="${Size.Small}"
                       .iconSize="${Size.Medium}"
                       @click="${(x) => e.onClear(x)}"></mosaik-button>
        `)}
        <div part="suffix"
             ?hidden="${!e.hasSlotContent('suffix')}">
            <slot name="suffix"></slot>
        </div>
    `;
}
//# sourceMappingURL=TextBoxElementTemplate.js.map