/* @oracle/oraclejet-preact: undefined */
'use strict';

var jsxRuntime = require('preact/jsx-runtime');
var PRIVATE_Chart_themes_ChartStyles_css = require('./PRIVATE_Chart/themes/ChartStyles.css.js');
var TrackResizeContainer = require('./TrackResizeContainer-a8631f0d.js');
var UNSAFE_visErrors = require('./UNSAFE_visErrors.js');
var useTextDimensions = require('./useTextDimensions-c8b41697.js');
var useCssVars = require('./useCssVars-8e83d496.js');
var hooks = require('preact/hooks');
var ReferenceLineArea = require('./ReferenceLineArea-7bc34276.js');
var utils = require('./utils-ee4fc356.js');
var useUser = require('./useUser-1295b5cb.js');

var useId = require('./useId-6c0eeb27.js');
var Axis = require('./Axis-a3a56403.js');
var useChartViewport = require('./useChartViewport-25f7d6db.js');
var useChartNav = require('./useChartNav-c69c817e.js');
var mergeProps = require('./mergeProps-e3da7237.js');
var ScrollBar = require('./ScrollBar-76e58249.js');
var useSelectDrill = require('./useSelectDrill-0b4b47ec.js');
var useTestId = require('./useTestId-4f53d561.js');
var cssUtils = require('./cssUtils-60d6bb40.js');
var useChartContextMenu = require('./useChartContextMenu-af989b4f.js');
var useChartDnd = require('./useChartDnd-edaa3619.js');
var eventsUtils = require('./eventsUtils-b87ea91f.js');
require('./accUtils-4a359187.js');
var layoutUtils = require('./layoutUtils-af53a104.js');
var useTooltip = require('./useTooltip-34accecc.js');
require('./logger-2b636482.js');
require('./LayerHost-3cd73603.js');
var compat = require('preact/compat');


require('./hooks/UNSAFE_useTooltip/themes/redwood/TooltipContentVariants.css.js');
require('./tooltipUtils-2bc15136.js');
var useChartMarquee = require('./useChartMarquee-ede5cae4.js');
var useVisTouchResponse = require('./useVisTouchResponse-376e11d5.js');
var useOverviewContext = require('./useOverviewContext-1732a3f1.js');
var scale = require('./scale-9e43a5f6.js');
var OverviewSlidingWindow = require('./OverviewSlidingWindow-0f5f00a3.js');
var PRIVATE_VisOverview_themes_VisOverview_css = require('./PRIVATE_VisOverview/themes/VisOverview.css.js');
var useTranslationBundle = require('./useTranslationBundle-12dd087d.js');
var useChartDatatip = require('./useChartDatatip-1bceba5d.js');
var preact = require('preact');
var stringUtils = require('./stringUtils-3e19c8af.js');

/**
 * @license
 * Copyright (c) %FIRST_YEAR% %CURRENT_YEAR%, Oracle and/or its affiliates.
 * Licensed under The Universal Permissive License (UPL), Version 1.0
 * as shown at https://oss.oracle.com/licenses/upl/
 * @ignore
 */
/**
 * Returns the parent group for the navigable item.
 * @param levelsArray The levels array.
 * @param levelIndex The levelIndex of current naviable group..
 * @param groupIndex The groupIndex of current navigable group.
 * @returns
 */
function getParentGroup(levelsArray, levelIndex, groupIndex, isGroupNavigable) {
    const path = levelsArray[levelIndex][groupIndex].path;
    if (path.length === 1) {
        return {
            levelIndex,
            groupIndex
        };
    }
    let lIndex = Math.max(0, levelIndex - 1);
    const groupItem = levelsArray[levelIndex][groupIndex];
    const { start, end } = groupItem;
    while (lIndex >= 0) {
        for (let i = 0; i < levelsArray[lIndex].length; i++) {
            const { start: s, end: e } = levelsArray[lIndex][i];
            if (s <= start && end <= e) {
                if (isGroupNavigable(lIndex, i)) {
                    return { groupIndex: i, levelIndex: lIndex };
                }
            }
        }
        lIndex -= 1;
    }
    return {
        levelIndex,
        groupIndex
    };
}
/**
 * @param levelsArray The levels array.
 * @param levelIndex The levelIndex of current navigable item.
 * @param groupIndex The groupIndex of current navigable item.
 * @returns
 */
function getChildGroup(levelsArray, levelIndex, groupIndex, isGroupNavigable) {
    if (levelIndex === levelsArray.length - 1) {
        return { levelIndex, groupIndex };
    }
    const lIndex = Math.min(levelsArray.length - 1, levelIndex + 1);
    const groupItem = levelsArray[levelIndex][groupIndex];
    const { start, end } = groupItem;
    while (lIndex <= levelsArray.length - 1) {
        for (let i = 0; i < levelsArray[lIndex].length; i++) {
            const { start: s, end: e } = levelsArray[lIndex][i];
            if (start <= s && e <= end) {
                if (isGroupNavigable(lIndex, i)) {
                    return { groupIndex: i, levelIndex: lIndex };
                }
            }
        }
    }
    return {
        levelIndex,
        groupIndex
    };
}
function getNextGroup(levelsArray, info, isGroupNavigable) {
    const groupIndex = info.groupIndex + 1;
    const levelIndex = info.levelIndex;
    const maxgroup = levelsArray[levelIndex].length - 1;
    if (groupIndex > maxgroup) {
        return;
    }
    if (isGroupNavigable(levelIndex, groupIndex)) {
        return { groupIndex, levelIndex };
    }
    return getNextGroup(levelsArray, { groupIndex, levelIndex }, isGroupNavigable);
}
function getPreviousGroup(info, isGroupNavigable) {
    const groupIndex = info.groupIndex - 1;
    const levelIndex = info.levelIndex;
    if (groupIndex < 0) {
        return;
    }
    if (isGroupNavigable(levelIndex, groupIndex)) {
        return { groupIndex, levelIndex };
    }
    return getPreviousGroup({ groupIndex, levelIndex }, isGroupNavigable);
}
function getGroupNavUtil(levelsArray, drilling, isRtl, isHoriz, isGroupLabelRendered) {
    const isGroupNavigable = (levelIndex, groupIndex) => {
        const group = levelsArray[levelIndex][groupIndex].item;
        const groupName = group.name || group.id;
        const groupsDrilling = group.drilling;
        const isLabelRendered = !!isGroupLabelRendered?.(levelIndex, groupIndex);
        return (isLabelRendered &&
            groupName != null &&
            (drilling === 'on' || drilling === 'groupsOnly') &&
            groupsDrilling != 'off');
    };
    const getDefaultNavGroup = () => {
        for (let levelIndex = 0; levelIndex < levelsArray.length; levelIndex++) {
            const numGroups = levelsArray[levelIndex].length;
            for (let groupIndex = 0; groupIndex < numGroups; groupIndex++) {
                if (isGroupNavigable(levelIndex, groupIndex)) {
                    return { groupIndex, levelIndex };
                }
            }
        }
        return { groupIndex: 0, levelIndex: 0 };
    };
    const getNextNavGroup = (info, arrow) => {
        let nextGroup;
        if (arrow === 'ArrowRight') {
            if (isHoriz) {
                nextGroup = !isRtl
                    ? getChildGroup(levelsArray, info.levelIndex, info.groupIndex, isGroupNavigable)
                    : getParentGroup(levelsArray, info.levelIndex, info.groupIndex, isGroupNavigable);
            }
            else {
                nextGroup = isRtl
                    ? getPreviousGroup(info, isGroupNavigable)
                    : getNextGroup(levelsArray, info, isGroupNavigable);
            }
        }
        else if (arrow === 'ArrowLeft') {
            if (isHoriz) {
                nextGroup = isRtl
                    ? getChildGroup(levelsArray, info.levelIndex, info.groupIndex, isGroupNavigable)
                    : getParentGroup(levelsArray, info.levelIndex, info.groupIndex, isGroupNavigable);
            }
            else {
                nextGroup = isRtl
                    ? getNextGroup(levelsArray, info, isGroupNavigable)
                    : getPreviousGroup(info, isGroupNavigable);
            }
        }
        else if (arrow === 'ArrowDown') {
            nextGroup = isHoriz
                ? getNextGroup(levelsArray, info, isGroupNavigable)
                : getParentGroup(levelsArray, info.levelIndex, info.groupIndex, isGroupNavigable);
        }
        else if (arrow === 'ArrowUp') {
            nextGroup = isHoriz
                ? getPreviousGroup(info, isGroupNavigable)
                : getChildGroup(levelsArray, info.levelIndex, info.groupIndex, isGroupNavigable);
        }
        return nextGroup || info;
    };
    return { getNextNavGroup, getDefaultNavGroup };
}

/**
 * @license
 * Copyright (c) %FIRST_YEAR% %CURRENT_YEAR%, Oracle and/or its affiliates.
 * Licensed under The Universal Permissive License (UPL), Version 1.0
 * as shown at https://oss.oracle.com/licenses/upl/
 * @ignore
 */
function getRefObjectPosition(object) {
    if (object.type === 'line') {
        return object.value;
    }
    if (object.type === 'area') {
        if (object.low != null && object.high != null) {
            return (object.low + object.high) / 2;
        }
    }
    return undefined;
}
function buildNavigableRefObjects(xRefs, yRefs, y2Refs) {
    const normalize = (arr) => (arr ?? [])
        .map((obj) => ({ id: obj.id, val: getRefObjectPosition(obj) }))
        .filter((obj) => obj.id != null && obj.val != null)
        .sort((a, b) => a.val - b.val);
    const xList = normalize(xRefs);
    const yList = normalize(yRefs);
    const y2List = normalize(y2Refs);
    return [...xList, ...yList, ...y2List];
}
/**
 * Compute an anchor bounds for a reference object by id. Returns a 1x1 box positioned
 * at a reasonable anchor point for the ref so datatips can use element anchoring.
 */
function getRefObjectBounds(id, xRefs, yRefs, y2Refs, xScale, yScale, y2Scale, orientation, plotAreaSpace) {
    const ref = xRefs?.find((item) => item.id === id) ??
        yRefs?.find((item) => item.id === id) ??
        y2Refs?.find((item) => item.id === id);
    if (!ref)
        return undefined;
    const isInX = xRefs?.some((item) => item.id === id);
    const isInY2 = y2Refs?.some((item) => item.id === id);
    const isXRef = !!isInX;
    const targetScale = isXRef ? xScale : isInY2 ? y2Scale : yScale;
    const spanningScale = isXRef ? yScale : xScale;
    const asPoint = (cx, cy) => ({ x: cx, y: cy, width: 1, height: 1 });
    if (ref.type === 'line' && ref.value != null) {
        const pos = targetScale?.transform(ref.value);
        const range = spanningScale?.range?.();
        const span1 = range?.[0];
        const span2 = range?.[1];
        if (typeof pos !== 'number' || isNaN(pos) || span1 == null || span2 == null)
            return undefined;
        const mid = (span1 + span2) / 2;
        const isHorizontalLine = (orientation === 'vertical' && !isXRef) || (orientation === 'horizontal' && isXRef);
        return isHorizontalLine ? asPoint(mid, pos) : asPoint(pos, mid);
    }
    // Constant area (low/high)
    if (ref.type === 'area') {
        const domain = targetScale?.domain?.();
        const domMin = domain ? Math.min(domain[0], domain[1]) : -Infinity;
        const domMax = domain ? Math.max(domain[0], domain[1]) : Infinity;
        const clampedLow = ref.low != null ? Math.max(ref.low, domMin) : domMin;
        const clampedHigh = ref.high != null ? Math.min(ref.high, domMax) : domMax;
        const pos1 = targetScale?.transform(clampedLow);
        const pos2 = targetScale?.transform(clampedHigh);
        const range = spanningScale?.range?.();
        const span1 = range?.[0];
        const span2 = range?.[1];
        if (typeof pos1 !== 'number' ||
            typeof pos2 !== 'number' ||
            isNaN(pos1) ||
            isNaN(pos2) ||
            span1 == null ||
            span2 == null) {
            return undefined;
        }
        const midSpan = (span1 + span2) / 2;
        const midPos = (pos1 + pos2) / 2;
        const isHorizontalArea = (orientation === 'vertical' && !isXRef) || (orientation === 'horizontal' && isXRef);
        return isHorizontalArea ? asPoint(midSpan, midPos) : asPoint(midPos, midSpan);
    }
    const centerX = plotAreaSpace.x + plotAreaSpace.width / 2;
    const centerY = plotAreaSpace.y + plotAreaSpace.height / 2;
    return asPoint(centerX, centerY);
}

/**
 * @license
 * Copyright (c) %FIRST_YEAR% %CURRENT_YEAR%, Oracle and/or its affiliates.
 * Licensed under The Universal Permissive License (UPL), Version 1.0
 * as shown at https://oss.oracle.com/licenses/upl/
 * @ignore
 */
function useTextTruncation({ getTextAndBounds, width, isRtl, textAndBounds }) {
    const [text, setText] = hooks.useState();
    const bounds = hooks.useRef();
    const hoveredRef = hooks.useRef(false);
    hooks.useEffect(() => {
        if (textAndBounds.text) {
            bounds.current = textAndBounds.bounds;
            setText(textAndBounds.text);
        }
        else if (!hoveredRef.current) {
            setText(undefined);
        }
    }, [textAndBounds]);
    const { tooltipContent, tooltipProps } = useTooltip.useTooltip({
        text,
        position: 'top-start',
        offset: layoutUtils.calculateOffset(isRtl, width, bounds.current)
    });
    const onPointerMove = (event) => {
        const textAndBounds = getTextAndBounds(event.target);
        if (textAndBounds) {
            bounds.current = textAndBounds.bounds;
            setText(textAndBounds.text);
            hoveredRef.current = true;
        }
        else {
            setText(undefined);
            hoveredRef.current = false;
        }
    };
    return {
        tooltipContent,
        tooltipProps: mergeProps.mergeProps({ onPointerMove }, tooltipProps)
    };
}

/**
 * @license
 * Copyright (c) %FIRST_YEAR% %CURRENT_YEAR%, Oracle and/or its affiliates.
 * Licensed under The Universal Permissive License (UPL), Version 1.0
 * as shown at https://oss.oracle.com/licenses/upl/
 * @ignore
 */
function getWindowCoords(isRtl, xViewportExtent, xAxisExtent, yViewportExtent, yAxisExtent, plotAreaSpace) {
    const xDomain = [xAxisExtent.min, xAxisExtent.max];
    const xRange = (isRtl
        ? [plotAreaSpace.x + plotAreaSpace.width, plotAreaSpace.x]
        : [plotAreaSpace.x, plotAreaSpace.x + plotAreaSpace.width]);
    const xScale = new scale.ScaleLinear(xDomain, xRange);
    const yDomain = [yAxisExtent.min, yAxisExtent.max];
    const yRange = [plotAreaSpace.y + plotAreaSpace.height, plotAreaSpace.y];
    const yScale = new scale.ScaleLinear(yDomain, yRange);
    const windowX = xScale.transform(xViewportExtent.viewportMin);
    const windowWidth = Math.abs(xScale.transform(xViewportExtent.viewportMax) - xScale.transform(xViewportExtent.viewportMin));
    return {
        windowX: isRtl ? windowX - windowWidth : windowX,
        windowWidth: windowWidth,
        windowY: yScale.transform(yViewportExtent.viewportMax),
        windowHeight: Math.abs(yScale.transform(yViewportExtent.viewportMax) - yScale.transform(yViewportExtent.viewportMin)),
        xScale,
        yScale
    };
}

function OverviewBackground({ x, width, height, y, windowX, windowHeight, windowWidth, windowY }) {
    return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx("rect", { x: x, y: y, width: Math.max(0, windowX - x), height: height, class: PRIVATE_VisOverview_themes_VisOverview_css.styles.overviewBackground }), jsxRuntime.jsx("rect", { x: windowX + windowWidth, width: Math.max(0, x + width - windowX - windowWidth), y: y, height: height, class: PRIVATE_VisOverview_themes_VisOverview_css.styles.overviewBackground }), jsxRuntime.jsx("rect", { x: windowX, y: y, height: Math.max(0, windowY - y), width: windowWidth, class: PRIVATE_VisOverview_themes_VisOverview_css.styles.overviewBackground }), jsxRuntime.jsx("rect", { x: windowX, y: windowY + windowHeight, width: windowWidth, class: PRIVATE_VisOverview_themes_VisOverview_css.styles.overviewBackground, height: Math.max(y + height - windowY - windowHeight, 0) })] }));
}

function getRenderer(xAxisExtent, isRtl, overviewXScale, plotAreaSpace, windowCoords, hasHandles, onViewportChange) {
    return {
        slidingWindow: (jsxRuntime.jsx(OverviewSlidingWindow.OverviewSlidingWindow, { ...plotAreaSpace, ...windowCoords, hasHandles: hasHandles, onWindowDimsChange: (props) => {
                utils.updateViewportFromOverview(xAxisExtent, isRtl, windowCoords.windowX, windowCoords.windowWidth, props.deltaX, props.deltaWidth, overviewXScale, onViewportChange);
            } })),
        background: jsxRuntime.jsx(OverviewBackground, { ...plotAreaSpace, ...windowCoords })
    };
}

// Main renderer component
function ReferenceObjects({ location, xAxis, yAxis, y2Axis, xScale, yScale, y2Scale, orientation, xAxisInfo, groups, activeId, activeInfo }) {
    const filterFunc = (item) => location === 'front' ? item.location === 'front' : item.location !== 'front';
    return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [xAxis?.referenceObjects
                ?.filter(filterFunc)
                .map((item, index) => (preact.createElement(ReferenceLineArea.ReferenceLineArea, { ...item, key: item.id, xScale: xScale, yScale: yScale, orientation: orientation, groups: groups, xStartIndex: xAxisInfo.startIndex, xEndIndex: xAxisInfo.endIndex, seriesIndex: index, isXRef: true, activeId: item.id === activeInfo?.refObjId ? activeId : undefined }))), yAxis?.referenceObjects
                ?.filter(filterFunc)
                .map((item, index) => (jsxRuntime.jsx(ReferenceLineArea.ReferenceLineArea, { ...item, xScale: xScale, yScale: yScale, orientation: orientation, groups: groups, xStartIndex: xAxisInfo.startIndex, xEndIndex: xAxisInfo.endIndex, seriesIndex: index, activeId: item.id === activeInfo?.refObjId ? activeId : undefined }))), y2Axis?.referenceObjects
                ?.filter(filterFunc)
                .map((item, index) => (jsxRuntime.jsx(ReferenceLineArea.ReferenceLineArea, { ...item, xScale: xScale, yScale: y2Scale, orientation: orientation, groups: groups, xStartIndex: xAxisInfo.startIndex, xEndIndex: xAxisInfo.endIndex, seriesIndex: index, activeId: item.id === activeInfo?.refObjId ? activeId : undefined })))] }));
}

const OVERVIEW_GAP = 10;
const chartVars = cssUtils.getChartVars();
const ChartWithDimensions = compat.forwardRef(({ width, height, selectedIds, hiddenIds, hideAndShowBehavior = 'none', orientation = 'vertical', xAxis, yAxis, y2Axis, plotArea, dragMode = 'user', series, groups, isStacked = false, stackLabelStyle, getStackGroup, getDataItem, selectionMode = 'none', drilling = 'off', dataCursorPosition, onSelectionChange, isDataCursorEnabled, dataCursorStyle, onViewportChange, onDataCursorPositionChange, onItemDrill, onGroupDrill, onItemHover, onItemFocus, datatip, zoomAndScroll = 'off', getNavUtil, getDataItemPos, getGapRatio, valueFormats, findNearest, getMarkerInfo, isRtl, children, testId, renderGridLinesInFront, isDataXAxis, contextMenuConfig, overview = 'off', getStartAndEndAxesOffset, defaultOverviewContentRenderer, isOverview, yAxisSize, overviewRenderer, initialZooming = 'none', ...props }, ref = null) => {
    const timeAxisType = xAxis?.timeAxisType;
    const isTimeAxis = timeAxisType != null;
    if (utils.hasInvalidData(timeAxisType, series, groups, getDataItem)) {
        throw new UNSAFE_visErrors.VisInvalidDataError('Chart received invalid data');
    }
    const testIdProps = useTestId.useTestId(testId);
    const rootRef = hooks.useRef(null);
    const isTestEnv = testIdProps['data-testid'] !== undefined;
    const isHoriz = orientation === 'horizontal';
    const { xAxisPosition, yAxisPosition, y2AxisPosition } = utils.getAxesPosition(yAxis, y2Axis, isHoriz, isRtl);
    const { resolvedVars, cssContent } = useCssVars.useCssVars(chartVars);
    const resolvedColors = Array.from(Array(12)).map((_, index) => {
        return resolvedVars[`color${index + 1}`];
    });
    const { textMeasureContent, getTextDimensions } = useTextDimensions.useTextDimensions();
    let availSpace = utils.getAvailSpace(width, height);
    if (isOverview && yAxisSize) {
        const w = availSpace.width - yAxisSize;
        const gaps = utils.getOuterGaps(w, height);
        availSpace.width -= yAxisSize - 2 * gaps.width;
        availSpace.x += yAxisSize - gaps.width;
    }
    const updatedSpace = utils.getScrollBarSpace(isTimeAxis, availSpace, zoomAndScroll, xAxisPosition, overview);
    let scrollDims = updatedSpace.scrollDims;
    availSpace = updatedSpace.availSpace;
    const { locale } = useUser.useUser();
    const { x, y, width: _width, height: _height } = availSpace;
    const labelFontSize = resolvedVars['labelFontSize'];
    const split = y2Axis?.split ?? 'off';
    const isSplitDualY = split !== 'off';
    const splitterPosition = split !== 'off' ? split : 0.5;
    const layoutInfo = hooks.useMemo(() => {
        const hiddenSet = new Set(hiddenIds);
        return utils.getLayoutInfo(series, groups, getDataItem, xAxis, yAxis, y2Axis, { x, y, width: _width, height: _height }, // availSpace
        hiddenSet, hideAndShowBehavior, isHoriz, isRtl, isStacked, labelFontSize, getStartAndEndAxesOffset, locale, isSplitDualY, splitterPosition, getStackGroup, getTextDimensions, isTestEnv, isDataXAxis, initialZooming, zoomAndScroll);
    }, [
        x,
        y,
        _width,
        _height,
        getDataItem,
        getTextDimensions,
        groups,
        hiddenIds,
        hideAndShowBehavior,
        isDataXAxis,
        isHoriz,
        isRtl,
        isStacked,
        isTestEnv,
        locale,
        getStartAndEndAxesOffset,
        labelFontSize,
        series,
        xAxis,
        yAxis,
        y2Axis,
        splitterPosition,
        isSplitDualY,
        getStackGroup,
        initialZooming,
        zoomAndScroll
    ]);
    const { getGroupFromPath, levelsArray, xAxisInfo, xProps, xScale, yProps, y2Props, yScale, y2Scale, yMaxDim, yAxisInfo, plotAreaSpace, xSpace, ySpace, y2Space, idToDataMap, y2AxisInfo, getYPreferredSize, getY2PreferredSize, getXPreferredSize } = layoutInfo;
    hooks.useImperativeHandle(ref, () => ({
        _getYaxis: () => {
            return { getPreferredSize: getYPreferredSize, bounds: ySpace };
        },
        _getY2axis: () => {
            return { getPreferredSize: getY2PreferredSize, bounds: y2Space };
        },
        _getXaxis: () => {
            return { getPreferredSize: getXPreferredSize, bounds: xSpace };
        }
    }));
    const leafGroupsInfo = levelsArray.length > 0 ? levelsArray[levelsArray.length - 1] : [];
    scrollDims = utils.updateScrollBarSpace(scrollDims, xAxisPosition === 'bottom', isRtl, yMaxDim);
    const gapRatio = getGapRatio(xAxisInfo.startIndex, xAxisInfo.endIndex);
    const getNextChartItem = getNavUtil(xAxisInfo.startIndex, xAxisInfo.endIndex);
    const { getNextNavGroup, getDefaultNavGroup } = getGroupNavUtil(levelsArray, drilling, isRtl, isHoriz, xProps.isGroupLabelRendered);
    const navigableRefObjects = hooks.useMemo(() => buildNavigableRefObjects(xAxis?.referenceObjects, yAxis?.referenceObjects, y2Axis?.referenceObjects), [xAxis?.referenceObjects, yAxis?.referenceObjects, y2Axis?.referenceObjects]);
    const getNextRefObject = (info, arrow) => {
        const list = navigableRefObjects;
        if (!list || list.length === 0) {
            return {};
        }
        const dir = arrow === 'ArrowLeft' || arrow === 'ArrowUp' ? -1 : 1;
        const idx = info.refObjId != null
            ? list.findIndex((o) => o.id === info.refObjId)
            : dir > 0
                ? -1
                : list.length;
        // Move one step in the desired direction. Clamp at the ends.
        let nextIdx = idx + dir;
        if (nextIdx < 0)
            nextIdx = 0;
        if (nextIdx >= list.length)
            nextIdx = list.length - 1;
        return { refObjId: list[nextIdx].id };
    };
    const { ignoreSelectPointerUp, cursor, yAxisCursor, marqueeProps, marqueeContent, toggleButtonContent, isPointInsideMarquee, dragMode: mode } = useChartMarquee.useChartMarquee({
        rootRef,
        plotAreaSpace,
        xSpace,
        ySpace,
        dragMode,
        chartWidth: width,
        isMultiSelection: selectionMode === 'multiple',
        onViewportChange,
        isZoomScroll: zoomAndScroll === 'live',
        xScale,
        selectedIds,
        getDataById: (id) => idToDataMap.get(id),
        onSelectionChange,
        isRtl,
        xAxisInfo
    });
    const { touchResponse, touchResponseStyle } = useVisTouchResponse.useVisTouchResponse({
        type: 'auto',
        supportsTouchDragGestures: mode !== 'off',
        rootRef
    });
    const { activeId, focusedItemInfo, hoveredItemInfo, focusedGroupInfo, navProps, onFocusUpdate } = useChartNav.useChartNav({
        rootRef,
        getNextChartItem,
        getNextRefObject,
        getNextNavGroup,
        getDefaultNavGroup,
        touchResponse,
        onItemHover,
        onItemFocus,
        drilling,
        xAxisInfo
    });
    const onContextMenuDismissed = (gesture) => {
        if (gesture === 'keyboard') {
            onFocusUpdate();
        }
    };
    const translations = useTranslationBundle.useTranslationBundle('@oracle/oraclejet-preact');
    const getTextAndBounds = (target) => {
        return useChartDatatip.getTextAndBoundsUtil(target, rootRef, xAxis?.title, yAxis?.title, y2Axis?.title, xProps.titleProps?.dims, yProps.titleProps?.dims, y2Props.titleProps?.dims, xProps.tickLabels, focusedGroupInfo);
    };
    const dimsAndTextInfo = useChartDatatip.getTextAndDimsInfo(xProps.tickLabels, focusedGroupInfo.groupIndex, focusedGroupInfo.levelIndex);
    const { tooltipContent, tooltipProps } = useTextTruncation({
        getTextAndBounds,
        width,
        isRtl,
        textAndBounds: {
            bounds: dimsAndTextInfo?.dims,
            text: dimsAndTextInfo?.text
        }
    });
    const viewportProps = useChartViewport.useChartViewport({
        rootRef,
        width,
        height,
        xAxisInfo,
        yAxisInfo,
        y2AxisInfo,
        xScale,
        yScale,
        y2Scale,
        plotAreaSpace,
        isRtl,
        isHoriz,
        zoomAndScroll,
        onViewportChange
    });
    const ignoreAsTrigger = (target) => {
        if (!target) {
            return false;
        }
        const dataset = eventsUtils.getElementData(rootRef, target);
        if ((dataset &&
            (dataset['ojPrivateObject'] === 'marquee' ||
                dataset['ojPrivateObject'] === 'dragModeControls' ||
                dataset['ojPrivateObject'] === 'scrollBar')) ||
            ignoreSelectPointerUp) {
            return true;
        }
        return false;
    };
    const { selectDrillProps, selectionContent } = useSelectDrill.useSelectDrill({
        selectionMode,
        selection: [...selectedIds],
        onChange: onSelectionChange,
        rootRef,
        drilling,
        onItemDrill,
        onGroupDrill,
        focusedGroupInfo,
        focusedItemInfo,
        levelsArray,
        getDataItem,
        getDataById: (id) => idToDataMap.get(id),
        ignoreAsTrigger
    });
    const findNearestData = findNearest(xScale, yScale, y2Scale, xProps.axisStepWidth, xProps.averageGroupZ, gapRatio);
    const getDataItemPosition = getDataItemPos(xScale, yScale, y2Scale, xProps.axisStepWidth, xProps.averageGroupZ, gapRatio);
    const [datatipDisabled, setDatatipDisabled] = hooks.useState(false);
    const getItemAriaLabel = useChartDatatip.getAriaLabelGenerator(series, translations, valueFormats, leafGroupsInfo, xAxis, !!isDataXAxis, getGroupFromPath, xProps.defaultLabelFormatter, yProps.defaultLabelFormatter, y2Props.defaultLabelFormatter);
    const getRefItem = (id) => {
        return (xAxis?.referenceObjects?.find((item) => item.id === id) ??
            yAxis?.referenceObjects?.find((item) => item.id === id) ??
            y2Axis?.referenceObjects?.find((item) => item.id === id));
    };
    const getRefObjectBounds$1 = (id) => {
        return getRefObjectBounds(id, xAxis?.referenceObjects, yAxis?.referenceObjects, y2Axis?.referenceObjects, xScale, yScale, y2Scale, orientation, plotAreaSpace);
    };
    const getRefAxis = (id) => {
        if (xAxis?.referenceObjects?.some((item) => item.id === id))
            return 'x';
        if (yAxis?.referenceObjects?.some((item) => item.id === id))
            return 'y';
        if (y2Axis?.referenceObjects?.some((item) => item.id === id))
            return 'y2';
        return undefined;
    };
    const { datatipContent, dataCursorContent, datatipProps: { 'aria-describedby': datatipAriaDescribedby, ...datatipProps } } = useSelectDrill.useChartDatatipAndCursor({
        series,
        leafGroupsInfo,
        width,
        height,
        findNearest: findNearestData,
        plotAreaSpace,
        onDataCursorPositionChange,
        isDataCursorEnabled,
        dataCursorPosition,
        dataCursorStyle,
        hoveredItemInfo,
        focusedItemInfo,
        getDataItem,
        getRefItem,
        getRefObjectBounds: getRefObjectBounds$1,
        getRefAxis,
        getMarkerInfo,
        getDataItemPos: getDataItemPosition,
        datatip,
        valueFormats,
        isHoriz,
        touchResponse,
        isDisabled: datatipDisabled,
        xScale: xScale,
        yScale,
        y2Scale,
        timeAxisType,
        defaultXFormatter: xProps.defaultLabelFormatter,
        defaultYFormatter: yProps.defaultLabelFormatter,
        defaultY2Formatter: y2Props.defaultLabelFormatter,
        hasXYValues: isDataXAxis,
        getGroupFromPath,
        translations
    });
    const isGroupInteractive = (index) => {
        if (isTimeAxis) {
            return false;
        }
        const groupDrill = groups[index]?.drilling;
        if (groupDrill === 'on') {
            return true;
        }
        if (groupDrill != 'off' && (drilling === 'on' || drilling === 'groupsOnly')) {
            return true;
        }
        return false;
    };
    const plotAreaClipPathId = useId.useId();
    //  const { yTicks, y2Ticks } = getYY2Ticks(yAxisInfo.ticks, y2AxisInfo.ticks, isHoriz, isSplitDualY);
    const gridLines = (jsxRuntime.jsx(ReferenceLineArea.Gridlines, { plotArea: plotArea, availSpace: plotAreaSpace, xAxisPosition: xAxisPosition, isRtl: isRtl, yMinorTicks: yAxisInfo.minorTicks, xMinorTicks: xAxisInfo.minorTicks, xScale: xScale, yScale: yScale, y2Scale: y2Scale, isLog: yAxis?.scale === 'log', yAxisPosition: yAxisPosition, isDataXAxis: isDataXAxis, xAxis: xAxis, yAxis: yAxis, y2Axis: y2Axis, hasAxisLine: !isOverview, y2MinorTicks: y2AxisInfo?.minorTicks, y2Ticks: y2AxisInfo.ticks, yTicks: yAxisInfo.ticks, xTicks: xAxisInfo.ticks, isSplitDualY: isSplitDualY }));
    const { contextMenuContent, contextMenuProps } = useChartContextMenu.useChartContextMenu({
        isRtl,
        width,
        height,
        getDataItemPosition,
        series,
        levelsArray,
        focusedGroupInfo,
        getDataItem,
        focusedItemInfo,
        rootRef,
        xAxisTitle: xAxis?.title,
        yAxisTitle: yAxis?.title,
        contextMenuConfig: utils.hasData(series, groups) ? contextMenuConfig : undefined,
        onContextMenuDismissed
    });
    const [dragOver, setDragOver] = hooks.useState({
        accepted: undefined,
        type: ''
    });
    const { draggable, dndProps, dndContent } = useChartDnd.useChartDnd({
        onDrag: props.onDrag,
        onDragStart: props.onDragStart,
        onDragEnd: props.onDragEnd,
        onDragEnter: props.onDragEnter,
        onDragLeave: props.onDragLeave,
        onDragOver: props.onDragOver,
        onDrop: props.onDrop,
        itemsDraggable: props.itemsDraggable,
        groupDraggable: props.groupDraggable,
        rootRef,
        levelsArray,
        series,
        selectedIds,
        getDataItem,
        xSpace,
        ySpace,
        plotAreaSpace,
        setDragOver,
        setDatatipDisabled,
        onSelectionChange
    });
    const eventsProps = mergeProps.mergeProps(navProps, selectDrillProps, viewportProps, datatipProps, marqueeProps, tooltipProps, contextMenuProps, dndProps);
    const overviewContentRenderer = overview != 'off' && (overview === 'on' || !overview.renderer)
        ? defaultOverviewContentRenderer
        : undefined;
    const { background, slidingWindow } = overviewRenderer(plotAreaSpace);
    const isActiveInfoRef = focusedItemInfo.refObjId != null && focusedItemInfo.isFocusVisible;
    const activeInfo = utils.getActiveInfo(focusedItemInfo, hoveredItemInfo);
    return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [getTextDimensions && resolvedVars['labelFontSize'] != undefined && (jsxRuntime.jsxs("div", { tabIndex: isOverview ? undefined : 0, draggable: draggable, ref: rootRef, "aria-activedescendant": activeId, "aria-label": props['aria-label'], "aria-labelledby": props['aria-labelledby'], "aria-describedby": stringUtils.l([props['aria-describedby'], datatipAriaDescribedby]), style: { ...touchResponseStyle }, role: isOverview ? undefined : 'application', className: PRIVATE_Chart_themes_ChartStyles_css.styles.baseChartStyle, "data-oj-private-selection-mode": isTestEnv ? selectionMode : undefined, ...testIdProps, ...(isOverview ? {} : eventsProps), children: [jsxRuntime.jsxs("svg", { width: "100%", height: scrollDims.height != 0 && overview != 'off'
                            ? `${Math.ceil((updatedSpace.availSpace.height + OVERVIEW_GAP) * 100) / height}%`
                            : '100%', children: [jsxRuntime.jsx("clipPath", { id: `${plotAreaClipPathId}`, children: jsxRuntime.jsx("rect", { ...plotAreaSpace }) }), background, jsxRuntime.jsx(ReferenceLineArea.PlotArea, { color: plotArea?.color, dragOverStyle: dragOver.type !== 'plotArea' ? 'none' : dragOver.accepted ? 'accept' : 'reject', cursor: cursor, availSpace: plotAreaSpace }), !renderGridLinesInFront && gridLines, jsxRuntime.jsx(Axis.Axis, { ...yProps, axisPosition: yAxisPosition, isRtl: isRtl, cursor: yAxisCursor, availSpace: ySpace, dragOverStyle: dragOver.type !== 'yAxis' ? 'none' : dragOver.accepted ? 'accept' : 'reject' }), jsxRuntime.jsx(Axis.Axis, { ...y2Props, axisPosition: y2AxisPosition, isRtl: isRtl, cursor: yAxisCursor, availSpace: y2Space, dragOverStyle: dragOver.type !== 'y2Axis' ? 'none' : dragOver.accepted ? 'accept' : 'reject' }), jsxRuntime.jsx(Axis.Axis, { ...xProps, isRtl: isRtl, axisPosition: xAxisPosition, isTextInteractive: isGroupInteractive, activeId: activeId, cursor: cursor, focusedGroupIndex: focusedGroupInfo.isFocusVisible ? focusedGroupInfo.groupIndex : undefined, focusedGroupLevelIndex: focusedGroupInfo.isFocusVisible ? focusedGroupInfo.levelIndex : undefined, availSpace: xSpace, dragOverStyle: dragOver.type !== 'xAxis' ? 'none' : dragOver.accepted ? 'accept' : 'reject', separatorColor: xAxis?.groupSeparators?.color }), jsxRuntime.jsxs("g", { "clip-path": `url(#${plotAreaClipPathId})`, children: [jsxRuntime.jsx(ReferenceObjects, { location: "back", activeId: isActiveInfoRef ? activeId : undefined, activeInfo: activeInfo, xAxis: xAxis, yAxis: yAxis, y2Axis: y2Axis, xScale: xScale, yScale: yScale, y2Scale: y2Scale, orientation: orientation, xAxisInfo: xAxisInfo, groups: groups }), children({
                                        xStartIndex: xAxisInfo.startIndex,
                                        xEndIndex: xAxisInfo.endIndex,
                                        getItemAriaLabel,
                                        groupsInfo: leafGroupsInfo,
                                        resolvedColors,
                                        xScale: xScale,
                                        yScale,
                                        y2Scale,
                                        isPointInsideMarquee,
                                        defaultFontSize: resolvedVars['labelFontSize'],
                                        gapRatio,
                                        activeId,
                                        focusedItemInfo,
                                        hoveredItemInfo,
                                        getTextDimensions,
                                        axisStepWidth: xProps.axisStepWidth,
                                        averageGroupZ: xProps.averageGroupZ,
                                        plotAreaClipPathId
                                    }), renderGridLinesInFront && gridLines, jsxRuntime.jsx(ReferenceObjects, { location: "front", xAxis: xAxis, yAxis: yAxis, y2Axis: y2Axis, activeId: activeId, activeInfo: activeInfo, xScale: xScale, yScale: yScale, y2Scale: y2Scale, orientation: orientation, xAxisInfo: xAxisInfo, groups: groups }), dataCursorContent] }), slidingWindow, zoomAndScroll === 'live' && !isOverview && (jsxRuntime.jsx(ScrollBar.ScrollBar, { availSpace: scrollDims, isRtl: isRtl, viewport: xAxisInfo, axisExtent: xAxisInfo, isHoriz: xAxisPosition === 'bottom' })), marqueeContent] }), jsxRuntime.jsx(useOverviewContext.OverviewContext.Provider, { value: {
                            yAxisSize: ySpace.width,
                            isOverview: true,
                            width,
                            height: scrollDims.height,
                            overviewRenderer: (overviewChartPlotArea) => {
                                const { xScale: overviewXScale, ...windowCoords } = getWindowCoords(isRtl, xAxisInfo, xAxisInfo, yAxisInfo, yAxisInfo, overviewChartPlotArea);
                                return getRenderer(xAxisInfo, isRtl, overviewXScale, overviewChartPlotArea, windowCoords, true, onViewportChange);
                            }
                        }, children: !isOverview && overview !== 'off' && overviewContentRenderer && (jsxRuntime.jsx("div", { style: { width, height: scrollDims.height }, children: overviewContentRenderer() })) }), toggleButtonContent, datatipContent, tooltipContent, contextMenuContent, selectionContent, dndContent] })), textMeasureContent, cssContent] }));
});

const Chart = compat.forwardRef(({ width, height, ...props }, ref = null) => {
    // TODO: reevaluate how we handle empty data
    const { isOverview, overviewRenderer, yAxisSize, width: overviewWidth, height: overviewHeight } = useOverviewContext.useOverviewContext();
    let chartWidth = width;
    let chartHeight = height;
    if (chartWidth === undefined && isOverview && overviewWidth !== undefined) {
        chartWidth = `${overviewWidth}px`;
    }
    if (chartHeight === undefined && isOverview && overviewHeight !== undefined) {
        chartHeight = `${overviewHeight}px`;
    }
    return (jsxRuntime.jsx(TrackResizeContainer.TrackResizeContainer, { width: chartWidth, height: chartHeight, class: PRIVATE_Chart_themes_ChartStyles_css.dimensionStyle, children: (width, height) => width || height ? (jsxRuntime.jsx(ChartWithDimensions, { ref: ref, width: width, height: height, ...props, yAxisSize: yAxisSize, isOverview: isOverview, overviewRenderer: overviewRenderer })) : undefined }));
});

exports.Chart = Chart;
//# sourceMappingURL=Chart-966da017.js.map
