import { r as registerInstance, d as createEvent, h, c as getElement } from './core-b78a8f7e.js';
import { T as Tunnel } from './i18n.provider-59e68a9d.js';

const DateFilterPanel = class {
    constructor(hostRef) {
        registerInstance(this, hostRef);
        this.anjFilterChange = createEvent(this, "anjFilterChange", 7);
    }
    onChange({ detail, target }) {
        const input = target;
        this[input.name] = detail.innerValue;
    }
    async reset() {
        this.element.querySelector('form').reset();
        this.max = undefined;
        this.min = undefined;
    }
    onSubmit(e) {
        e.preventDefault();
        const valid = e.target.checkValidity();
        if (!valid)
            return;
        const filter = { field: this.field };
        let query;
        let type;
        if (this.min && this.max) {
            type = 'contains';
            query = [new Date(this.min), new Date(this.max)];
        }
        else if (this.min) {
            type = 'starts-with';
            query = new Date(this.min);
        }
        else {
            type = 'ends-with';
            query = new Date(this.max);
        }
        if (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('Start Date')), h("anj-input", { name: "min", max: this.max }, h("anj-date-picker-toggle", null), h("anj-date-picker", null))) : undefined, this.types.includes('ends-with') || this.types.includes('contains') ?
            h("anj-form-group", null, h("anj-label", null, this.translator('End Date')), h("anj-input", { name: "max", min: this.min }, h("anj-date-picker-toggle", null), h("anj-date-picker", null))) : 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-date-filter-panel-h {\n  display: block;\n  padding: 1rem;\n}\n.sc-anj-date-filter-panel-h anj-button-group.sc-anj-date-filter-panel {\n  margin-bottom: 0;\n}"; }
};
Tunnel.injectProps(DateFilterPanel, ['translator']);

export { DateFilterPanel as anj_date_filter_panel };
