import { ApplicationUtils } from "@sankhyalabs/ezui/dist/collection/utils";
class SnkFilterModalFactory {
  constructor({ filterConfig, configName, onComplete, getMessage, disablePersonalizedFilter, onAddPersonalizedFilter, onEditPersonalizedFilter, onDeletePersonalizedFilter, filterCustomConfigInterceptor }) {
    this._filterConfig = filterConfig;
    this._configName = configName;
    this._onComplete = onComplete;
    this._getMessage = getMessage;
    this._disablePersonalizedFilter = disablePersonalizedFilter;
    this._addPersonalizedFilterFn = onAddPersonalizedFilter;
    this._editPersonalizedFilterFn = onEditPersonalizedFilter;
    this._onDeletePersonalizedFilter = onDeletePersonalizedFilter;
    this._filterCustomConfigInterceptor = filterCustomConfigInterceptor;
  }
  applyFilters(newFilterConfig) {
    this._onComplete(newFilterConfig);
    this._closeModal();
  }
  buildFilterModal() {
    const filterModal = document.createElement("snk-filter-modal");
    filterModal.className = "ez-size-height--full";
    filterModal.filters = this._filterConfig;
    filterModal.configName = this._configName;
    filterModal.disablePersonalizedFilter = this._disablePersonalizedFilter;
    filterModal.getMessage = this._getMessage.bind(this);
    filterModal.applyFilters = this.applyFilters.bind(this);
    filterModal.closeModal = () => this._closeModal();
    filterModal.addPersonalizedFilter = (isDefault) => this._addPersonalizedFilterFn(isDefault);
    filterModal.editPersonalizedFilter = (id, isDefault) => this._editPersonalizedFilterFn(id, isDefault);
    filterModal.deletePersonalizedFilter = (filter, configName, isDefault) => this._onDeletePersonalizedFilter(filter, configName, isDefault);
    filterModal.filterCustomConfigInterceptor = this._filterCustomConfigInterceptor;
    return filterModal;
  }
  async showModal() {
    const filterModal = this.buildFilterModal();
    const modalProps = {
      content: filterModal,
      position: 'right',
      heightMode: 'full',
      closeOutsideClick: false,
      useScrimLight: true
    };
    this._closeModal = await ApplicationUtils.showModal(modalProps);
  }
  async closeModal() {
    this._closeModal();
  }
}
export default SnkFilterModalFactory;
