import { r as registerInstance, j as createEvent, h, g as getElement } from './index-07845439.js';
import { d as dist$1 } from './index-b6cf748e.js';
import { d as dist } from './index-63517df5.js';
import './_commonjsHelpers-8fe71198.js';

const sv = {
  Filter: "Filtrera",
  "Remove filter": "Ta bort filter",
  "Apply filter": "Tillämpa filter",
};

function create(language) {
  return dist.create({
    sv,
  }, language);
}

const styleCss = ".sc-ig-filter-h{display:block;width:100%;max-width:90em;margin:auto}[hidden].sc-ig-filter-h{display:none}.sc-ig-filter-h>form.sc-ig-filter{border:1px solid rgb(var(--smoothly-medium-color));margin:0.2em 0 0.5em 0;clear:both}.sc-ig-filter-h>form.sc-ig-filter>ig-autocomplete-input.sc-ig-filter{width:calc(100% - 80px);display:inline-block}.sc-ig-filter-h>form.sc-ig-filter>smoothly-input.sc-ig-filter{width:calc(100% - 80px);display:inline-block}.sc-ig-filter-h>form.sc-ig-filter>smoothly-submit.sc-ig-filter{display:inline-block}";

const IntergiroFilter = class {
  constructor(hostRef) {
    registerInstance(this, hostRef);
    this.filterChanged = createEvent(this, "filterChanged", 7);
    this.textEntered = false;
    this.criteriaString = "";
  }
  async componentWillLoad() {
    this.t = create(this.element);
  }
  checkTextEntered() {
    const input = this.inputElement;
    if (hasValue(input))
      this.textEntered = input.value != "";
  }
  onFilter(e) {
    this.criteriaString = e.detail.filter;
    this.applyFilter();
    this.checkTextEntered();
  }
  criteriaStringChanged() {
    const input = this.inputElement;
    if (hasValue(input))
      input.value = this.criteriaString;
    this.textEntered = true;
    this.applyFilter();
  }
  applyFilter(criteria) {
    this.filter = criteria || dist$1.and(dist$1.parse(this.criteriaString)).generalize();
    this.filterChanged.emit(this.value ? dist$1.filter(this.filter, this.value) : this.filter);
  }
  reset() {
    this.criteriaString = "";
    this.applyFilter();
    const input = this.inputElement;
    if (hasValue(input))
      input.value = "";
    this.textEntered = false;
  }
  render() {
    return (h("form", null, h("ig-autocomplete-input", { template: this.template, ref: (el) => (this.inputElement = el), name: "filter", onKeyDown: this.checkTextEntered.bind(this) }, this.t("Filter")), h("smoothly-submit", { fill: "clear", prevent: true, onSubmit: (e) => this.onFilter(e), style: { visibility: this.textEntered ? "visible" : "hidden" } }, h("smoothly-icon", { toolTip: this.t("Apply filter"), name: "search", size: "small" })), h("smoothly-submit", { fill: "clear", prevent: true, onSubmit: () => this.reset() }, h("smoothly-icon", { toolTip: this.t("Remove filter"), size: "small", name: "backspace" }))));
  }
  get element() { return getElement(this); }
  static get watchers() { return {
    "criteriaString": ["criteriaStringChanged"]
  }; }
};
function hasValue(element) {
  return element.value == undefined || typeof element.value === "string";
}
IntergiroFilter.style = styleCss;

export { IntergiroFilter as ig_filter };
