/* @oracle/oraclejet-preact: undefined */
import { jsx, Fragment, jsxs } from 'preact/jsx-runtime';
import { h as findNearestDataPoint } from './layoutUtils-5d62f2b4.js';
import { A as AreaSeries, g as getLineAreaChartItemPosition } from './chartUtils-088f15d9.js';
import { a as getSeriesData, b as getLineAreaSegments, g as getMarkers } from './useChartDnd-fc7ba21c.js';
import { L as LineSeries, M as MarkersWithLabel } from './LineSeries-fc167ea2.js';
import { f as getLineAreaChartNavUtil, d as getItemColor, h as getMarkerType } from './dataStyleUtils-1e980302.js';
import { u as useUser } from './useUser-1cd223a9.js';
import { g as getColorRamp } from './colorUtils-35e3dd2b.js';
import './accUtils-ce2d6588.js';
import { colorSchemeVars } from './Common/themes/themeContract.css.js';
import { B as BarGroup, g as getBarGapRatio, a as getBarPosition } from './BarGroup-dbf70e2c.js';
import { C as Chart } from './Chart-4ec13697.js';

function OverviewComboChart(props) {
    return (jsx(ComboChart, { datatip: () => ({ content: '' }), zoomAndScroll: "off", plotArea: {
            yMajorTick: {
                isRendered: false
            },
            xMajorTick: {}
        }, xAxis: {
            tickLabel: {
                autoRotate: false,
                // @ts-ignore
                isRendered: props.xAxis?.timeAxisType ? true : false
            }
        }, series: props.series, groups: props.groups, getDataItem: props.getDataItem, yAxis: {
            tickLabel: {
                isRendered: false
            }
        }, overview: "off" }));
}

const BAR_AXIS_OFFSET = 0.5;
const AXIS_OFFSET = 0.2;
const LINE_WITH_AREA_OPACITY = 0.2;
/**
 * The ComboChart displays information graphically using bars, lines and filled areas, making relationships among the data easier to understand.
 */
function ComboChart({ width, height, selectedIds = [], hiddenIds = [], highlightedIds, hideAndShowBehavior = 'none', orientation = 'vertical', yAxis, series, groups, isStacked = false, getDataItem, selectionMode = 'none', drilling = 'off', dataItemGaps = 0.5, dataLabelEffect = 'outline', ...props }) {
    const { direction, forcedColors } = useUser();
    const isHighContrast = forcedColors === 'active';
    const filteredBarSeries = series.filter((currentSeries) => currentSeries.type === 'bar');
    const isRtl = direction === 'rtl';
    const isLog = yAxis?.scale === 'log';
    const timeAxisType = props.xAxis?.timeAxisType;
    const hiddenSet = new Set(hiddenIds);
    const selectedSet = new Set(selectedIds);
    const highlightedSet = new Set(highlightedIds);
    const isHoriz = orientation === 'horizontal';
    const colors = getColorRamp();
    // TODO: JET-71332 ; should only be (number | undefined)[][]
    // remove the type inference from scatter chart item.
    const renderedSeries = getSeriesData(series.length, groups.length, getDataItem, hiddenSet, isLog);
    const hasArea = renderedSeries.some((_, index) => series[index].type === 'area' || series[index].type === 'lineWithArea');
    const hasBar = renderedSeries.some((_, index) => series[index].type === 'bar');
    const renderedGetDataItem = (seriesIndex, groupIndex) => {
        if (!isStacked)
            return getDataItem(seriesIndex, groupIndex);
        return {
            ...getDataItem(seriesIndex, groupIndex),
            value: renderedSeries[seriesIndex][groupIndex]
        };
    };
    const getGapRatio = () => {
        return 1;
    };
    const getNextChartItemFunc = (startIndex, endIndex) => {
        // TODO: JET-71332
        //@ts-ignore
        return getLineAreaChartNavUtil(getDataItem, series.length, startIndex, endIndex, isStacked, isRtl, isHoriz);
    };
    const getDataItemPos = (xScale, yScale, groupWidth, gapRatio) => {
        const _getBarPosition = hasBar
            ? getBarPosition(filteredBarSeries, groups, getDataItem, xScale, yScale, hiddenSet, dataItemGaps, groupWidth, gapRatio, yAxis?.scale === 'log', isStacked, isRtl, isHoriz, timeAxisType)
            : undefined;
        return (seriesIndex, groupIndex) => {
            const seriesItem = series[seriesIndex];
            if (seriesItem.type === 'bar') {
                return _getBarPosition ? _getBarPosition(seriesIndex, groupIndex) : undefined;
            }
            else {
                return getLineAreaChartItemPosition(seriesIndex, groupIndex, renderedSeries, getDataItem, groups, isHoriz, xScale, yScale, timeAxisType);
            }
        };
    };
    const getMarkerColorAndType = (seriesIndex, groupIndex) => {
        const color = getItemColor(seriesIndex, groupIndex, series, getDataItem);
        const markerType = getMarkerType(seriesIndex, groupIndex, getDataItem);
        return { color, markerType };
    };
    const findNearest = (xScale, yScale) => {
        const getSeriesDataInfo = () => {
            return {
                offset: 0,
                dataWidth: 0
            };
        };
        const getYCoord = (value, yScale) => {
            return yScale.transform(value);
        };
        return findNearestDataPoint(series, groups, xScale, yScale, renderedGetDataItem, isStacked, getSeriesDataInfo, getYCoord, isLog, 0, hiddenSet, timeAxisType);
    };
    const markers = getMarkers();
    const allLineSegmentCoords = [];
    return (jsx(Chart, { width: width, height: height, selectedIds: selectedSet, hiddenIds: hiddenIds, hideAndShowBehavior: hideAndShowBehavior, orientation: orientation, yAxis: yAxis, series: series, defaultOverviewContentRenderer: () => {
            return jsx(OverviewComboChart, { groups: groups, series: series, getDataItem: getDataItem });
        }, groups: groups, selectionMode: selectionMode, drilling: drilling, isStacked: isStacked, getDataItem: getDataItem, findNearest: findNearest, getDataItemPos: getDataItemPos, getMarkerInfo: getMarkerColorAndType, renderGridLinesInFront: hasArea, getNavUtil: getNextChartItemFunc, getGapRatio: getGapRatio, offset: hasBar ? BAR_AXIS_OFFSET : AXIS_OFFSET, isRtl: isRtl, ...props, children: ({ xStartIndex, xEndIndex, xScale, yScale, activeId, focusedItemInfo, hoveredItemInfo, isPointInsideMarquee, getTextDimensions, defaultFontSize, groupWidth }) => {
            let barSeriesIndex = -1;
            return (jsx(Fragment, { children: renderedSeries.map((valueSeries, index) => {
                    const currentSeries = series[index];
                    const areaOpacity = currentSeries.type === 'lineWithArea' ? LINE_WITH_AREA_OPACITY : 1;
                    const isAreaRendered = currentSeries.type === 'area' || currentSeries.type === 'lineWithArea';
                    const isContrastLineNeeded = currentSeries.type === 'area';
                    if (valueSeries.length === 0) {
                        return;
                    }
                    const lineSegmentCoords = getLineAreaSegments(yScale, xScale, valueSeries, xStartIndex, xEndIndex, isHoriz, isLog, groups, index, renderedGetDataItem, timeAxisType);
                    allLineSegmentCoords[index] = lineSegmentCoords[0];
                    const isBottomSegmentCurved = currentSeries.type !== 'bar'
                        ? currentSeries.lineType === 'curved' &&
                            isStacked &&
                            renderedSeries.length > 1 &&
                            index > 0
                        : isStacked && renderedSeries.length > 1 && index > 0;
                    const isHighlighted = highlightedIds === undefined ||
                        highlightedSet.size === 0 ||
                        highlightedSet.has(currentSeries.id);
                    const prevCoords = isStacked && index != 0
                        ? allLineSegmentCoords.reduce((prevValue, newValue, j) => {
                            // find the index i such that i < index, and series i  has at least
                            // one or more data item unhidden. Only such series will can be
                            // used as bottomCoord for current series. Otherwise we have to use
                            // baseline coord
                            if (j >= index) {
                                return prevValue;
                            }
                            if (newValue.length > 0) {
                                return j;
                            }
                            return prevValue;
                        }, 0)
                        : undefined;
                    if (currentSeries.type === 'bar')
                        barSeriesIndex = barSeriesIndex + 1;
                    return (jsxs(Fragment, { children: [currentSeries.type === 'bar' &&
                                groups.slice(xStartIndex, xEndIndex + 1).map((_, index) => {
                                    const barGroup = (jsx(BarGroup, { yScale: yScale, xScale: xScale, groupIndex: index + xStartIndex, selectedIds: selectedSet, hiddenIds: hiddenSet, highlightedIds: highlightedIds ? highlightedSet : highlightedIds, isDrillEnabled: drilling === 'on', series: filteredBarSeries, barGapRatio: getBarGapRatio(isStacked, xStartIndex, xEndIndex), dataItemGaps: dataItemGaps, isPointInsideMarquee: isPointInsideMarquee, isStacked: isStacked, groupWidth: groupWidth, group: groups[index], timeAxisType: props.xAxis?.timeAxisType, colors: colors, activeId: activeId, isLog: yAxis?.scale === 'log', orientation: orientation, getDataItem: getDataItem, isSelectionEnabled: selectionMode != 'none', isRtl: isRtl, focusedItemInfo: focusedItemInfo, hoveredItemInfo: hoveredItemInfo, getTextDimensions: getTextDimensions, defaultFontSize: defaultFontSize, seriesIndex: barSeriesIndex }));
                                    return barGroup;
                                }), isAreaRendered && (jsx(AreaSeries, { yScale: yScale, lineType: currentSeries.lineType, color: currentSeries.areaColor || colors[index % colors.length], isHorizontal: isHoriz, areaColorOpacity: areaOpacity, isBottomSegmentCurved: isBottomSegmentCurved, bottomCoords: prevCoords !== undefined &&
                                    allLineSegmentCoords[prevCoords].some((value) => value != null)
                                    ? allLineSegmentCoords[prevCoords]
                                    : undefined, lineSegments: lineSegmentCoords, isLog: isLog, isHighlighted: isHighlighted, seriesIndex: index })), currentSeries.type === 'line' && (jsx(LineSeries, { lineType: currentSeries.lineType, lineColor: isContrastLineNeeded
                                    ? colorSchemeVars.dvt.contrastLine
                                    : currentSeries.lineColor, lineWidth: isContrastLineNeeded ? 1.25 : currentSeries.lineWidth, lineStyle: currentSeries.lineStyle || 'solid', color: currentSeries.lineColor || colors[index % colors.length], lineSegmentCoords: lineSegmentCoords, isHorizontal: isHoriz, isHighlighted: isHighlighted, seriesIndex: index })), 
                            /*for non stacked charts, markers should render in the order of series.
                             some markers might get hidden behind area but this preserves the legacy behavior. */
                            !isStacked && (currentSeries.type === 'line' || isAreaRendered) && (jsx(MarkersWithLabel, { yScale: yScale, xScale: xScale, groups: groups, series: currentSeries, timeAxisType: timeAxisType, color: colors[index % colors.length] /* TODO : make this use getItemColor function from dataStyleUtils. */, seriesIndex: index, startIndex: xStartIndex, endIndex: xEndIndex, markerType: markers[index % markers.length], orientation: orientation, isLog: isLog, activeId: activeId, getDataItem: getDataItem, isPointInsideMarquee: isPointInsideMarquee, selectedIds: selectedSet, focusedItemIndex: focusedItemInfo.seriesIndex === index &&
                                    focusedItemInfo.isFocusVisible &&
                                    !(props.isDataCursorEnabled && props.dataCursorStyle?.isMarkerDisplayed)
                                    ? focusedItemInfo.groupIndex
                                    : undefined, hoveredItemIndex: hoveredItemInfo?.isCurrent && hoveredItemInfo.seriesIndex === index
                                    ? hoveredItemInfo.groupIndex
                                    : undefined, isSelectionEnabled: selectionMode === 'single' || selectionMode === 'multiple', isDrillEnabled: drilling === 'on', defaultFontSize: defaultFontSize, dataLabelEffect: dataLabelEffect, isHighContrast: isHighContrast }))] }));
                }) })
            //TODO - handle isStack part
            );
        } }));
}

export { ComboChart as C };
//# sourceMappingURL=ComboChart-d1c3e17a.js.map
