import { ApplicationContext, ElementIDUtils, ErrorException, LockManager, LockManagerOperation, ObjectUtils } from '@sankhyalabs/core';
import { EzScrollDirection } from '@sankhyalabs/ezui/dist/collection/components/ez-scroller/EzScrollDirection';
import { h, Host } from '@stencil/core';
import { ConfigStorage } from '../../lib/configs/ConfigStorage';
import { PersonalizedFilterUtils } from '../snk-personalized-filter/subcomponents/snk-filter-param-config/utils/PersonalizedFilterUtils';
import buildFilter from './filter-item/dataunitfilter/data-unit-filter-builder';
import FilterItemType from './filter-item/filter-item-type.enum';
export class SnkFilterBar {
  constructor() {
    this._updateSequence = [];
    this._loadingPending = false;
    this._configUpdated = false;
    this._firstLoad = true;
    this._pendingVariables = false;
    this._isDefaultFilter = false;
    this._customfiltersToBeUpdated = [];
    this._resolveLoading = undefined;
    this._calculateSortIndex = (item) => {
      if (!item.visible)
        return 0;
      if (item.hardFixed)
        return 1000000; //campos Hard Fixed não variam a ordem
      let index = item.fixed ? 100000 : 0;
      index += this.hasValidValue(item) ? 10000 : 0;
      index += this._updateSequence.lastIndexOf(item.id) + 1;
      return index;
    };
    this._filtersComparator = (a, b) => {
      return this._calculateSortIndex(b) - this._calculateSortIndex(a);
    };
    this.enableLockManagerLoadingComp = false;
    this.customFilterBarConfig = undefined;
    this.dataUnit = undefined;
    this.title = undefined;
    this.configName = undefined;
    this.resourceID = undefined;
    this.mode = "regular";
    this.filterConfig = undefined;
    this.messagesBuilder = undefined;
    this.disablePersonalizedFilter = undefined;
    this.filterBarLegacyConfigName = undefined;
    this.autoLoad = undefined;
    this.afterApplyConfig = undefined;
    this.filterCustomConfig = undefined;
    this.filterCustomConfigInterceptor = undefined;
    this.allowDefault = undefined;
    this.scrollerLocked = false;
    this.showPersonalizedFilter = false;
    this.personalizedFilterId = undefined;
    this.isFilterModalOpen = false;
  }
  hasValidValue(item) {
    var _a, _b;
    if (item.value === undefined || item.value === null) {
      return false;
    }
    if (item.type === FilterItemType.PERIOD) {
      return (!!((_a = item.value) === null || _a === void 0 ? void 0 : _a.start) || !!((_b = item.value) === null || _b === void 0 ? void 0 : _b.end));
    }
    if (item.groupedItems) {
      return true;
    }
    if (!Array.isArray(item.value)) {
      return true;
    }
    return item.value.some(filterItem => filterItem.check === true);
  }
  observeFilterConfig(newValue, oldValue) {
    if (ObjectUtils.equals(newValue, oldValue))
      return;
    this.handleFilterConfigsChanged(oldValue, newValue);
  }
  handleFilterConfigsChanged(oldValue, newValue) {
    if (oldValue != undefined && newValue == undefined) {
      this._loadingPending = true;
      this._configUpdated = true;
    }
    else {
      const oldItems = new Map(oldValue ? oldValue.map(item => [item.id, item]) : undefined);
      if (oldItems.size === 0 && newValue.length > 0) {
        this._loadingPending = true;
        this._configUpdated = false;
      }
      else {
        newValue.forEach(newItem => {
          const oldItem = oldItems.get(newItem.id);
          if (oldItem != undefined) {
            this._configUpdated = this._configUpdated || ObjectUtils.objectToString(oldItem) != ObjectUtils.objectToString(newItem);
            this._loadingPending = this._loadingPending || ObjectUtils.objectToString(oldItem.value) !== ObjectUtils.objectToString(newItem.value);
            if (!this._loadingPending) {
              const groupedChanged = ObjectUtils.objectToString(oldItem.groupedItems) != ObjectUtils.objectToString(newItem.groupedItems);
              this._configUpdated = this._configUpdated || groupedChanged;
              this._loadingPending = this._loadingPending || groupedChanged;
            }
          }
          else {
            this._configUpdated = true;
            this._loadingPending = this._loadingPending || newItem.value != undefined;
          }
        });
      }
    }
    if (this._loadingPending || this._configUpdated)
      this.configUpdated.emit(newValue);
    this.processAfterUpdateConfig();
  }
  /**
   * @description Faz o recarregamento da barra de filtros buscando o state no servidor.
   * @async
   * @return {Promise<void>} Retorna uma Promise que resolve quando o recarregamento for concluído.
   */
  async reload() {
    this.loadConfigFromStorage(true);
  }
  /**
   * @description Retorna um item de filtro pelo ID.
   * @async
   * @param {string} id - ID do item de filtro.
   * @returns {Promise<SnkFilterItemConfig | undefined>} O item de filtro correspondente ou undefined se não for encontrado.
   */
  async getFilterItem(id) {
    const item = this.filterConfig.find(item => item.id === id);
    return Promise.resolve(ObjectUtils.copy(item));
  }
  /**
  * @description Atualiza um item do filtro.
  * @async
  * @param {SnkFilterItemConfig} newFilterItem - Item com as informações atualizadas, caso o item não seja encontrado no array, ele não será modificado.
  * @return {Promise<void>} Retorna uma Promise que resolve quando a atualização for concluída.
  */
  async updateFilterItem(newFilterItem) {
    const itemIndex = this.filterConfig.findIndex(item => item.id === newFilterItem.id);
    if (itemIndex == -1) {
      console.warn("[SnkFilterBar.updateFilterItem] " + this.getMessage("snkFilterBar.filterItem.updateFilterItemNotFound"));
      return Promise.resolve();
    }
    this._loadingPending = true;
    this.updateFilter(newFilterItem);
    return Promise.resolve();
  }
  /**
  * @description Adiciona um item de filtro.
  * @async
  * @param {SnkFilterItemConfig} filterItem - Item a ser adicionado, caso o item já exista com o ID, ele não será adicionado novamente.
  * @return {Promise<void>} Retorna uma Promise que resolve quando o item for adicionado.
  */
  async addFilterItem(filterItem) {
    const itemIndex = this.filterConfig.findIndex(item => item.id === filterItem.id);
    if (itemIndex > -1) {
      console.warn("[SnkFilterBar.addFilterItem] " + this.getMessage("snkFilterBar.filterItem.addFilterItemExists"));
      return Promise.resolve();
    }
    this.filterConfig.push(filterItem);
    this._loadingPending = true;
    this.updateFilter(filterItem);
    return Promise.resolve();
  }
  /**
  * @description Remove um item de filtro.
  * @async
  * @param {string} filterID - ID do item a ser removido.
  * @returns {Promise<SnkFilterItemConfig|undefined>} Retorna o item de filtro removido, ou undefined caso não seja encontrado.
  */
  async removeFilterItem(filterID) {
    const itemIndex = this.filterConfig.findIndex(item => item.id === filterID);
    if (itemIndex == -1) {
      console.warn("[SnkFilterBar.removeFilterItem] " + this.getMessage("snkFilterBar.filterItem.removeFilterItemNotFound"));
      return Promise.resolve(undefined);
    }
    const itemToRemove = this.filterConfig[itemIndex];
    this.filterConfig = this.filterConfig.filter(item => item.id !== filterID);
    return Promise.resolve(itemToRemove);
  }
  componentDidLoad() {
    if (this._element) {
      const dataInfo = { dataUnit: this.dataUnit };
      ElementIDUtils.addIDInfo(this._element, null, dataInfo);
    }
  }
  processPendingFilter() {
    if (this._pendingVariables) {
      const popUp = this._element.querySelector("#filter-PERSONALIZED_FILTER_GROUP");
      if (popUp) {
        popUp.showUp(true).then(() => {
          this.processAfterUpdateConfig();
        });
      }
    }
    else {
      this.processAfterUpdateConfig();
    }
  }
  getPersonalizedFilterItem() {
    return this.filterConfig.find(item => item.type === FilterItemType.PERSONALIZED);
  }
  async processAfterUpdateConfig() {
    var _a;
    if (this._loadingPending) {
      if (await this._application.isLoadedByPk() && !this._configUpdated)
        return;
      const personalizedFilter = this.getPersonalizedFilterItem();
      this._pendingVariables = !PersonalizedFilterUtils.validateVariableValues(personalizedFilter);
      if (this._pendingVariables) {
        return;
      }
      this._loadingPending = false;
      this.doLoadData();
    }
    if (this._configUpdated) {
      this._configUpdated = false;
      ConfigStorage.saveFilterBarConfig(this.filterConfig, this.configName, this.resourceID);
      (_a = this.afterApplyConfig) === null || _a === void 0 ? void 0 : _a.call(this);
    }
  }
  async doLoadData(forceReload = false) {
    try {
      if (this._firstLoad && this.autoLoad === false) {
        return;
      }
      if (this._firstLoad && !forceReload && this.autoLoad === undefined) {
        let autoLoad = await this._application.getBooleanParam("global.carregar.registros.iniciar.tela");
        if (!autoLoad) {
          return;
        }
      }
      this.dataUnit.loadData(undefined, undefined, true);
    }
    finally {
      this._firstLoad = false;
    }
  }
  /**
   * Conforme mecanismo de mensagens, é possível customizar as mensagens dos blocos de construção
   * através de um pequeno módulo na estrutura da aplicação:
   * - Criar um arquivo no seguinte caminho: /messages/appmessages.msg.js.
   * Para conhecer os detalhes do módulo, vide o arquivo neste projeto "/src/lib/message/resources/snk-filter-bar.msg.ts"
   */
  getMessage(key, params, defaultValue) {
    var _a;
    if (this.messagesBuilder == undefined && this._application) {
      this.messagesBuilder = this._application.messagesBuilder;
    }
    return ((_a = this.messagesBuilder) === null || _a === void 0 ? void 0 : _a.getMessage(key, params)) || defaultValue;
  }
  async getFilters() {
    return this.getFilter(null);
  }
  getFilter(_dataUnit) {
    var _a;
    const filters = [];
    (_a = this.filterConfig) === null || _a === void 0 ? void 0 : _a.filter(item => this.isActiveFilter(item)).forEach(item => {
      const filter = buildFilter(item);
      if (filter) {
        filters.push(filter);
      }
    });
    return filters;
  }
  isActiveFilter(item) {
    /*
      - O filtro padrão também deve sempre ser condiderado ativo, pois, sempre deve
        ser aplicado.
    */
    if (item.type === FilterItemType.DEFAULT_FILTER) {
      return true;
    }
    return this.filterActiveFilter(item) && this.hasValidValue(item);
  }
  async registryFilterProvider() {
    this.dataUnit.addFilterProvider(this);
    if (this.filterConfig) {
      await this.doLoadData();
    }
  }
  itemFocused(selectedItem) {
    this._element.querySelectorAll("snk-filter-item,snk-filter-list").forEach(item => {
      if (item.id === selectedItem) {
        if (item.tagName.toLowerCase() === "snk-filter-item" && item.getClientRects()[0].x < 0) {
          item.scrollIntoView({ behavior: "auto", inline: 'nearest' });
        }
      }
      else {
        item["hideDetail"]();
      }
    });
  }
  filterActiveFilter(item) {
    return item.visible || item.removalBlocked;
  }
  filterPersonalizedItems(item) {
    return item.type === FilterItemType.PERSONALIZED;
  }
  getPersonalizedFilterVariableItems() {
    return this.filterConfig
      .filter(this.filterPersonalizedItems)
      .map(item => {
      const itemId = `filter-${item.id}`;
      return (h("snk-filter-item", { key: item.id, id: itemId, config: Object.assign({}, item), onFocusin: () => this.itemFocused(itemId), onVisibleChanged: (evt) => this.scrollerLocked = evt.detail, onFilterChange: (event) => this.updateFilter(event.detail), getMessage: (key, props) => this.getMessage(key, props), showChips: false }));
    });
  }
  getFilterItems() {
    const pinnedItems = [];
    const unpinnedItems = [];
    this.filterConfig.sort((a, b) => this._filtersComparator(a, b))
      .filter(this.filterActiveFilter)
      .forEach((item) => {
      item = ObjectUtils.copy(item);
      const itemId = `filter-${item.id}`;
      const filterItem = (h("snk-filter-item", { onVisibleChanged: (evt) => this.scrollerLocked = evt.detail, onFilterChange: (event) => this.updateFilter(event.detail), onFocusin: () => this.itemFocused(itemId), id: itemId, config: item, class: "ez-margin-horizontal--extra-small", getMessage: (key, props) => this.getMessage(key, props), key: item.id }));
      if (item.fixed || item.hardFixed || item.required) {
        pinnedItems.push(filterItem);
      }
      else {
        unpinnedItems.push(filterItem);
      }
      return filterItem;
    });
    const elements = [];
    elements.push(...pinnedItems.reverse());
    if (pinnedItems.length > 0 && unpinnedItems.length > 0) {
      elements.push(h("hr", { class: "ez-margin-horizontal--small ez-margin-vertical--auto ez-divider-vertical ez-divider--dark snk-filter-bar__divider" }));
    }
    elements.push(...unpinnedItems);
    return elements;
  }
  calculateUpdateSequence(item) {
    if (item) {
      this._updateSequence = this._updateSequence.filter(itemId => item.id !== itemId);
      this._updateSequence.push(item.id);
    }
  }
  normalizeItem(item) {
    const normalized = Object.assign({}, item);
    const isPersonalizedFilter = item.type === FilterItemType.PERSONALIZED;
    const hasNormalizedGroupedItems = (normalized.value === undefined && normalized.groupedItems);
    if (isPersonalizedFilter && hasNormalizedGroupedItems) {
      normalized.value = normalized.groupedItems.filter(groupItem => !!groupItem.visible).length;
    }
    const optionals = ["props", "value", "hardFixed", "fixed"];
    optionals.forEach(prop => {
      if (prop === "value" && isPersonalizedFilter) {
        return;
      }
      if (normalized[prop] == undefined) {
        delete normalized[prop];
      }
    });
    if (normalized.value === "" && !isPersonalizedFilter) {
      delete normalized.value;
    }
    return normalized;
  }
  updateFilter(newItem) {
    const normalizedNewItem = this.normalizeItem(newItem);
    let config = this.filterConfig.map(item => {
      if (item.id !== normalizedNewItem.id) {
        return item;
      }
      if (ObjectUtils.objectToString(item) == ObjectUtils.objectToString(normalizedNewItem)) {
        this.calculateUpdateSequence(normalizedNewItem);
      }
      return normalizedNewItem;
    }).sort((a, b) => this._filtersComparator(a, b));
    if (this.filterCustomConfigInterceptor) {
      config = this.filterCustomConfigInterceptor(config);
    }
    this.filterConfig = config;
  }
  loadPermitions() {
    this._application.isUserSup().then(value => this.allowDefault = value);
  }
  addFilterBarLegacyConfigName() {
    if (this.filterBarLegacyConfigName) {
      ConfigStorage.addFilterBarLegacyConfig(this.configName, this.filterBarLegacyConfigName);
    }
  }
  async loadConfigFromStorage(clearCache) {
    try {
      if (clearCache) {
        await ConfigStorage.deleteFilterBarConfigCache(this.configName, this.resourceID);
      }
      let config;
      if (this.customFilterBarConfig) {
        config = await this.customFilterBarConfig(this.configName, this.resourceID, { contextURI: this.dataUnit.name });
      }
      else {
        config = await ConfigStorage.loadFilterBarConfig(this.configName, this.resourceID, { contextURI: this.dataUnit.name });
      }
      if (this.filterCustomConfig) {
        config = [...this.filterCustomConfig, ...config];
      }
      if (this.filterCustomConfigInterceptor) {
        config = this.filterCustomConfigInterceptor(config);
      }
      this.filterConfig = config.map(item => this.normalizeItem(item));
      this.filterConfig.sort((a, b) => this._filtersComparator(a, b));
    }
    catch (e) {
      throw new ErrorException(this.getMessage("snkFilterBar.failToLoadConfig"), e);
    }
  }
  async attachDataUnit() {
    if (this.dataUnit == undefined) {
      let parent = this._element.parentElement;
      while (parent) {
        if (parent.tagName.toUpperCase() === "SNK-DATA-UNIT") {
          const snkDataUnit = parent;
          this.dataUnit = snkDataUnit.dataUnit;
          if (this.dataUnit) {
            await this.registryFilterProvider();
          }
          else {
            snkDataUnit.addEventListener("dataUnitReady", async (evt) => {
              this.dataUnit = evt.detail;
              await this.registryFilterProvider();
            });
          }
          break;
        }
      }
      parent = parent.parentElement;
    }
    else {
      await this.registryFilterProvider();
    }
  }
  /**
  * Emitido quando acontece a alteração do estado do filtro.
  */
  filterChangeListener(evt) {
    this.updateFilter(evt.detail);
  }
  /**
   * Escuta quando há um filtro do tipo pesquisa retorna um valor vazio.
   */
  async emptySearchListener(_evt) {
    await this.showPersonalizedFilterItem();
  }
  /**
   * @description Abre o modal de filtros.
   * @async
  */
  async showFilterModal() {
    if (this.isFilterModalOpen) {
      return; // Evita abrir múltiplos modais
    }
    this.isFilterModalOpen = true;
  }
  async showPersonalizedFilterItem() {
    const popUp = this._element.querySelector('#filter-PERSONALIZED_FILTER_GROUP');
    await (popUp === null || popUp === void 0 ? void 0 : popUp.showUp(true));
  }
  addPersonalizedFilter(isDefault = false) {
    this.isFilterModalOpen = false;
    this._isDefaultFilter = isDefault;
    this.personalizedFilterId = undefined;
    this.showPersonalizedFilter = true;
    window.requestAnimationFrame(() => {
      this._elPersonalizedFilter.createPersonalizedFilter();
    });
  }
  editPersonalizedFilter(id, isDefault = false) {
    this.isFilterModalOpen = false;
    this._isDefaultFilter = isDefault;
    this.showPersonalizedFilter = true;
    this.personalizedFilterId = id;
  }
  deletePersonalizedFilter(filter, filterItemType, configName, isDefault = false) {
    if (isDefault) {
      ConfigStorage.removeDefaultFilter(filter, this.resourceID, configName);
      this._isDefaultFilter = false;
      return;
    }
    if (filterItemType === FilterItemType.PERSONALIZED) {
      ConfigStorage.removePersonalizedFilter(filter, this.resourceID, configName);
    }
  }
  closeFilterModal() {
    this.isFilterModalOpen = false;
  }
  applyFiltersFromModal(filters) {
    var _a;
    this.filterConfig = filters.map(this.normalizeItem).sort((a, b) => this._filtersComparator(a, b));
    (_a = this.afterApplyConfig) === null || _a === void 0 ? void 0 : _a.call(this);
    this.isFilterModalOpen = false;
  }
  handleHidePersonalizedFilter(reloadFilterBar) {
    if (reloadFilterBar) {
      this.loadConfigFromStorage().then(() => {
        this.hidePersonalizedFilter();
      });
    }
    else {
      this.hidePersonalizedFilter();
    }
  }
  hidePersonalizedFilter() {
    this.personalizedFilterId = undefined;
    this.showPersonalizedFilter = false;
    this._isDefaultFilter = false;
  }
  async componentWillLoad() {
    var _a;
    try {
      this._application = ApplicationContext.getContextValue("__SNK__APPLICATION__");
      await this.attachDataUnit();
      if (this._application) {
        if (this._application.enableLockManagerLoadingApp && this.enableLockManagerLoadingComp) {
          const appLoadLockerID = LockManager.addLockManagerCtxId(this._element);
          this._resolveLoading = LockManager.lock(appLoadLockerID, LockManagerOperation.APP_LOADING);
        }
        await Promise.all([
          this.loadPermitions(),
          this.addFilterBarLegacyConfigName(),
          this.loadConfigFromStorage(),
        ]);
      }
    }
    finally {
      (_a = this._resolveLoading) === null || _a === void 0 ? void 0 : _a.call(this);
    }
  }
  componentDidRender() {
    this.processPendingFilter();
  }
  render() {
    if (!this.dataUnit || !this.filterConfig || this.filterConfig.length === 0) {
      return undefined;
    }
    if (this.showPersonalizedFilter) {
      return h("snk-personalized-filter", { class: "filter-bar__personalized-filter", filterId: this.personalizedFilterId, ref: (el) => this._elPersonalizedFilter = el, isDefaultFilter: this._isDefaultFilter, onEzCancel: () => this.handleHidePersonalizedFilter(false), onEzAfterSave: () => this.handleHidePersonalizedFilter(true), entityUri: this.dataUnit.name, configName: this.configName, resourceID: this.resourceID });
    }
    let filtersConfigCopy = ObjectUtils.copy(this.filterConfig);
    filtersConfigCopy = filtersConfigCopy.sort((itemA, itemB) => {
      return itemA.originOrder - itemB.originOrder;
    });
    if (this.mode !== "regular") {
      return (h(Host, { "data-mode": this.mode }, this.getPersonalizedFilterVariableItems(), this.mode === 'button' && (h("ez-button", { class: "ez-margin-left--medium", size: "small", label: this.getMessage('snkFilterBar.filters', undefined, this.getMessage("snkFilterBar.filters")), onClick: this.showFilterModal.bind(this) })), h("snk-filter-modal", { opened: this.isFilterModalOpen, filterConfig: this.filterConfig, configName: this.configName, disablePersonalizedFilter: this.disablePersonalizedFilter, getMessage: (key, props) => this.getMessage(key, props), applyFilters: (filters) => this.applyFiltersFromModal(filters), closeModal: () => this.closeFilterModal(), addPersonalizedFilter: (isDefault) => this.addPersonalizedFilter(isDefault), editPersonalizedFilter: (id, isDefault) => this.editPersonalizedFilter(id, isDefault), deletePersonalizedFilter: (filter, configName, isDefault) => this.deletePersonalizedFilter(filter, FilterItemType.PERSONALIZED, configName, isDefault), filterCustomConfigInterceptor: this.filterCustomConfigInterceptor })));
    }
    return (h(Host, null, h("div", null, h("span", { class: "snk-filter-bar__title", title: this.title, "data-tooltip": this.title, "data-flow": "bottom" }, this.title)), h("ez-scroller", { class: "snk-filter-bar__scroller", direction: EzScrollDirection.HORIZONTAL, activeShadow: true, locked: this.scrollerLocked }, h("section", { class: "snk-filter-bar__filter-item-container" }, this.getFilterItems())), h("ez-button", { class: "ez-padding-left--medium ez-margin-top--extra-small", size: "small", label: this.getMessage('snkFilterBar.filters', undefined, this.getMessage("snkFilterBar.filters")), onClick: this.showFilterModal.bind(this) }, h("ez-icon", { slot: "leftIcon", iconName: "plus", class: "ez-padding-right--small" })), h("snk-filter-modal", { opened: this.isFilterModalOpen, filterConfig: this.filterConfig, configName: this.configName, disablePersonalizedFilter: this.disablePersonalizedFilter, getMessage: (key, props) => this.getMessage(key, props), applyFilters: (filters) => this.applyFiltersFromModal(filters), closeModal: () => this.closeFilterModal(), addPersonalizedFilter: (isDefault) => this.addPersonalizedFilter(isDefault), editPersonalizedFilter: (id, isDefault) => this.editPersonalizedFilter(id, isDefault), deletePersonalizedFilter: (filter, configName, isDefault) => this.deletePersonalizedFilter(filter, FilterItemType.PERSONALIZED, configName, isDefault), filterCustomConfigInterceptor: this.filterCustomConfigInterceptor })));
  }
  static get is() { return "snk-filter-bar"; }
  static get encapsulation() { return "scoped"; }
  static get originalStyleUrls() {
    return {
      "$": ["snk-filter-bar.css"]
    };
  }
  static get styleUrls() {
    return {
      "$": ["snk-filter-bar.css"]
    };
  }
  static get properties() {
    return {
      "enableLockManagerLoadingComp": {
        "type": "boolean",
        "mutable": false,
        "complexType": {
          "original": "boolean",
          "resolved": "boolean",
          "references": {}
        },
        "required": false,
        "optional": true,
        "docs": {
          "tags": [{
              "name": "description",
              "text": "Define se o componente deve usar o LockManager para controle de carregamento."
            }],
          "text": ""
        },
        "attribute": "enable-lock-manager-loading-comp",
        "reflect": false,
        "defaultValue": "false"
      },
      "customFilterBarConfig": {
        "type": "unknown",
        "mutable": false,
        "complexType": {
          "original": "(configName: string, resourceId: string, options: any) => Promise<Array<SnkFilterItemConfig>>",
          "resolved": "(configName: string, resourceId: string, options: any) => Promise<SnkFilterItemConfig[]>",
          "references": {
            "Promise": {
              "location": "global"
            },
            "Array": {
              "location": "global"
            },
            "SnkFilterItemConfig": {
              "location": "import",
              "path": "./filter-item/snk-filter-item"
            }
          }
        },
        "required": false,
        "optional": true,
        "docs": {
          "tags": [{
              "name": "description",
              "text": "Loader customizado para carregar as configura\u00E7\u00F5es."
            }, {
              "name": "param",
              "text": "configName - Nome da configura\u00E7\u00E3o."
            }, {
              "name": "param",
              "text": "resourceId - ID do recurso."
            }, {
              "name": "param",
              "text": "options - Op\u00E7\u00F5es adicionais."
            }, {
              "name": "returns",
              "text": "Retorna a configura\u00E7\u00E3o dos filtros."
            }],
          "text": ""
        }
      },
      "dataUnit": {
        "type": "unknown",
        "mutable": true,
        "complexType": {
          "original": "DataUnit",
          "resolved": "DataUnit",
          "references": {
            "DataUnit": {
              "location": "import",
              "path": "@sankhyalabs/core"
            }
          }
        },
        "required": false,
        "optional": false,
        "docs": {
          "tags": [{
              "name": "description",
              "text": "Recebe o DataUnit do ambiente. Se n\u00E3o for informado, procura pela refer\u00EAncia\ndo SnkDataUnit. Necess\u00E1rio para se registrar como provedor de filtros."
            }],
          "text": ""
        }
      },
      "title": {
        "type": "string",
        "mutable": false,
        "complexType": {
          "original": "string",
          "resolved": "string",
          "references": {}
        },
        "required": false,
        "optional": false,
        "docs": {
          "tags": [{
              "name": "description",
              "text": "T\u00EDtulo que ser\u00E1 apresentado na barra de filtros."
            }],
          "text": ""
        },
        "attribute": "title",
        "reflect": false
      },
      "configName": {
        "type": "string",
        "mutable": false,
        "complexType": {
          "original": "string",
          "resolved": "string",
          "references": {}
        },
        "required": false,
        "optional": false,
        "docs": {
          "tags": [{
              "name": "description",
              "text": "Eventualmente poderemos ter mais de uma barra de filtros. Essa propriedade\nserve para separar a configura\u00E7\u00E3o de cada uma."
            }],
          "text": ""
        },
        "attribute": "config-name",
        "reflect": false
      },
      "resourceID": {
        "type": "string",
        "mutable": false,
        "complexType": {
          "original": "string",
          "resolved": "string",
          "references": {}
        },
        "required": false,
        "optional": false,
        "docs": {
          "tags": [{
              "name": "description",
              "text": "Identificador de recursos como configura\u00E7\u00F5es e acesso."
            }],
          "text": ""
        },
        "attribute": "resource-i-d",
        "reflect": false
      },
      "mode": {
        "type": "string",
        "mutable": false,
        "complexType": {
          "original": "\"regular\" | \"button\" | \"hidden\"",
          "resolved": "\"button\" | \"hidden\" | \"regular\"",
          "references": {}
        },
        "required": false,
        "optional": false,
        "docs": {
          "tags": [{
              "name": "description",
              "text": "Modo de apresenta\u00E7\u00E3o da barra de filtros."
            }],
          "text": ""
        },
        "attribute": "mode",
        "reflect": false,
        "defaultValue": "\"regular\""
      },
      "filterConfig": {
        "type": "unknown",
        "mutable": true,
        "complexType": {
          "original": "Array<SnkFilterItemConfig>",
          "resolved": "SnkFilterItemConfig[]",
          "references": {
            "Array": {
              "location": "global"
            },
            "SnkFilterItemConfig": {
              "location": "import",
              "path": "./filter-item/snk-filter-item"
            }
          }
        },
        "required": false,
        "optional": false,
        "docs": {
          "tags": [{
              "name": "description",
              "text": "Lista todos os filtros dispon\u00EDveis ao usu\u00E1rio."
            }],
          "text": ""
        }
      },
      "messagesBuilder": {
        "type": "unknown",
        "mutable": true,
        "complexType": {
          "original": "SnkMessageBuilder",
          "resolved": "SnkMessageBuilder",
          "references": {
            "SnkMessageBuilder": {
              "location": "import",
              "path": "../../lib/message/SnkMessageBuilder"
            }
          }
        },
        "required": false,
        "optional": false,
        "docs": {
          "tags": [{
              "name": "description",
              "text": "Respons\u00E1vel por flexibilizar e padronizar o uso de mensagens nos blocos de constru\u00E7\u00E3o."
            }],
          "text": ""
        }
      },
      "disablePersonalizedFilter": {
        "type": "boolean",
        "mutable": false,
        "complexType": {
          "original": "boolean",
          "resolved": "boolean",
          "references": {}
        },
        "required": false,
        "optional": false,
        "docs": {
          "tags": [{
              "name": "description",
              "text": "Desabilita a apresenta\u00E7\u00E3o da op\u00E7\u00E3o de filtros personalizados na filter bar (chip de filtros)\ne no modal lateral de filtros (container de filtros personalizados)."
            }],
          "text": ""
        },
        "attribute": "disable-personalized-filter",
        "reflect": false
      },
      "filterBarLegacyConfigName": {
        "type": "string",
        "mutable": false,
        "complexType": {
          "original": "string",
          "resolved": "string",
          "references": {}
        },
        "required": false,
        "optional": false,
        "docs": {
          "tags": [{
              "name": "description",
              "text": "Chave da configura\u00E7\u00E3o legada da barra de filtros."
            }],
          "text": ""
        },
        "attribute": "filter-bar-legacy-config-name",
        "reflect": false
      },
      "autoLoad": {
        "type": "boolean",
        "mutable": false,
        "complexType": {
          "original": "boolean",
          "resolved": "boolean",
          "references": {}
        },
        "required": false,
        "optional": true,
        "docs": {
          "tags": [{
              "name": "description",
              "text": "Define se a carga dos dados ser\u00E1 feita assim que o componente for carregado."
            }],
          "text": ""
        },
        "attribute": "auto-load",
        "reflect": false
      },
      "afterApplyConfig": {
        "type": "unknown",
        "mutable": false,
        "complexType": {
          "original": "() => void",
          "resolved": "() => void",
          "references": {}
        },
        "required": false,
        "optional": true,
        "docs": {
          "tags": [{
              "name": "description",
              "text": "Fun\u00E7\u00E3o chamada depois de aplicar os filtros."
            }],
          "text": ""
        }
      },
      "filterCustomConfig": {
        "type": "unknown",
        "mutable": false,
        "complexType": {
          "original": "Array<SnkFilterItemConfig>",
          "resolved": "SnkFilterItemConfig[]",
          "references": {
            "Array": {
              "location": "global"
            },
            "SnkFilterItemConfig": {
              "location": "import",
              "path": "./filter-item/snk-filter-item"
            }
          }
        },
        "required": false,
        "optional": true,
        "docs": {
          "tags": [{
              "name": "description",
              "text": "Configura\u00E7\u00E3o customizada dos filtros."
            }, {
              "name": "param",
              "text": "config - Lista de configura\u00E7\u00F5es de filtros."
            }],
          "text": ""
        }
      },
      "filterCustomConfigInterceptor": {
        "type": "unknown",
        "mutable": false,
        "complexType": {
          "original": "(config: Array<SnkFilterItemConfig>) => Array<SnkFilterItemConfig>",
          "resolved": "(config: SnkFilterItemConfig[]) => SnkFilterItemConfig[]",
          "references": {
            "Array": {
              "location": "global"
            },
            "SnkFilterItemConfig": {
              "location": "import",
              "path": "./filter-item/snk-filter-item"
            }
          }
        },
        "required": false,
        "optional": true,
        "docs": {
          "tags": [{
              "name": "description",
              "text": "Intercepta a configura\u00E7\u00E3o dos filtros antes de serem aplicadas."
            }, {
              "name": "param",
              "text": "config - Lista de configura\u00E7\u00F5es de filtros."
            }, {
              "name": "returns",
              "text": "Retorna a lista de configura\u00E7\u00F5es de filtros."
            }],
          "text": ""
        }
      }
    };
  }
  static get states() {
    return {
      "allowDefault": {},
      "scrollerLocked": {},
      "showPersonalizedFilter": {},
      "personalizedFilterId": {},
      "isFilterModalOpen": {}
    };
  }
  static get events() {
    return [{
        "method": "configUpdated",
        "name": "configUpdated",
        "bubbles": true,
        "cancelable": true,
        "composed": true,
        "docs": {
          "tags": [{
              "name": "description",
              "text": "Evento emitido quando a configura\u00E7\u00E3o dos filtros \u00E9 atualizada."
            }, {
              "name": "param",
              "text": "configs - Lista de configura\u00E7\u00F5es de filtros atualizadas."
            }, {
              "name": "event",
              "text": undefined
            }],
          "text": ""
        },
        "complexType": {
          "original": "SnkFilterItemConfig[]",
          "resolved": "SnkFilterItemConfig[]",
          "references": {
            "SnkFilterItemConfig": {
              "location": "import",
              "path": "./filter-item/snk-filter-item"
            }
          }
        }
      }];
  }
  static get methods() {
    return {
      "reload": {
        "complexType": {
          "signature": "() => Promise<void>",
          "parameters": [],
          "references": {
            "Promise": {
              "location": "global"
            }
          },
          "return": "Promise<void>"
        },
        "docs": {
          "text": "",
          "tags": [{
              "name": "description",
              "text": "Faz o recarregamento da barra de filtros buscando o state no servidor."
            }, {
              "name": "async",
              "text": undefined
            }, {
              "name": "return",
              "text": "Retorna uma Promise que resolve quando o recarregamento for conclu\u00EDdo."
            }]
        }
      },
      "getFilterItem": {
        "complexType": {
          "signature": "(id: string) => Promise<SnkFilterItemConfig | undefined>",
          "parameters": [{
              "tags": [{
                  "name": "param",
                  "text": "id - ID do item de filtro."
                }],
              "text": "- ID do item de filtro."
            }],
          "references": {
            "Promise": {
              "location": "global"
            },
            "SnkFilterItemConfig": {
              "location": "import",
              "path": "./filter-item/snk-filter-item"
            }
          },
          "return": "Promise<SnkFilterItemConfig>"
        },
        "docs": {
          "text": "",
          "tags": [{
              "name": "description",
              "text": "Retorna um item de filtro pelo ID."
            }, {
              "name": "async",
              "text": undefined
            }, {
              "name": "param",
              "text": "id - ID do item de filtro."
            }, {
              "name": "returns",
              "text": "O item de filtro correspondente ou undefined se n\u00E3o for encontrado."
            }]
        }
      },
      "updateFilterItem": {
        "complexType": {
          "signature": "(newFilterItem: SnkFilterItemConfig) => Promise<void>",
          "parameters": [{
              "tags": [{
                  "name": "param",
                  "text": "newFilterItem - Item com as informa\u00E7\u00F5es atualizadas, caso o item n\u00E3o seja encontrado no array, ele n\u00E3o ser\u00E1 modificado."
                }],
              "text": "- Item com as informa\u00E7\u00F5es atualizadas, caso o item n\u00E3o seja encontrado no array, ele n\u00E3o ser\u00E1 modificado."
            }],
          "references": {
            "Promise": {
              "location": "global"
            },
            "SnkFilterItemConfig": {
              "location": "import",
              "path": "./filter-item/snk-filter-item"
            }
          },
          "return": "Promise<void>"
        },
        "docs": {
          "text": "",
          "tags": [{
              "name": "description",
              "text": "Atualiza um item do filtro."
            }, {
              "name": "async",
              "text": undefined
            }, {
              "name": "param",
              "text": "newFilterItem - Item com as informa\u00E7\u00F5es atualizadas, caso o item n\u00E3o seja encontrado no array, ele n\u00E3o ser\u00E1 modificado."
            }, {
              "name": "return",
              "text": "Retorna uma Promise que resolve quando a atualiza\u00E7\u00E3o for conclu\u00EDda."
            }]
        }
      },
      "addFilterItem": {
        "complexType": {
          "signature": "(filterItem: SnkFilterItemConfig) => Promise<void>",
          "parameters": [{
              "tags": [{
                  "name": "param",
                  "text": "filterItem - Item a ser adicionado, caso o item j\u00E1 exista com o ID, ele n\u00E3o ser\u00E1 adicionado novamente."
                }],
              "text": "- Item a ser adicionado, caso o item j\u00E1 exista com o ID, ele n\u00E3o ser\u00E1 adicionado novamente."
            }],
          "references": {
            "Promise": {
              "location": "global"
            },
            "SnkFilterItemConfig": {
              "location": "import",
              "path": "./filter-item/snk-filter-item"
            }
          },
          "return": "Promise<void>"
        },
        "docs": {
          "text": "",
          "tags": [{
              "name": "description",
              "text": "Adiciona um item de filtro."
            }, {
              "name": "async",
              "text": undefined
            }, {
              "name": "param",
              "text": "filterItem - Item a ser adicionado, caso o item j\u00E1 exista com o ID, ele n\u00E3o ser\u00E1 adicionado novamente."
            }, {
              "name": "return",
              "text": "Retorna uma Promise que resolve quando o item for adicionado."
            }]
        }
      },
      "removeFilterItem": {
        "complexType": {
          "signature": "(filterID: string) => Promise<SnkFilterItemConfig | undefined>",
          "parameters": [{
              "tags": [{
                  "name": "param",
                  "text": "filterID - ID do item a ser removido."
                }],
              "text": "- ID do item a ser removido."
            }],
          "references": {
            "Promise": {
              "location": "global"
            },
            "SnkFilterItemConfig": {
              "location": "import",
              "path": "./filter-item/snk-filter-item"
            }
          },
          "return": "Promise<SnkFilterItemConfig>"
        },
        "docs": {
          "text": "",
          "tags": [{
              "name": "description",
              "text": "Remove um item de filtro."
            }, {
              "name": "async",
              "text": undefined
            }, {
              "name": "param",
              "text": "filterID - ID do item a ser removido."
            }, {
              "name": "returns",
              "text": "Retorna o item de filtro removido, ou undefined caso n\u00E3o seja encontrado."
            }]
        }
      },
      "getFilters": {
        "complexType": {
          "signature": "() => Promise<Filter[]>",
          "parameters": [],
          "references": {
            "Promise": {
              "location": "global"
            },
            "Filter": {
              "location": "import",
              "path": "@sankhyalabs/core/dist/dataunit/metadata/UnitMetadata"
            }
          },
          "return": "Promise<Filter[]>"
        },
        "docs": {
          "text": "",
          "tags": []
        }
      },
      "showFilterModal": {
        "complexType": {
          "signature": "() => Promise<void>",
          "parameters": [],
          "references": {
            "Promise": {
              "location": "global"
            }
          },
          "return": "Promise<void>"
        },
        "docs": {
          "text": "",
          "tags": [{
              "name": "description",
              "text": "Abre o modal de filtros."
            }, {
              "name": "async",
              "text": undefined
            }]
        }
      }
    };
  }
  static get elementRef() { return "_element"; }
  static get watchers() {
    return [{
        "propName": "filterConfig",
        "methodName": "observeFilterConfig"
      }];
  }
  static get listeners() {
    return [{
        "name": "filterChange",
        "method": "filterChangeListener",
        "target": undefined,
        "capture": false,
        "passive": false
      }, {
        "name": "ezEmptySearch",
        "method": "emptySearchListener",
        "target": "window",
        "capture": false,
        "passive": false
      }];
  }
}
