import { r as registerInstance, c as createEvent, h, H as Host, g as getElement } from './index-baa5e267.js';
import { StringUtils, ElementIDUtils } from '@sankhyalabs/core';

const ezClassicTextAreaCss = ":host{display:flex;flex-direction:column;align-items:flex-start;box-sizing:border-box;font-family:var(--font--pattern, Arial, sans-serif);font-size:var(--font-size--default, 14px);color:var(--color--ocean-green-1000, #00281D);border:none;padding:0;--ez-classic-text-area--label-color:var(--color--ocean-green-1000, #00281D);--ez-classic-text-area--border-color-default:var(--color--gray-200, #D2D2D3);--ez-classic-text-area--border-color-focus:var(--color--gray-300, #A4A5A7);--ez-classic-text-area--border-color-success:var(--color--green-600, #157A00);--ez-classic-text-area--border-color-error:var(--color--red-600, #BD0025);--ez-classic-text-area--border-color-warning:var(--color--yellow-600, #EFB103);--ez-classic-text-area--background-color:var(--color--gray-70, #FFFFFF);--ez-classic-text-area--background-color-disabled:var(--color--gray-90, #EAEAEA);--ez-classic-text-area--text-color:var(--color--ocean-green-1000, #00281D);--ez-classic-text-area--placeholder-color:#bdbdbd;--ez-classic-text-area--icon-color:var(--color--gray-400, #77777A);--ez-classic-text-area--helptext-color:var(--color--ocean-green-1000, #00281D)}.text-area-container{display:flex;flex-direction:row;align-items:start;width:100%;border:none;border-radius:var(--border--radius-8, 8px);padding:var(--space--16, 16px);box-sizing:border-box;gap:var(--space--10, 10px);margin:var(--space--4, 4px) var(--space--2, 2px);transition:box-shadow 0.2s cubic-bezier(0.4, 0, 0.2, 1);resize:vertical;overflow:auto;background-color:var(--ez-classic-text-area--background-color)}.text-area-container,.text-area-container[data-state=\"default\"]{box-shadow:0 0 0 1px var(--ez-classic-text-area--border-color-default)}.text-area-container[data-state=\"success\"]{box-shadow:0 0 0 var(--space--2, 2px) var(--ez-classic-text-area--border-color-success)}.text-area-container[data-state=\"error\"]{box-shadow:0 0 0 var(--space--2, 2px) var(--ez-classic-text-area--border-color-error)}.text-area-container[data-state=\"warning\"]{box-shadow:0 0 0 var(--space--2, 2px) var(--ez-classic-text-area--border-color-warning)}.text-area-container:focus-within{box-shadow:0 0 0 var(--space--2, 2px) var(--ez-classic-text-area--border-color-focus)}ez-icon{min-width:var(--space--24, 24px);color:var(--ez-classic-text-area--icon-color)}textarea{flex:1;border:none;outline:none;background:transparent;height:100%;width:100%;padding:0;font-family:var(--font--pattern, Arial, sans-serif);font-size:var(--font-size--default, 14px);color:var(--color--ocean-green-1000, #00281D);text-overflow:ellipsis;min-height:calc(var(--ez-classic-text-area--min-height) - var(--space--32, 32px));resize:none;scrollbar-width:thin;color:var(--ez-classic-text-area--text-color)}.text-area-container[data-disabled=\"true\"]{cursor:not-allowed;background:var(--ez-classic-text-area--background-color-disabled);border-color:var(--ez-classic-text-area--border-color-default)}.text-area-container[data-disabled=\"true\"]>*{cursor:not-allowed}@keyframes ez-helptext-fadein{from{opacity:0;transform:translateY(-4px)}to{opacity:1;transform:translateY(0)}}span{font-size:var(--font-size--xsmall, 10px);line-height:var(--line-height--16, 16px);overflow:hidden;text-overflow:ellipsis;animation:ez-helptext-fadein 0.3s ease;color:var(--ez-classic-text-area--helptext-color)}label{display:block;width:100%;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;line-height:var(--line-height--20, 20px);color:var(--ez-classic-text-area--label-color)}.icon-clickable{cursor:pointer}.text-area-container[data-resize=\"none\"]{resize:none}.text-area-container[data-resize=\"both\"]{resize:both}.text-area-container[data-resize=\"horizontal\"]{resize:horizontal}.text-area-container[data-resize=\"vertical\"]{resize:vertical}.text-area-container::-webkit-resizer{display:none}.text-area-container::-moz-resizer{display:none}.text-area-container:not([data-resize=\"none\"]){position:relative}.text-area-container:not([data-resize=\"none\"])::after{content:'';position:absolute;bottom:var(--space--2, 2px);right:var(--space--2, 2px);width:var(--space--10, 10px);height:var(--space--10, 10px);background:linear-gradient(135deg, transparent 0% 50%, var(--ez-classic-text-area--border-color-default) 50% 58%, transparent 58% 70%, var(--ez-classic-text-area--border-color-default) 70% 78%, transparent 78% 100%);pointer-events:none}";

const EzClassicTextArea = class {
  constructor(hostRef) {
    registerInstance(this, hostRef);
    this.ezChange = createEvent(this, "ezChange", 7);
    this.ezBlur = createEvent(this, "ezBlur", 7);
    this.iconClick = createEvent(this, "iconClick", 7);
    this.name = StringUtils.generateUUID();
    this.label = '';
    this.placeholder = '';
    this.value = '';
    this.helpText = undefined;
    this.state = "default";
    this.enabled = true;
    this.readonly = false;
    this.maxlength = undefined;
    this.resize = 'vertical';
    this.leftIconName = undefined;
    this.rightIconName = undefined;
    this.rightIconTooltip = undefined;
    this.leftIconTooltip = undefined;
    this.leftIconClickable = false;
    this.rightIconClickable = false;
    this.rows = 5;
  }
  /** Aplica o foco no campo. */
  async setFocus(option) {
    if (option === null || option === void 0 ? void 0 : option.selectText) {
      this._textAreaElem.select();
    }
    if (!(option === null || option === void 0 ? void 0 : option.preventScroll)) {
      this._textAreaElem.scrollIntoView({ behavior: "smooth", block: "center" });
    }
    this._textAreaElem.focus({ preventScroll: true });
  }
  /** Remove o foco do campo. */
  async setBlur() {
    this._textAreaElem.blur();
  }
  onBlur() {
    this.ezBlur.emit(this.value);
  }
  handleInput(event) {
    const target = event.target;
    this.ezChange.emit(target.value);
  }
  ;
  handleIconClick(event, icon) {
    if (!this.enabled) {
      return;
    }
    if ((icon === "left" && !this.leftIconClickable) || (icon === "right" && !this.rightIconClickable)) {
      this.setFocus({ preventScroll: true });
      return;
    }
    event.stopPropagation();
    this.iconClick.emit({ icon });
  }
  addInfoId() {
    if (this._element) {
      ElementIDUtils.addIDInfo(this._element);
    }
    if (this._textAreaElem) {
      const dataInfo = { id: 'embedded' };
      ElementIDUtils.addIDInfo(this._textAreaElem, 'classic-text-area', dataInfo);
    }
  }
  componentDidLoad() {
    this.addInfoId();
  }
  render() {
    return (h(Host, null, this.label && (h("label", { title: this.label, htmlFor: this.name }, this.label)), h("div", { class: "text-area-container", "data-state": this.state, "data-disabled": (!this.enabled).toString(), "data-resize": this.resize, onClick: () => this.setFocus({ preventScroll: true }) }, this.leftIconName && (h("ez-icon", { iconName: this.leftIconName, title: this.leftIconTooltip, onClick: (event) => this.handleIconClick(event, "left"), class: { 'icon-clickable': this.leftIconClickable } })), h("textarea", { ref: (el) => (this._textAreaElem = el), id: this.name, name: this.name, placeholder: this.placeholder, value: this.value, disabled: !this.enabled, readOnly: this.readonly, maxLength: this.maxlength, rows: this.rows, onInput: this.handleInput.bind(this), onBlur: this.onBlur.bind(this) }), this.rightIconName && (h("ez-icon", { iconName: this.rightIconName, title: this.rightIconTooltip, onClick: (event) => this.handleIconClick(event, "right"), class: { 'icon-clickable': this.rightIconClickable } }))), this.helpText && (h("span", { title: this.helpText }, this.helpText))));
  }
  get _element() { return getElement(this); }
};
EzClassicTextArea.style = ezClassicTextAreaCss;

export { EzClassicTextArea as ez_classic_text_area };
