import { selector, selectorWithDynamicFilter } from "../../../../../dataSelector/index.js";
import { isEmpty, isNullish } from "remeda";
import { getCurveTension, getCurveType } from "./curve/index.js";
const lineStyle_lineStyle = (spec, context)=>{
    const { advancedVSeed } = context;
    const { markStyle } = advancedVSeed;
    const { lineStyle } = markStyle;
    const result = {
        ...spec,
        line: {
            style: {}
        }
    };
    if (isNullish(lineStyle) || isEmpty(lineStyle)) return result;
    const lineStyles = Array.isArray(lineStyle) ? lineStyle : [
        lineStyle
    ];
    const customMap = lineStyles.reduce((result, style, index)=>{
        const { lineColor, lineColorOpacity, lineSmooth, lineStyle, lineWidth = 2, lineVisible = true } = style;
        const dashSegment = 2 * lineWidth;
        const dashGap = lineWidth;
        const lineDash = 'dashed' === lineStyle ? [
            dashSegment,
            dashSegment
        ] : 'dotted' === lineStyle ? [
            dashGap / 2,
            2 * dashGap
        ] : [
            0,
            0
        ];
        const curveType = getCurveType(context.vseed, lineSmooth);
        const curveTension = getCurveTension(context.vseed, lineSmooth);
        return {
            ...result,
            [`custom${index + 1}`]: {
                level: index + 1,
                filter: (_, node)=>{
                    const lineData = node.renderNode.context.data;
                    for (const d of lineData){
                        const shouldApply = style.dynamicFilter ? selectorWithDynamicFilter(d, style.dynamicFilter, style.selector) : selector(d, style.selector);
                        if (shouldApply) return true;
                    }
                    return false;
                },
                style: {
                    visible: lineVisible,
                    curveType: curveType,
                    curveTension: curveTension,
                    strokeOpacity: lineColorOpacity,
                    stroke: lineColor,
                    lineWidth: lineWidth,
                    lineDash: lineDash
                }
            }
        };
    }, {});
    return {
        ...result,
        line: {
            ...result.line,
            state: {
                ...customMap
            }
        }
    };
};
export { lineStyle_lineStyle as lineStyle };

//# sourceMappingURL=lineStyle.js.map