'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

const index = require('./index-17105557.js');
const core = require('@sankhyalabs/core');
const filterItemType_enum = require('./filter-item-type.enum-a7ffdaa6.js');
const presentationMode = require('./presentationMode-52ec3bdd.js');

const SnkFilterBinarySelect = class {
  constructor(hostRef) {
    index.registerInstance(this, hostRef);
    this.valueChanged = index.createEvent(this, "valueChanged", 7);
    this._noOptionValue = 'NO_VALUE';
    this._radioButtonValue = undefined;
    this.value = undefined;
    this.config = undefined;
    this.presentationMode = presentationMode.EPresentationMode.CHIP;
    this.errorMessage = undefined;
  }
  isSelected(option) {
    return this.value == undefined || this.value === option;
  }
  /**
   * Emitido quando acontece a alteração de valor do componente snk-filter-binary-select
   */
  ezChangeListener(evt) {
    this.errorMessage = undefined;
    if (this.presentationMode === presentationMode.EPresentationMode.MODAL) {
      if (!evt.detail) {
        this.assertCheckedOption(evt.target);
      }
      this.updateValue();
      return;
    }
    this.value = evt.detail === this._noOptionValue ? undefined : evt.detail;
    this._radioButtonValue = evt.detail;
  }
  /**
   * Redefine os valores padrão do componente.
   */
  async resetValues() {
    this.ezChangeListener({ detail: this._noOptionValue });
  }
  /**
   * Limpa o valor do componente restaurando o valor original da configuração.
   */
  async clearValue() {
    this.value = this.config.value;
    this._radioButtonValue = this.value || this._noOptionValue;
  }
  /**
   * Define o foco no componente snk-filter-binary-select.
   */
  async setFocus() {
    if (this.presentationMode === presentationMode.EPresentationMode.MODAL) {
      this._checkOne.setFocus();
      return;
    }
    this._element.querySelector('ez-radio-button').focus();
  }
  assertCheckedOption(updatingCheck) {
    if (updatingCheck === this._checkOne) {
      this._checkTwo.value = true;
    }
    else {
      this._checkOne.value = true;
    }
  }
  updateValue() {
    if (!this._checkOne.value || !this._checkTwo.value) {
      const [optOne, optTwo] = this.config.props.options;
      this.value = this._checkOne.value ? optOne.name : optTwo.name;
    }
    else {
      this.value = undefined;
    }
    this.valueChanged.emit(this.value);
  }
  setRadioValue() {
    this._radioButtonValue = this.value || this._noOptionValue;
  }
  componentDidLoad() {
    if (this._element) {
      core.ElementIDUtils.addIDInfo(this._element, 'filterContentEditor');
    }
  }
  componentWillLoad() {
    this.setRadioValue();
  }
  componentShouldUpdate() {
    this.setRadioValue();
  }
  disconnectedCallback() {
    this.value = this.config.value;
  }
  render() {
    if (!this.config || this.config.type !== filterItemType_enum.FilterItemType.BINARY_SELECT) {
      return undefined;
    }
    const [optOne, optTwo] = this.config.props.options;
    if (this.presentationMode === presentationMode.EPresentationMode.MODAL) {
      return (index.h(index.Host, null, index.h("div", { class: "ez-row ez-size-height--full" }, index.h("label", { class: "ez-text ez-title--small ez-title--primary ez-size-height--full ez-flex ez-flex--row ez-flex--align-items-center ez-col ez-col--sd-4" }, this.config.detailModal), index.h("div", { class: "ez-col ez-col--sd-4" }, index.h("ez-check", { ref: (ref) => this._checkOne = ref, id: `${this.config.id}_${optOne.name || "option1"}`, class: "sc-snk-filter-bar editor__ez-check", label: optOne.label, enabled: this.config.enabled, value: this.isSelected(optOne.name) })), index.h("div", { class: "ez-col ez-col--sd-4" }, index.h("ez-check", { ref: (ref) => this._checkTwo = ref, id: `${this.config.id}_${optTwo.name || "option2"}`, class: "sc-snk-filter-bar editor__ez-check", label: optTwo.label, enabled: this.config.enabled, value: this.isSelected(optTwo.name) })), this.errorMessage &&
        index.h("span", { class: 'ez-text ez-text--small ez-text--error ez-margin--small' }, this.errorMessage))));
    }
    return (index.h(index.Host, null, index.h("ez-tooltip", { active: this.config.enabled === false, message: this.config.disabledMessage, type: 'warning' }, index.h("ez-radio-button", { value: this._radioButtonValue }, index.h("ez-radio-button-option", { id: `${this.config.id}_${optOne.name || "option1"}`, class: "sc-snk-filter-bar editor__ez-check", label: optOne.label, value: optOne.name }), index.h("ez-radio-button-option", { id: `${this.config.id}_${optTwo.name || "option2"}`, class: "sc-snk-filter-bar editor__ez-check", label: optTwo.label, value: optTwo.name }), index.h("ez-radio-button-option", { id: `${this.config.id}_option3`, class: "sc-snk-filter-bar editor__ez-check", label: `${optOne.label} + ${optTwo.label}`, value: this._noOptionValue })), this.errorMessage &&
      index.h("span", { class: 'ez-text ez-text--small ez-text--error ez-margin--small' }, this.errorMessage))));
  }
  get _element() { return index.getElement(this); }
};

exports.snk_filter_binary_select = SnkFilterBinarySelect;
