/*!
 * Built by ShiftSoftware
 * Copyright (c)
 */
import { getNestedValue } from "./get-nested-value";
const getObjectValue = (obj, path) => {
    if (typeof path === 'string')
        return getNestedValue(obj, path);
    return path.map(itemPath => getNestedValue(obj, itemPath)).find(value => value != null);
};
export const populateItems = (data, setup, hasMeta) => {
    const options = [];
    const baseOptions = getObjectValue(data, setup.items);
    baseOptions.forEach(item => {
        const value = getObjectValue(item, setup['item-value']);
        const label = getObjectValue(item, setup['item-label']);
        const newItemObject = { value: (setup === null || setup === void 0 ? void 0 : setup.useNamedValue) ? label : value, label };
        if (hasMeta)
            newItemObject.meta = Object.assign({}, item);
        options.push(newItemObject);
    });
    return options;
};
