"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getReferencedDimensionCaseInsensitive = exports.getReferencedMetric = exports.getReferencedDimension = exports.getReferencedTable = void 0;
const getReferencedTable = (refTable, tables) => {
    if (tables[refTable]) {
        return tables[refTable];
    }
    return Object.values(tables).find((table) => table.name === refTable || table.originalName === refTable);
};
exports.getReferencedTable = getReferencedTable;
const getReferencedDimension = (refTable, refName, tables) => (0, exports.getReferencedTable)(refTable, tables)?.dimensions[refName];
exports.getReferencedDimension = getReferencedDimension;
const getReferencedMetric = (refTable, refName, tables) => (0, exports.getReferencedTable)(refTable, tables)?.metrics[refName];
exports.getReferencedMetric = getReferencedMetric;
const getReferencedDimensionCaseInsensitive = (refTable, refName, tables) => {
    const table = tables[refTable];
    if (!table) {
        return undefined;
    }
    // NOTE: date dimensions from explores have their time format uppercased
    // (e.g. order_date_DAY) - see ticket:
    // https://github.com/lightdash/lightdash/issues/5998
    const dimensionRefName = Object.keys(table.dimensions).find((key) => key.toLowerCase() === refName.toLowerCase());
    return dimensionRefName ? table.dimensions[dimensionRefName] : undefined;
};
exports.getReferencedDimensionCaseInsensitive = getReferencedDimensionCaseInsensitive;
//# sourceMappingURL=referenceLookup.js.map