'use strict';

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

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

const DateFilterPanel = class {
    constructor(hostRef) {
        core.registerInstance(this, hostRef);
        this.anjFilterChange = core.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 (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('Start Date')), core.h("anj-input", { name: "min", max: this.max }, core.h("anj-date-picker-toggle", null), core.h("anj-date-picker", null))) : undefined, this.types.includes('ends-with') || this.types.includes('contains') ?
            core.h("anj-form-group", null, core.h("anj-label", null, this.translator('End Date')), core.h("anj-input", { name: "max", min: this.min }, core.h("anj-date-picker-toggle", null), core.h("anj-date-picker", null))) : 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-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}"; }
};
i18n_provider.Tunnel.injectProps(DateFilterPanel, ['translator']);

exports.anj_date_filter_panel = DateFilterPanel;
