'use strict';

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

const index$1 = require('./index-df541290.js');
const index$2 = require('./index-0b6f1dd9.js');
const index = require('./index-b7493032.js');
require('./_commonjsHelpers-10109b76.js');

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

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

exports.ig_filter = IntergiroFilter;
