'use strict';

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

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

const NumberFilterPanel = class {
    constructor(hostRef) {
        core.registerInstance(this, hostRef);
        this.anjFilterChange = core.createEvent(this, "anjFilterChange", 7);
    }
    onChange({ detail, target }) {
        const el = target;
        this[el.name] = detail.checked ? detail.checked : detail.value;
    }
    async reset() {
        this.element.querySelector('form').reset();
        this.max = undefined;
        this.min = undefined;
    }
    onSubmit(e) {
        e.preventDefault();
        const filter = { field: this.field };
        const valid = e.target.checkValidity();
        if (!valid)
            return;
        let query;
        let type;
        if (utils.hasValue(this.min) && utils.hasValue(this.max)) {
            type = 'contains';
            query = [parseInt(this.min, 10), parseInt(this.max, 10)];
        }
        else if (utils.hasValue(this.min)) {
            type = 'starts-with';
            query = parseInt(this.min, 10);
        }
        else {
            type = 'ends-with';
            query = parseInt(this.max, 10);
        }
        if (utils.hasValue(query)) {
            filter.type = type;
            filter.query = query;
            this.anjFilterChange.emit(filter);
        }
    }
    render() {
        return (core.h("form", { onSubmit: (e) => this.onSubmit(e), novalidate: true }, this.types.includes('starts-with') || this.types.includes('contains') ?
            core.h("anj-form-group", null, core.h("anj-label", null, this.translator('Min')), core.h("anj-input", { name: "min", type: "number", max: this.max, value: this.min })) : undefined, this.types.includes('ends-with') || this.types.includes('contains') ?
            core.h("anj-form-group", null, core.h("anj-label", null, this.translator('Max')), core.h("anj-input", { name: "max", type: "number", min: this.min, value: this.max })) : undefined, 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-number-filter-panel-h {\n  display: block;\n  padding: 1rem;\n}\n.sc-anj-number-filter-panel-h anj-button-group.sc-anj-number-filter-panel {\n  margin-bottom: 0;\n}"; }
};
i18n_provider.Tunnel.injectProps(NumberFilterPanel, ['translator']);

exports.anj_number_filter_panel = NumberFilterPanel;
