import { T as TailwindStyledElement, x, A } from '../../index-8c5a9941.js';
import { n, e } from '../../query-assigned-elements-1c8c9e90.js';
import { t } from '../../state-b9ca4e74.js';
import { c as ce } from '../../index-ca8e900d.js';
import '../../tailwind-config.js';
import { c as cn } from '../../cn-b54dcc61.js';
import '../lukso-icon/index.js';
import '../../bundle-mjs-fbc6e2a8.js';
import '../../style-map-1ee93d7f.js';
import '../../directive-2bb7789e.js';

const style = ":host {\n\n    display: inline-flex\n}\n\n:host([is-full-width]) {\n\n    display: flex;\n\n    width: 100%\n}";

var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __decorateClass = (decorators, target, key, kind) => {
  var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
    if (decorator = decorators[i])
      result = (kind ? decorator(target, key, result) : decorator(result)) || result;
  if (kind && result)
    __defProp(target, key, result);
  return result;
};
const FOCUS_DELAY_MS = 10;
let LuksoTextarea = class extends TailwindStyledElement(style) {
  constructor() {
    super(...arguments);
    this.value = "";
    this.name = "";
    this.placeholder = "";
    this.label = "";
    this.id = "";
    this.ref = void 0;
    this.description = "";
    this.error = "";
    this.customClass = "";
    this.isFullWidth = false;
    this.isReadonly = false;
    this.isDisabled = false;
    this.autofocus = false;
    this.borderless = false;
    this.isNonResizable = false;
    this.keepFocusOnEscape = false;
    this.size = "medium";
    this.rows = 4;
    this.hasFocus = false;
    this.hasHighlight = false;
    this.styles = ce({
      slots: {
        wrapper: "group flex",
        input: `bg-neutral-100 border-solid placeholder:text-neutral-70 w-full
        outline-none transition transition-all duration-150 appearance-none`
      },
      variants: {
        hasError: {
          true: {
            input: "border-red-85"
          },
          false: {
            input: "border-neutral-90"
          }
        },
        hasHighlight: {
          true: {
            input: "border-neutral-35"
          }
        },
        borderless: {
          true: { input: "border-0" },
          false: { input: "border" }
        },
        isReadonly: {
          true: { input: "cursor-not-allowed" }
        },
        isDisabled: {
          true: {
            input: "text-neutral-60 cursor-not-allowed"
          },
          false: { input: "text-neutral-20" }
        },
        isFullWidth: {
          true: { wrapper: "w-full" },
          false: { wrapper: "w-[350px]" }
        },
        size: {
          small: {
            input: "min-h-[28px] px-2 py-1 paragraph-inter-12-regular rounded-8"
          },
          medium: {
            input: "min-h-[48px] px-4 py-3 paragraph-inter-14-regular rounded-12"
          }
        },
        isNonResizable: {
          true: {
            input: "resize-none"
          }
        }
      },
      compoundVariants: [
        {
          isFullWidth: false,
          size: "small",
          class: { wrapper: "w-[210px]" }
        },
        {
          hasHighlight: true,
          hasError: true,
          class: {
            input: "border-red-65"
          }
        }
      ]
    });
  }
  connectedCallback() {
    super.connectedCallback();
    if (this.autofocus) {
      setTimeout(() => {
        const textarea = this.shadowRoot?.querySelector("textarea");
        textarea?.focus();
      }, FOCUS_DELAY_MS);
    }
  }
  inputTemplate(styles) {
    return x`
      <textarea
        name=${this.name ? this.name : A}
        placeholder=${this.placeholder ? this.placeholder : A}
        ref=${this.ref ? this.ref : A}
        id=${this.id ? this.id : A}
        rows=${this.rows}
        data-testid=${this.name ? `textarea-${this.name}` : "textarea"}
        ?autofocus=${this.autofocus}
        ?readonly=${this.isReadonly ? true : void 0}
        ?disabled=${this.isDisabled ? true : void 0}
        class=${cn(styles, this.customClass)}
        @focus=${this.handleFocus}
        @input=${this.handleInput}
        @change=${this.handleChange}
        @blur=${this.handleBlur}
        @keyup=${this.handleKeyUp}
        @keydown=${this.handleKeyDown}
        @keypress=${this.handleKeyPress}
        @mouseenter=${this.handleMouseOver}
        @mouseleave=${this.handleMouseOut}
        @click=${this.handleInputClick}
      >
${this.value}</textarea
      >
    `;
  }
  labelTemplate() {
    return x`
      <label
        for=${this.name}
        class="heading-inter-14-bold text-neutral-20 pb-2 block"
        >${this.label}</label
      >
    `;
  }
  descriptionTemplate() {
    return x`
      <div class="paragraph-inter-12-regular text-neutral-20 pb-2">
        ${this.description ?? A}
      </div>
    `;
  }
  errorTemplate() {
    return x`<div class="paragraph-inter-12-regular text-red-65 pt-2">
      ${this.error}
    </div>`;
  }
  handleFocus() {
    if (!this.isReadonly && !this.isDisabled) {
      this.hasFocus = true;
      this.hasHighlight = true;
    }
  }
  async handleBlur(event) {
    this.hasFocus = false;
    this.hasHighlight = false;
    await this.updateComplete;
    const target = event.target;
    const blurEvent = new CustomEvent("on-blur", {
      detail: {
        value: target?.value,
        event
      },
      bubbles: false,
      composed: true
    });
    this.dispatchEvent(blurEvent);
  }
  async handleChange(event) {
    await this.updateComplete;
    const target = event.target;
    const changeEvent = new CustomEvent("on-change", {
      detail: {
        value: target?.value,
        event
      },
      bubbles: false,
      composed: true
    });
    this.dispatchEvent(changeEvent);
  }
  async handleInput(event) {
    const target = event.target;
    this.value = target?.value;
    await this.updateComplete;
    const changeEvent = new CustomEvent("on-input", {
      detail: {
        value: target?.value,
        event
      },
      bubbles: false,
      composed: true
    });
    this.dispatchEvent(changeEvent);
  }
  async handleKeyUp(event) {
    await this.updateComplete;
    const target = event.target;
    const keyEvent = new CustomEvent("on-key-up", {
      detail: {
        value: target?.value,
        event
      },
      bubbles: true,
      composed: true
    });
    this.dispatchEvent(keyEvent);
    if (event.key === "Escape" && !this.keepFocusOnEscape) {
      this.blur();
    }
  }
  async handleKeyDown(event) {
    await this.updateComplete;
    const target = event.target;
    const keyEvent = new CustomEvent("on-key-down", {
      detail: {
        value: target.value,
        event
      },
      bubbles: true,
      composed: true
    });
    this.dispatchEvent(keyEvent);
  }
  async handleKeyPress(event) {
    await this.updateComplete;
    const target = event.target;
    const keyEvent = new CustomEvent("on-key-press", {
      detail: {
        value: target?.value,
        event
      },
      bubbles: true,
      composed: true
    });
    this.dispatchEvent(keyEvent);
  }
  handleMouseOver() {
    if (!this.isReadonly && !this.isDisabled) {
      this.hasHighlight = true;
    }
  }
  handleMouseOut() {
    if (!this.hasFocus) {
      this.hasHighlight = false;
    }
  }
  async handleInputClick(event) {
    await this.updateComplete;
    const target = event.target;
    const clickEvent = new CustomEvent("on-input-click", {
      detail: {
        value: target.value,
        event
      },
      bubbles: false,
      composed: true
    });
    this.dispatchEvent(clickEvent);
  }
  render() {
    const { wrapper, input } = this.styles({
      hasError: this.error !== "",
      hasHighlight: this.hasHighlight,
      borderless: this.borderless,
      isReadonly: this.isReadonly,
      isDisabled: this.isDisabled,
      isFullWidth: this.isFullWidth,
      size: this.size,
      isNonResizable: this.isNonResizable
    });
    return x`
      <div class="w-[inherit]">
        ${this.label ? this.labelTemplate() : A}
        ${this.description ? this.descriptionTemplate() : A}
        <div class=${wrapper()}>
          <div class="relative w-[inherit] flex">
            ${this.inputTemplate(input())}
          </div>
        </div>
        ${this.error ? this.errorTemplate() : A}
      </div>
    `;
  }
};
__decorateClass([
  n({ type: String })
], LuksoTextarea.prototype, "value", 2);
__decorateClass([
  n({ type: String })
], LuksoTextarea.prototype, "name", 2);
__decorateClass([
  n({ type: String })
], LuksoTextarea.prototype, "placeholder", 2);
__decorateClass([
  n({ type: String })
], LuksoTextarea.prototype, "label", 2);
__decorateClass([
  n({ type: String })
], LuksoTextarea.prototype, "id", 2);
__decorateClass([
  n({ type: String })
], LuksoTextarea.prototype, "ref", 2);
__decorateClass([
  n({ type: String })
], LuksoTextarea.prototype, "description", 2);
__decorateClass([
  n({ type: String })
], LuksoTextarea.prototype, "error", 2);
__decorateClass([
  n({ type: String, attribute: "custom-class" })
], LuksoTextarea.prototype, "customClass", 2);
__decorateClass([
  n({ type: Boolean, attribute: "is-full-width" })
], LuksoTextarea.prototype, "isFullWidth", 2);
__decorateClass([
  n({ type: Boolean, attribute: "is-readonly" })
], LuksoTextarea.prototype, "isReadonly", 2);
__decorateClass([
  n({ type: Boolean, attribute: "is-disabled" })
], LuksoTextarea.prototype, "isDisabled", 2);
__decorateClass([
  n({ type: Boolean })
], LuksoTextarea.prototype, "autofocus", 2);
__decorateClass([
  n({ type: Boolean })
], LuksoTextarea.prototype, "borderless", 2);
__decorateClass([
  n({ type: Boolean, attribute: "is-non-resizable" })
], LuksoTextarea.prototype, "isNonResizable", 2);
__decorateClass([
  n({ type: Boolean, attribute: "keep-focus-on-escape" })
], LuksoTextarea.prototype, "keepFocusOnEscape", 2);
__decorateClass([
  n({ type: String })
], LuksoTextarea.prototype, "size", 2);
__decorateClass([
  n({ type: Number })
], LuksoTextarea.prototype, "rows", 2);
__decorateClass([
  t()
], LuksoTextarea.prototype, "hasFocus", 2);
__decorateClass([
  t()
], LuksoTextarea.prototype, "hasHighlight", 2);
LuksoTextarea = __decorateClass([
  e("lukso-textarea")
], LuksoTextarea);

export { LuksoTextarea };
