// Fusion Accounting - Aged Partner Balance Filters
// Copyright (C) 2026 Nexa Systems Inc.

import { _t } from "@web/core/l10n/translation";
import { WarningDialog } from "@web/core/errors/error_dialogs";
import { AccountReport } from "@fusion_accounting/components/account_report/account_report";
import { AccountReportFilters } from "@fusion_accounting/components/account_report/filters/filters";

/**
 * AgedPartnerBalanceFilters - Extended filter panel for the aged partner
 * balance report, adding aging interval configuration controls.
 */
export class AgedPartnerBalanceFilters extends AccountReportFilters {
    static template = "fusion_accounting.AgedPartnerBalanceFilters";

    //------------------------------------------------------------------------------------------------------------------
    // Aging Interval
    //------------------------------------------------------------------------------------------------------------------
    async setAgingInterval(ev) {
        const agingInterval = parseInt(ev.target.value);
        if (agingInterval < 1) {
            this.dialog.add(WarningDialog, {
                title: _t("Odoo Warning"),
                message: _t("Intervals cannot be smaller than 1"),
            });
            return;
        }

        await this.filterClicked({ optionKey:"aging_interval", optionValue: agingInterval, reload: true });
    }

}

AccountReport.registerCustomComponent(AgedPartnerBalanceFilters);
