import * as index from '../labels/index.mjs';
import { labelWeekday } from '../labels/labelWeekday.mjs';
import { labelWeekNumberHeader } from '../labels/labelWeekNumberHeader.mjs';
import { labelNav } from '../labels/labelNav.mjs';
import { labelGridcell } from '../labels/labelGridcell.mjs';
import { labelGrid } from '../labels/labelGrid.mjs';
import { labelYearDropdown } from '../labels/labelYearDropdown.mjs';
import { labelWeekNumber } from '../labels/labelWeekNumber.mjs';
import { labelPrevious } from '../labels/labelPrevious.mjs';
import { labelNext } from '../labels/labelNext.mjs';
import { labelMonthDropdown } from '../labels/labelMonthDropdown.mjs';
import { labelDayButton } from '../labels/labelDayButton.mjs';

const resolveLabel = (defaultLabel, customLabel, localeLabel) => {
    if (customLabel)
        return customLabel;
    if (localeLabel) {
        return (typeof localeLabel === "function"
            ? localeLabel
            : (..._args) => localeLabel);
    }
    return defaultLabel;
};
/**
 * Merges custom labels from the props with the default labels.
 *
 * When available, uses the locale-provided translation for `labelNext`.
 *
 * @param customLabels The custom labels provided in the DayPicker props.
 * @param options Options from the date library, used to resolve locale
 *   translations.
 * @returns The merged labels object with locale-aware defaults.
 */
function getLabels(customLabels, options) {
    const localeLabels = options.locale?.labels ?? {};
    return {
        ...index,
        ...(customLabels ?? {}),
        labelDayButton: resolveLabel(labelDayButton, customLabels?.labelDayButton, localeLabels.labelDayButton),
        labelMonthDropdown: resolveLabel(labelMonthDropdown, customLabels?.labelMonthDropdown, localeLabels.labelMonthDropdown),
        labelNext: resolveLabel(labelNext, customLabels?.labelNext, localeLabels.labelNext),
        labelPrevious: resolveLabel(labelPrevious, customLabels?.labelPrevious, localeLabels.labelPrevious),
        labelWeekNumber: resolveLabel(labelWeekNumber, customLabels?.labelWeekNumber, localeLabels.labelWeekNumber),
        labelYearDropdown: resolveLabel(labelYearDropdown, customLabels?.labelYearDropdown, localeLabels.labelYearDropdown),
        labelGrid: resolveLabel(labelGrid, customLabels?.labelGrid, localeLabels.labelGrid),
        labelGridcell: resolveLabel(labelGridcell, customLabels?.labelGridcell, localeLabels.labelGridcell),
        labelNav: resolveLabel(labelNav, customLabels?.labelNav, localeLabels.labelNav),
        labelWeekNumberHeader: resolveLabel(labelWeekNumberHeader, customLabels?.labelWeekNumberHeader, localeLabels.labelWeekNumberHeader),
        labelWeekday: resolveLabel(labelWeekday, customLabels?.labelWeekday, localeLabels.labelWeekday),
    };
}

export { getLabels };
