import { r as registerInstance, d as createEvent, h, c as getElement } from './core-3f33e631.js';
import { j as hasValue } from './utils-3aef1637.js';
import { T as Tunnel } from './i18n.provider-106e9203.js';

const NumberFilterPanel = class {
    constructor(hostRef) {
        registerInstance(this, hostRef);
        this.anjFilterChange = 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 (hasValue(this.min) && hasValue(this.max)) {
            type = 'contains';
            query = [parseInt(this.min, 10), parseInt(this.max, 10)];
        }
        else if (hasValue(this.min)) {
            type = 'starts-with';
            query = parseInt(this.min, 10);
        }
        else {
            type = 'ends-with';
            query = parseInt(this.max, 10);
        }
        if (hasValue(query)) {
            filter.type = type;
            filter.query = query;
            this.anjFilterChange.emit(filter);
        }
    }
    render() {
        return (h("form", { onSubmit: (e) => this.onSubmit(e), novalidate: true }, this.types.includes('starts-with') || this.types.includes('contains') ?
            h("anj-form-group", null, h("anj-label", null, this.translator('Min')), h("anj-input", { name: "min", type: "number", max: this.max, value: this.min })) : undefined, this.types.includes('ends-with') || this.types.includes('contains') ?
            h("anj-form-group", null, h("anj-label", null, this.translator('Max')), h("anj-input", { name: "max", type: "number", min: this.min, value: this.max })) : undefined, h("anj-button-group", { align: "right" }, h("anj-button", { context: "text", type: "submit" }, this.translator('Apply')))));
    }
    get element() { return 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}"; }
};
Tunnel.injectProps(NumberFilterPanel, ['translator']);

export { NumberFilterPanel as anj_number_filter_panel };
