/** @odoo-module */

import { patch } from "@web/core/utils/patch";
import { getRelativeDateDomain } from "@spreadsheet/global_filters/helpers";
import * as helpers from "@spreadsheet/global_filters/helpers";
import { serializeDate, serializeDateTime } from "@web/core/l10n/dates";
import { Domain } from "@web/core/domain";

const originalGetRelativeDateDomain = helpers.getRelativeDateDomain;

patch(helpers, {
    getRelativeDateDomain(now, offset, rangeType, fieldName, fieldType) {
    console.log(" inside getRelativeDateDomain ");
        if (rangeType === "today") {getRelativeDateDomain
            const offsetParam = { days: offset };
            const startDate = now.startOf("day").plus(offsetParam);
            const endDate = now.endOf("day").plus(offsetParam);

            let leftBound, rightBound;
            if (fieldType === "date") {
                leftBound = serializeDate(startDate);
                rightBound = serializeDate(endDate);
            } else {
                leftBound = serializeDateTime(startDate);
                rightBound = serializeDateTime(endDate);
            }
            return new Domain(["&", [fieldName, ">=", leftBound], [fieldName, "<=", rightBound]]);
        }
        return originalGetRelativeDateDomain(now, offset, rangeType, fieldName, fieldType);
    },
});