odoo.define('month_filter.ModeExtension', function (require) {
    "use strict";
    const components = {
      ControlPanelModelExtension: require("web/static/src/js/control_panel/control_panel_model_extension.js"),
    };
    const { patch } = require("web.utils");
    const Domain = require('web.Domain');
    const pyUtils = require('web.py_utils');

    const { DEFAULT_INTERVAL, DEFAULT_PERIOD,
        getComparisonOptions, getIntervalOptions, getPeriodOptions,
        constructDateDomain, rankInterval, yearSelected } = require('month_filter.searchUtils');

    patch(
      components.ControlPanelModelExtension,
      "month_filter/static/src/js/control_panel/control_panel_custom_extension.js",
      {
        toggleFilterWithOptions(filterId, optionId) {
            this.referenceMoment = moment();
            this.optionGenerators = getPeriodOptions(this.referenceMoment);
            return this._super(filterId, optionId);
        },
        _enrichFilterCopy(filter, filterQueryElements) {
            this.referenceMoment = moment();
            this.optionGenerators = getPeriodOptions(this.referenceMoment);
            return this._super(filter, filterQueryElements);
        },
        _getDateFilterDomain(filter, filterQueryElements, key = 'domain') {
            const { fieldName, fieldType } = filter;
            const selectedOptionIds = filterQueryElements.map(queryElem => queryElem.optionId);

            const dateFilterRange = constructDateDomain(
                this.referenceMoment, fieldName, fieldType, selectedOptionIds,
            );
            return dateFilterRange[key];
        },
      }
    );
    });