import { selector, selectorWithDynamicFilter } from "../../../../../dataSelector/index.js";
import { isEmpty, isNullish } from "remeda";
const barStyle_barStyle = (spec, context)=>{
    const { advancedVSeed } = context;
    const { markStyle, dataset = [] } = advancedVSeed;
    const { barStyle } = markStyle;
    const showStroke = dataset.length <= 100;
    const result = {
        ...spec,
        bar: {
            style: {
                visible: true,
                fillOpacity: 1,
                lineWidth: showStroke ? 1 : 0
            },
            state: {
                hover: {
                    fillOpacity: 0.6
                }
            }
        }
    };
    if (isNullish(barStyle) || isEmpty(barStyle)) return result;
    const barStyles = Array.isArray(barStyle) ? barStyle : [
        barStyle
    ];
    const customMap = barStyles.reduce((result, style, index)=>{
        const { barBorderColor, barBorderStyle, barBorderWidth = 1, barColor, barColorOpacity, barBorderOpacity, barRadius, barVisible = true } = style;
        const lineDash = 'dashed' === barBorderStyle ? [
            5,
            2
        ] : 'dotted' === barBorderStyle ? [
            2,
            5
        ] : [
            0,
            0
        ];
        return {
            ...result,
            [`custom${index + 1}`]: {
                level: index + 1,
                filter: (datum)=>{
                    const shouldApply = style.dynamicFilter ? selectorWithDynamicFilter(datum, style.dynamicFilter, style.selector) : selector(datum, style.selector);
                    if (shouldApply) return true;
                    return false;
                },
                style: {
                    visible: barVisible,
                    fill: barColor,
                    fillOpacity: barColorOpacity,
                    cornerRadius: barRadius,
                    lineWidth: barBorderWidth,
                    stroke: barBorderColor,
                    strokeOpacity: barBorderOpacity,
                    lineDash: lineDash
                }
            }
        };
    }, {});
    result.bar.state = {
        ...result.bar.state,
        ...customMap
    };
    return result;
};
export { barStyle_barStyle as barStyle };

//# sourceMappingURL=barStyle.js.map