/* @oracle/oraclejet-preact: undefined */
import { jsxs, Fragment, jsx } from 'preact/jsx-runtime';
import { styles } from './PRIVATE_PlotArea/themes/PlotAreaStyles.css.js';
import { styles as styles$1 } from './hooks/PRIVATE_useVisDnd/themes/VisDndStyles.css.js';
import { c as classNames } from './classNames-4e12b00d.js';
import { u as useColorScheme } from './useColorScheme-c4e237ad.js';

function getXAxisLineProps(availSpace, axisPosition, axisLine) {
    return {
        x1: axisPosition === 'right' ? availSpace.x + availSpace.width : availSpace.x,
        x2: axisPosition === 'left' ? availSpace.x : availSpace.x + availSpace.width,
        y1: axisPosition === 'bottom' ? availSpace.y + availSpace.height : availSpace.y,
        y2: axisPosition === 'top' ? availSpace.y : availSpace.y + availSpace.height,
        stroke: axisLine?.lineColor,
        strokeWidth: axisLine?.lineWidth
    };
}
function getYAxisLineProps(availSpace, isRtl, axisLine) {
    return {
        x1: isRtl ? availSpace.x + availSpace.width : availSpace.x,
        x2: isRtl ? availSpace.x + availSpace.width : availSpace.x,
        y1: availSpace.y,
        y2: availSpace.y + availSpace.height,
        stroke: axisLine?.lineColor,
        strokeWidth: axisLine?.lineWidth
    };
}
function getBaseLineProps(availSpace, coord, axisPosition) {
    let x1, x2, y1, y2;
    if (axisPosition === 'bottom') {
        x1 = availSpace.x;
        x2 = availSpace.x + availSpace.width;
        y1 = coord;
        y2 = coord;
    }
    else {
        x1 = coord;
        x2 = coord;
        y1 = availSpace.y;
        y2 = availSpace.y + availSpace.height;
    }
    return { x1, x2, y1, y2 };
}

function PlotArea({ color, yScale, isLog, availSpace, xAxisPosition, cursor, isDataXAxis, isRtl, hasAxisLine, dragOverStyle }) {
    const hasBaseLine = !isLog && yScale.domain()[0] < 0 && yScale.domain()[1] > 0;
    const xAxisLineProps = getXAxisLineProps(availSpace, xAxisPosition);
    const baseLineProps = getBaseLineProps(availSpace, yScale.transform(0), xAxisPosition);
    const dragClass = [];
    switch (dragOverStyle) {
        case 'accept':
            dragClass.push(styles$1.dndDragOverSvgStyle);
            break;
        case 'reject':
            dragClass.push(styles$1.dndRejectedStyle);
            dragClass.push(styles.plotAreaStyle);
            break;
        case 'none':
            dragClass.push(styles.plotAreaStyle);
            break;
    }
    return (jsxs(Fragment, { children: [jsx("rect", { ...availSpace, class: classNames(dragClass), style: { fill: dragOverStyle === 'accept' ? undefined : color, cursor } }), isDataXAxis && (jsx("line", { ...getYAxisLineProps(availSpace, isRtl), class: styles.axisLineStyle })), hasAxisLine && jsx("line", { ...xAxisLineProps, class: styles.axisLineStyle }), hasBaseLine && jsx("line", { ...baseLineProps, class: styles.baseLineStyle })] }));
}

const TICK_DEFAULT = {
    yMajorTick: {
        isRendered: true
    },
    yMinorTick: {
        isRendered: false
    },
    xMajorTick: {
        isRendered: false
    },
    xMinorTick: {
        isRendered: false
    }
};
function Gridlines({ plotArea = TICK_DEFAULT, yMinorTicks, xMinorTicks, xScale, yScale, isLog, yTicks, xTicks, yAxisPosition, isDataXAxis }) {
    const isHoriz = yAxisPosition === 'top' || yAxisPosition === 'bottom';
    const [x1, x2] = xScale.range();
    const [y1, y2] = yScale.range();
    let yLinesPath = '';
    let xLinesPath = '';
    let yMinorPath = '';
    let xMinorPath = '';
    const { yMajorTick: _yMajorTick, yMinorTick: _yMinorTick, xMajorTick: _xMajorTick, xMinorTick: _xMinorTick } = plotArea;
    const yMajorTick = { ...TICK_DEFAULT.yMajorTick, ..._yMajorTick };
    const yMinorTick = { ...TICK_DEFAULT.yMinorTick, ..._yMinorTick };
    const xMinorTick = { ...TICK_DEFAULT.xMinorTick, ..._xMinorTick };
    const xMajorTick = { ...TICK_DEFAULT.xMajorTick, ..._xMajorTick };
    const isYMinorRendered = yMinorTick?.isRendered === true || isLog;
    const isXMajorRendered = xMajorTick?.isRendered === true || (_xMajorTick?.isRendered === false && isDataXAxis);
    if (yMajorTick?.isRendered) {
        for (let i = 1; i < yTicks.length; i++) {
            let y = yScale.transform(yTicks[i]);
            // last grid line get's clipped due to plot area clippath. Slightly adjust
            // coord so that it's not clipped.
            if (i === yTicks.length - 1) {
                y += isHoriz ? -1 : 1;
            }
            yLinesPath += isHoriz ? `M${y},${x1}L${y},${x2}` : `M${x1},${y}L${x2},${y}`;
        }
    }
    if (isXMajorRendered) {
        if (xTicks) {
            for (let i = 1; i < xTicks.length; i++) {
                const x = xScale.transform(xTicks[i]);
                xLinesPath += isHoriz ? `M${y1},${x}L${y2},${x}` : `M${x},${y1}L${x},${y2}`;
            }
        }
    }
    if (isYMinorRendered) {
        for (let i = 0; i < yMinorTicks.length; i++) {
            const y = yScale.transform(yMinorTicks[i]);
            yMinorPath += isHoriz ? `M${y},${x1}L${y},${x2}` : `M${x1},${y}L${x2},${y}`;
        }
    }
    if (xMinorTick.isRendered && xMinorTicks) {
        for (let i = 0; i < xMinorTicks.length; i++) {
            const x = xScale.transform(xMinorTicks[i]);
            xMinorPath += isHoriz ? `M${y1},${x}L${y2},${x}` : `M${x},${y1}L${x},${y2}`;
        }
    }
    const colorScheme = useColorScheme();
    return (jsxs(Fragment, { children: [yMajorTick?.isRendered && (jsx("path", { d: yLinesPath, class: classNames([
                    styles.noPointerEvents,
                    styles.majorTickLineStyles,
                    yMajorTick?.lineStyle === 'dashed' ? styles.dashedLine : undefined,
                    yMajorTick?.lineStyle === 'dotted' ? styles.dottedLine : undefined
                ]), style: {
                    stroke: yMajorTick.lineColor,
                    strokeWidth: yMajorTick.lineWidth
                } })), isXMajorRendered && (jsx("path", { d: xLinesPath, class: classNames([
                    styles.noPointerEvents,
                    styles.majorTickLineStyles,
                    xMajorTick?.lineStyle === 'dashed' ? styles.dashedLine : undefined,
                    xMajorTick?.lineStyle === 'dotted' ? styles.dottedLine : undefined
                ]), style: {
                    stroke: xMajorTick.lineColor,
                    strokeWidth: xMajorTick.lineWidth
                } })), isYMinorRendered && (jsx("path", { d: yMinorPath, class: classNames([
                    styles.noPointerEvents,
                    styles.minorTickLineStyles,
                    colorScheme === 'light'
                        ? styles.lightMinorTickLineStroke
                        : styles.darkMinorTickLineStroke,
                    yMinorTick?.lineStyle === 'dashed' ? styles.dashedLine : undefined,
                    yMinorTick?.lineStyle === 'dotted' ? styles.dottedLine : undefined
                ]), style: {
                    stroke: yMinorTick?.lineColor,
                    strokeWidth: yMinorTick?.lineWidth
                } })), xMinorTick.isRendered && (jsx("path", { d: xMinorPath, class: classNames([
                    styles.noPointerEvents,
                    styles.minorTickLineStyles,
                    colorScheme === 'light'
                        ? styles.lightMinorTickLineStroke
                        : styles.darkMinorTickLineStroke,
                    xMinorTick?.lineStyle === 'dashed' ? styles.dashedLine : undefined,
                    xMinorTick?.lineStyle === 'dotted' ? styles.dottedLine : undefined
                ]), style: {
                    stroke: xMinorTick?.lineColor,
                    strokeWidth: xMinorTick?.lineWidth
                } }))] }));
}

export { Gridlines as G, PlotArea as P };
//# sourceMappingURL=Gridlines-6098cb5b.js.map
