import { r as registerInstance, e as createEvent, h, g as getElement } from './index-e9c7ceaa.js';
import { ElementIDUtils } from '@sankhyalabs/core';
import { F as FilterItemType } from './filter-item-type.enum-d45e026f.js';
import { F as FilterNumberVariation } from './filterNumberVariation-8cee02ea.js';
import { E as EPresentationMode } from './presentationMode-783bbf9d.js';

const SnkFilterPeriod = class {
  constructor(hostRef) {
    registerInstance(this, hostRef);
    this.valueChanged = createEvent(this, "valueChanged", 7);
    this._startIntervalLabel = 'Inicial';
    this._endIntervalLabel = 'Final';
    this._toLabel = 'até';
    this.config = undefined;
    this.getMessage = undefined;
    this.value = undefined;
    this.presentationMode = EPresentationMode.CHIP;
    this.errorMessage = undefined;
  }
  /**
   * Emitido quando acontece a alteração de valor do componente snk-filter-number
   */
  ezInputListener(evt) {
    this.errorMessage = undefined;
    const value = evt.detail;
    if (this.getVariation() === FilterNumberVariation.INTERVAL) {
      if (evt.target === this._startInterval && !isNaN(value)) {
        this.value = Object.assign(this.value, { start: value });
      }
      if (evt.target === this._endInterval && !isNaN(value)) {
        this.value = Object.assign(this.value, { end: value });
      }
      this.valueChanged.emit(this.value);
      return;
    }
    this.value = value;
    this.valueChanged.emit(this.value);
  }
  /**
   * Exibe o componente snk-filter-number
   */
  async show() {
    if (this.getVariation() === FilterNumberVariation.INTERVAL) {
      this._startInterval.setFocus();
      return;
    }
    this._numberElement.setFocus();
  }
  /**
   * Define o foco no componente snk-filter-number
   */
  async setFocus() {
    if (this.getVariation() === FilterNumberVariation.INTERVAL) {
      await this._startInterval.setFocus();
      return;
    }
    await this._numberElement.setFocus();
  }
  /**
   * Limpa o valor do componente restaurando o valor original da configuração.
   */
  async clearValue() {
    var _a, _b;
    this.value = this.config.value;
    if (this.getVariation() === FilterNumberVariation.INTERVAL) {
      const intervalValue = this.config.value;
      if (this._startInterval) {
        this._startInterval.value = (_a = intervalValue === null || intervalValue === void 0 ? void 0 : intervalValue.start) !== null && _a !== void 0 ? _a : null;
      }
      if (this._endInterval) {
        this._endInterval.value = (_b = intervalValue === null || intervalValue === void 0 ? void 0 : intervalValue.end) !== null && _b !== void 0 ? _b : null;
      }
    }
    else if (this._numberElement) {
      this._numberElement.value = this.config.value;
    }
  }
  getIntervalValue(prop) {
    const objValue = this.value ? this.value[prop] : null;
    return objValue !== null && objValue !== void 0 ? objValue : null;
  }
  buildLabel() {
    if (this.presentationMode === EPresentationMode.CHIP) {
      return h("label", { class: "ez-text ez-text--medium ez-text--primary ez-margin--medium" }, this._toLabel);
    }
  }
  getVariation() {
    var _a, _b;
    return (_b = (_a = this.config.props) === null || _a === void 0 ? void 0 : _a.variation) !== null && _b !== void 0 ? _b : FilterNumberVariation.DEFAULT;
  }
  componentWillLoad() {
    if (this.getMessage) {
      this._startIntervalLabel = this.getMessage('snkFilterBar.labelStart');
      this._endIntervalLabel = this.getMessage('snkFilterBar.labelEnd');
      this._toLabel = this.getMessage('snkFilterBar.labelTo');
    }
  }
  componentDidLoad() {
    if (this._element) {
      ElementIDUtils.addIDInfo(this._element, 'filterContentEditor');
    }
  }
  render() {
    var _a, _b, _c;
    if (!this.config || this.config.type !== FilterItemType.NUMBER) {
      return undefined;
    }
    if (this.getVariation() === FilterNumberVariation.INTERVAL) {
      return (h("ez-tooltip", { active: this.config.enabled === false, message: this.config.disabledMessage, type: 'warning' }, h("div", { class: "ez-col ez-col--nowrap" }, h("ez-number-input", { id: `${this.config.id}_start`, class: this.presentationMode === EPresentationMode.MODAL ? 'ez-padding-right--medium' : '', label: this._startIntervalLabel, ref: ref => this._startInterval = ref, value: this.getIntervalValue("start"), enabled: this.config.enabled, precision: (_a = this.config.props) === null || _a === void 0 ? void 0 : _a.precision, errorMessage: this.errorMessage }), this.buildLabel(), h("ez-number-input", { id: `${this.config.id}_end`, label: this._endIntervalLabel, ref: ref => this._endInterval = ref, value: this.getIntervalValue("end"), enabled: this.config.enabled, precision: (_b = this.config.props) === null || _b === void 0 ? void 0 : _b.precision, errorMessage: this.errorMessage }))));
    }
    return (h("ez-tooltip", { active: this.config.enabled === false, message: this.config.disabledMessage, type: 'warning' }, h("ez-number-input", { id: this.config.id, label: this.config.label, ref: ref => this._numberElement = ref, value: this.config.value, precision: (_c = this.config.props) === null || _c === void 0 ? void 0 : _c.precision, enabled: this.config.enabled, errorMessage: this.errorMessage })));
  }
  get _element() { return getElement(this); }
};

export { SnkFilterPeriod as snk_filter_number };
