'use strict';

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

const index = require('./index-17105557.js');
const defaultFilters = require('./default-filters-a09bf82b.js');

const snkDefaultFilterCss = ".sc-snk-default-filter-h{display:flex;justify-content:flex-end}.default_container.sc-snk-default-filter{border:none;background:none;display:flex;align-items:center;gap:var(--space--3xs, 4px);font-family:var(--font-pattern);color:var(--title--primary, #2b3a54);font-size:var(--text--medium, 14px);padding:0;outline:none}.default_container.sc-snk-default-filter ez-icon.sc-snk-default-filter{cursor:pointer}.default_container.sc-snk-default-filter ez-icon.sc-snk-default-filter:hover{color:var(--color--primary-600)}.new_filter.sc-snk-default-filter{cursor:pointer;margin:0 var(--space--3xs, 4px)}.new_filter.sc-snk-default-filter:hover{color:var(--color--primary-600)}";

const SnkDefaultFilter = class {
  constructor(hostRef) {
    index.registerInstance(this, hostRef);
    this.actionSelected = index.createEvent(this, "actionSelected", 7);
    this.OFFSET_HEIGHT = 5;
    this.getMessage = undefined;
    this.hasDefaultFilter = false;
    this._opened = false;
  }
  repositionDropDown() {
    if (!this._refIcon || !this._refDropdown) {
      return;
    }
    const boundingIcon = this._refIcon.getBoundingClientRect();
    const boundingDropDown = this._refDropdown.getBoundingClientRect();
    this._refDropdown.style.top = (boundingIcon.y + boundingIcon.height + this.OFFSET_HEIGHT) + "px";
    this._refDropdown.style.left = ((boundingIcon.x + (boundingIcon.width / 2)) - boundingDropDown.width) + "px";
  }
  toggleDropdown() {
    this._opened = !this._opened;
  }
  closeDropdown(evt) {
    const target = evt === null || evt === void 0 ? void 0 : evt.target;
    if (!target) {
      return;
    }
    if (!target.closest("#dropdown-parent-demo")) {
      this._opened = false;
    }
  }
  buildItems() {
    return ([
      {
        id: defaultFilters.ActionDefaultFilter.EDIT,
        label: this.getMessage('defaultFilter.edit'),
      },
      {
        id: defaultFilters.ActionDefaultFilter.REMOVE,
        label: this.getMessage('defaultFilter.remove'),
      },
    ]);
  }
  onValueSelected({ detail: item }) {
    this._opened = false;
    this.actionSelected.emit(item.id);
  }
  openCreateNewFilter() {
    this.actionSelected.emit(defaultFilters.ActionDefaultFilter.CREATE);
  }
  componentDidRender() {
    this.repositionDropDown();
  }
  componentWillLoad() {
    this._items = this.buildItems();
    document.removeEventListener("scroll", this.repositionDropDown.bind(this));
    document.addEventListener("scroll", this.repositionDropDown.bind(this));
  }
  render() {
    if (!this.hasDefaultFilter) {
      return (index.h(index.Host, null, index.h("button", { class: "default_container new_filter", onClick: this.openCreateNewFilter.bind(this) }, index.h("span", null, this.getMessage('defaultFilter.create')))));
    }
    return (index.h(index.Host, null, index.h("button", { class: "default_container", onClick: this.toggleDropdown.bind(this) }, index.h("span", null, this.getMessage('defaultFilter.title')), index.h("ez-icon", { ref: (ref) => this._refIcon = ref, iconName: 'dots-vertical' })), this._opened &&
      index.h("ez-dropdown", { ref: (ref) => this._refDropdown = ref, items: this._items, onEzClick: this.onValueSelected.bind(this), onEzOutsideClick: this.closeDropdown.bind(this) })));
  }
};
SnkDefaultFilter.style = snkDefaultFilterCss;

exports.snk_default_filter = SnkDefaultFilter;
