import { omit } from "remeda";
const selector_selector = (vchartDatum, selector, selectorMode = 'And')=>{
    if (!selector) return true;
    const vchartKeys = Object.keys(vchartDatum).filter((k)=>k.toLocaleLowerCase().startsWith('__vchart'));
    const datum = omit(vchartDatum, vchartKeys);
    const selectors = Array.isArray(selector) ? selector : [
        selector
    ];
    return selectors['And' === selectorMode ? 'every' : 'some']((selector)=>{
        if (isValueSelector(selector)) {
            if (Object.values(datum).find((v)=>v === selector)) return true;
        } else if (isMeasureSelector(selector)) {
            const op = selector.operator || selector.op;
            const selectorValueArr = Array.isArray(selector.value) ? selector.value : [
                selector.value
            ];
            switch(op){
                case '=':
                    if (String(datum[selector.field]) === String(selectorValueArr[0])) return true;
                    break;
                case '==':
                    if (datum[selector.field] === selectorValueArr[0]) return true;
                    break;
                case '!=':
                    if (datum[selector.field] !== selectorValueArr[0]) return true;
                    break;
                case '>':
                    if (datum[selector.field] > selectorValueArr[0]) return true;
                    break;
                case '<':
                    if (datum[selector.field] < selectorValueArr[0]) return true;
                    break;
                case '>=':
                    if (datum[selector.field] >= selectorValueArr[0]) return true;
                    break;
                case '<=':
                    if (datum[selector.field] <= selectorValueArr[0]) return true;
                    break;
                case 'between':
                    if (Array.isArray(selector.value) && datum[selector.field] >= selectorValueArr[0] && datum[selector.field] <= selectorValueArr[1]) return true;
                    break;
            }
        } else if (isDimensionSelector(selector)) {
            const op = selector.operator || selector.op;
            const selectorValueArr = Array.isArray(selector.value) ? selector.value : [
                selector.value
            ];
            switch(op){
                case 'in':
                    if (selectorValueArr.includes(datum[selector.field])) return true;
                    break;
                case 'not in':
                    if (!selectorValueArr.includes(datum[selector.field])) return true;
                    break;
            }
        } else if (isPartialDatumSelector(selector)) {
            if (Object.keys(selector).every((key)=>datum[key] === selector[key])) return true;
        }
        return false;
    });
};
const isValueSelector = (selector)=>'string' == typeof selector || 'number' == typeof selector;
const isPartialDatumSelector = (selector)=>'object' == typeof selector && null !== selector;
const isMeasureSelector = (selector)=>'object' == typeof selector && null !== selector && 'field' in selector && ('operator' in selector || 'op' in selector) && 'value' in selector && ([
        '=',
        '==',
        '!=',
        '>',
        '<',
        '>=',
        '<=',
        'between'
    ].includes(selector.operator) || [
        '=',
        '==',
        '!=',
        '>',
        '<',
        '>=',
        '<=',
        'between'
    ].includes(selector.op));
const isDimensionSelector = (selector)=>'object' == typeof selector && null !== selector && 'field' in selector && ('operator' in selector || 'op' in selector) && 'value' in selector && ([
        'in',
        'not in'
    ].includes(selector.operator) || [
        'in',
        'not in'
    ].includes(selector.op));
export { isDimensionSelector, isMeasureSelector, isPartialDatumSelector, isValueSelector, selector_selector as selector };

//# sourceMappingURL=selector.js.map