import { defaultTheme } from './defaultTheme';
const isRecord = (value) => {
    return typeof value === 'object' && value !== null && !Array.isArray(value);
};
const merge = (base, overrides) => {
    if (!isRecord(base) || overrides === undefined || overrides === null) {
        return (overrides ?? base);
    }
    const baseRecord = base;
    const overrideRecord = overrides;
    const result = { ...baseRecord };
    for (const key of Object.keys(overrideRecord)) {
        const baseValue = baseRecord[key];
        const overrideValue = overrideRecord[key];
        if (overrideValue === undefined) {
            continue;
        }
        if (isRecord(baseValue) && isRecord(overrideValue)) {
            result[key] = merge(baseValue, overrideValue);
        }
        else {
            result[key] = overrideValue;
        }
    }
    return result;
};
export const createTheme = (overrides, baseTheme = defaultTheme) => {
    if (!overrides) {
        return merge(baseTheme, {});
    }
    return merge(baseTheme, overrides);
};
