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';

const SnkFilterCheckboxList = class {
  constructor(hostRef) {
    registerInstance(this, hostRef);
    this.valueChanged = createEvent(this, "valueChanged", 7);
    this.config = undefined;
    this.errorMessage = undefined;
    this.optionsList = [];
  }
  /**
   * Define o foco no componente snk-filter-checkbox-list.
   */
  async setFocus() {
    var _a, _b;
    (_b = (_a = this._element) === null || _a === void 0 ? void 0 : _a.querySelector('ez-check')) === null || _b === void 0 ? void 0 : _b.setFocus();
  }
  /**
   * Limpa o valor do componente restaurando o valor original da configuração.
   */
  async clearValue() {
    var _a;
    this.config = Object.assign(Object.assign({}, this.config), { value: this.config.value });
    this.valueChanged.emit((_a = this.config) === null || _a === void 0 ? void 0 : _a.value);
  }
  componentDidLoad() {
    if (this._element) {
      ElementIDUtils.addIDInfo(this._element, 'filterContentEditor');
    }
  }
  handleToggleCheck(itemChanged, checked) {
    var _a, _b;
    this.errorMessage = undefined;
    let configValueMap = (_a = this.config.value) !== null && _a !== void 0 ? _a : {};
    configValueMap[itemChanged.name] = checked;
    this.config = Object.assign(Object.assign({}, this.config), { value: configValueMap });
    this.valueChanged.emit((_b = this.config) === null || _b === void 0 ? void 0 : _b.value);
  }
  renderOptions() {
    return this.optionsList.map(option => (h("ez-check", { label: option.label, onEzChange: (event) => this.handleToggleCheck(option, event.detail), value: !!this.isChecked(option.name), enabled: this.config.enabled })));
  }
  isChecked(itemName) {
    var _a;
    return (_a = this.config.value) === null || _a === void 0 ? void 0 : _a[itemName];
  }
  buidOptions() {
    var _a, _b, _c;
    const propsOptions = (_c = (_b = (_a = this.config) === null || _a === void 0 ? void 0 : _a.props) === null || _b === void 0 ? void 0 : _b.options) !== null && _c !== void 0 ? _c : [];
    this.optionsList = [...propsOptions];
  }
  componentWillRender() {
    this.buidOptions();
  }
  render() {
    if (!this.config || this.config.type !== FilterItemType.CHECK_BOX_LIST) {
      return undefined;
    }
    return (h("ez-tooltip", { active: this.config.enabled === false, message: this.config.disabledMessage, type: 'warning' }, h("div", { class: 'ez-flex ez-flex--column' }, this.renderOptions(), this.errorMessage &&
      h("span", { class: 'ez-text ez-text--small ez-text--error ez-margin--small' }, this.errorMessage))));
  }
  get _element() { return getElement(this); }
};

export { SnkFilterCheckboxList as snk_filter_checkbox_list };
