var __awaiter=this&&this.__awaiter||function(t,e,i,r){function n(t){return t instanceof i?t:new i((function(e){e(t)}))}return new(i||(i=Promise))((function(i,l){function o(t){try{s(r.next(t))}catch(t){l(t)}}function a(t){try{s(r["throw"](t))}catch(t){l(t)}}function s(t){t.done?i(t.value):n(t.value).then(o,a)}s((r=r.apply(t,e||[])).next())}))};var __generator=this&&this.__generator||function(t,e){var i={label:0,sent:function(){if(l[0]&1)throw l[1];return l[1]},trys:[],ops:[]},r,n,l,o;return o={next:a(0),throw:a(1),return:a(2)},typeof Symbol==="function"&&(o[Symbol.iterator]=function(){return this}),o;function a(t){return function(e){return s([t,e])}}function s(o){if(r)throw new TypeError("Generator is already executing.");while(i)try{if(r=1,n&&(l=o[0]&2?n["return"]:o[0]?n["throw"]||((l=n["return"])&&l.call(n),0):n.next)&&!(l=l.call(n,o[1])).done)return l;if(n=0,l)o=[o[0]&2,l.value];switch(o[0]){case 0:case 1:l=o;break;case 4:i.label++;return{value:o[1],done:false};case 5:i.label++;n=o[1];o=[0];continue;case 7:o=i.ops.pop();i.trys.pop();continue;default:if(!(l=i.trys,l=l.length>0&&l[l.length-1])&&(o[0]===6||o[0]===2)){i=0;continue}if(o[0]===3&&(!l||o[1]>l[0]&&o[1]<l[3])){i.label=o[1];break}if(o[0]===6&&i.label<l[1]){i.label=l[1];l=o;break}if(l&&i.label<l[2]){i.label=l[2];i.ops.push(o);break}if(l[2])i.ops.pop();i.trys.pop();continue}o=e.call(t,i)}catch(t){o=[6,t];n=0}finally{r=l=0}if(o[0]&5)throw o[1];return{value:o[0]?o[1]:void 0,done:true}}};import{r as registerInstance,c as createEvent,h,g as getElement}from"./index-08b73e9e.js";import{d as dist$1}from"./index-f77ff597.js";import{d as dist}from"./index-a0a71287.js";import"./_commonjsHelpers-9943807e.js";import"./index-1f953d81.js";var sv={Filter:"Filtrera","Remove filter":"Ta bort filter","Apply filter":"Tillämpa filter"};function create(t){return dist.create({sv:sv},t)}var 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}";var IntergiroFilter=function(){function t(t){registerInstance(this,t);this.filterChanged=createEvent(this,"filterChanged",7);this.textEntered=false;this.criteriaString=""}t.prototype.componentWillLoad=function(){return __awaiter(this,void 0,void 0,(function(){return __generator(this,(function(t){this.t=create(this.element);return[2]}))}))};t.prototype.checkTextEntered=function(){var t=this.inputElement;if(hasValue(t))this.textEntered=t.value!=""};t.prototype.onFilter=function(t){this.criteriaString=t.detail.filter;this.applyFilter();this.checkTextEntered()};t.prototype.criteriaStringChanged=function(){var t=this.inputElement;if(hasValue(t))t.value=this.criteriaString;this.textEntered=true;this.applyFilter()};t.prototype.applyFilter=function(t){this.filter=t||dist$1.and(dist$1.parse(this.criteriaString)).generalize();this.filterChanged.emit(this.value?dist$1.filter(this.filter,this.value):this.filter)};t.prototype.reset=function(){this.criteriaString="";this.applyFilter();var t=this.inputElement;if(hasValue(t))t.value="";this.textEntered=false};t.prototype.render=function(){var t=this;return h("form",null,h("ig-autocomplete-input",{template:this.template,ref:function(e){return t.inputElement=e},name:"filter",onKeyDown:this.checkTextEntered.bind(this)},this.t("Filter")),h("smoothly-submit",{fill:"clear",prevent:true,onSubmit:function(e){return t.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:function(){return t.reset()}},h("smoothly-icon",{toolTip:this.t("Remove filter"),size:"small",name:"backspace"})))};Object.defineProperty(t.prototype,"element",{get:function(){return getElement(this)},enumerable:false,configurable:true});Object.defineProperty(t,"watchers",{get:function(){return{criteriaString:["criteriaStringChanged"]}},enumerable:false,configurable:true});return t}();function hasValue(t){return t.value==undefined||typeof t.value==="string"}IntergiroFilter.style=styleCss;export{IntergiroFilter as ig_filter};