'use strict';

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

const core = require('./core-b7b9d752.js');
const i18n_provider = require('./i18n.provider-5632e5ed.js');

var FilterTypeLabels;
(function (FilterTypeLabels) {
    FilterTypeLabels["contains"] = "Contains";
    FilterTypeLabels["ends-with"] = "Ends With";
    FilterTypeLabels["equals"] = "Equals";
    FilterTypeLabels["starts-with"] = "Starts With";
})(FilterTypeLabels || (FilterTypeLabels = {}));
const StringFilterPanel = class {
    constructor(hostRef) {
        core.registerInstance(this, hostRef);
        this.anjFilterChange = core.createEvent(this, "anjFilterChange", 7);
    }
    async reset() {
        this.element.querySelector('form').reset();
    }
    componentWillLoad() {
        this.type = this.filter ? this.filter.type : this.types[0] || 'contains';
    }
    onSubmit(e) {
        e.preventDefault();
        const filter = {};
        Array.from(e.target.querySelectorAll('input')).forEach((i) => {
            filter[i.name] = i.value.trim() !== '' ? i.value.trim() : undefined;
        });
        filter.type = this.type;
        this.anjFilterChange.emit(filter);
    }
    render() {
        return (core.h("form", { onSubmit: (e) => this.onSubmit(e) }, core.h("input", { type: "hidden", name: "field", value: this.field }), this.types.length > 1 ?
            core.h("anj-form-group", null, core.h("anj-label", null, this.translator('Type')), core.h("anj-select", { name: "type", value: this.type, onAnjChange: e => this.type = e.detail.value }, this.types.map(t => core.h("anj-option", { value: t }, this.translator(FilterTypeLabels[t])))))
            : undefined, core.h("anj-form-group", null, core.h("anj-label", null, this.translator('Filter')), core.h("anj-input", { name: "query" })), core.h("anj-button-group", { align: "right" }, core.h("anj-button", { context: "text", type: "submit" }, this.translator('Apply')))));
    }
    get element() { return core.getElement(this); }
    static get style() { return ".sc-anj-string-filter-panel-h {\n  display: block;\n  padding: 1rem;\n}\n.sc-anj-string-filter-panel-h anj-button-group.sc-anj-string-filter-panel {\n  margin-bottom: 0;\n}"; }
};
i18n_provider.Tunnel.injectProps(StringFilterPanel, ['translator']);

exports.anj_string_filter_panel = StringFilterPanel;
