import * as __WEBPACK_EXTERNAL_MODULE__tachybase_utils_client__ from "@tachybase/utils/client";
import * as __WEBPACK_EXTERNAL_MODULE_lodash__ from "lodash";
const defaultFieldNames = {
    label: 'label',
    value: 'value',
    color: 'color',
    options: 'children'
};
function flatData(data, fieldNames) {
    const newArr = [];
    if (!Array.isArray(data)) return newArr;
    for(let i = 0; i < data.length; i++){
        const children = data[i][fieldNames.options];
        if (Array.isArray(children)) newArr.push(...flatData(children, fieldNames));
        newArr.push({
            ...data[i]
        });
    }
    return newArr;
}
function getCurrentOptions(values, dataSource, fieldNames) {
    const result = flatData(dataSource, fieldNames);
    const arrValues = (0, __WEBPACK_EXTERNAL_MODULE_lodash__.castArray)(values).filter((item)=>null != item).map((val)=>(0, __WEBPACK_EXTERNAL_MODULE__tachybase_utils_client__.isPlainObject)(val) ? val[fieldNames.value] : val);
    function findOptions(options) {
        if (!options) return [];
        const current = [];
        for (const value of arrValues){
            const option = options.find((v)=>v[fieldNames.value] == value) || {
                value,
                label: value ? value.toString() : value
            };
            current.push(option);
        }
        return current;
    }
    return findOptions(result);
}
export { defaultFieldNames, getCurrentOptions };
