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

var jsxRuntime = require('preact/jsx-runtime');
var layoutUtils = require('./layoutUtils-0615d614.js');
var useChartDnd = require('./useChartDnd-765ad341.js');
var LineSeries = require('./LineSeries-a658f2b0.js');
var dataStyleUtils = require('./dataStyleUtils-e5ab11d0.js');
var useUser = require('./useUser-c85f9587.js');
var colorUtils = require('./colorUtils-d762d81b.js');
require('./accUtils-dcffb3de.js');
var Chart = require('./Chart-13ccd345.js');

const AXIS_OFFSET = 0.2;
/**
 * Scatter charts define data items using x and y values, making them useful for viewing relationships between 2 dimensions.
 */
function ScatterChart({ width, height, selectedIds = [], hiddenIds = [], highlightedIds, hideAndShowBehavior = 'none', orientation = 'vertical', yAxis, series, groups, getDataItem, selectionMode = 'none', drilling = 'off', dataLabelEffect = 'outline', lineType = 'none', ...props }) {
    const { direction, forcedColors } = useUser.useUser();
    const isHighContrast = forcedColors === 'active';
    const isTestEnv = props.testId !== undefined;
    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 = colorUtils.getColorRamp();
    const renderedSeries = useChartDnd.getSeriesData(series?.length, groups?.length, getDataItem, hiddenSet, isLog);
    const renderedGetDataItem = (seriesIndex, groupIndex) => getDataItem(seriesIndex, groupIndex);
    const getGapRatio = () => {
        return 1;
    };
    const getNextChartItemFunc = (startIndex, endIndex) => {
        // TODO: JET-71301
        return dataStyleUtils.getLineAreaChartNavUtil(getDataItem, series.length, startIndex, endIndex, false, isRtl, isHoriz);
    };
    const getDataItemPos = (xScale, yScale) => {
        return (seriesIndex, groupIndex) => {
            // Scatter shouldn't create renderedSeries. Can filter for hidden item here.
            // TODO: JET-71332
            const item = renderedSeries[seriesIndex][groupIndex];
            if (item?.x == null && item?.y) {
                return;
            }
            const x = xScale.transform(item?.x);
            const y = yScale.transform(item?.y);
            return { x, y, height: 0, width: 0 };
        };
    };
    const getMarkerColorAndType = (seriesIndex, groupIndex) => {
        return {
            color: dataStyleUtils.getItemColor(seriesIndex, groupIndex, series, getDataItem),
            type: dataStyleUtils.getMarkerType(seriesIndex, groupIndex, getDataItem)
        };
    };
    const findNearest = (xScale, yScale) => {
        const getSeriesDataInfo = () => {
            return {
                offset: 0,
                dataWidth: 0
            };
        };
        const getYCoord = (value, yScale) => {
            return yScale.transform(value);
        };
        return layoutUtils.findNearestDataPoint(series, groups, xScale, yScale, renderedGetDataItem, false, getSeriesDataInfo, getYCoord, isLog, 0, hiddenSet, timeAxisType);
    };
    const markers = useChartDnd.getMarkers();
    return (jsxRuntime.jsx(Chart.Chart, { width: width, height: height, selectedIds: selectedSet, hiddenIds: hiddenIds, hideAndShowBehavior: hideAndShowBehavior, orientation: orientation, yAxis: yAxis, series: series, groups: groups, overview: "off", defaultOverviewContentRenderer: () => null, selectionMode: selectionMode, drilling: drilling, getDataItem: getDataItem, findNearest: findNearest, getDataItemPos: getDataItemPos, getMarkerInfo: getMarkerColorAndType, renderGridLinesInFront: true, isDataXAxis: true, getNavUtil: getNextChartItemFunc, getGapRatio: getGapRatio, offset: AXIS_OFFSET, isRtl: isRtl, ...props, children: ({ xStartIndex, xEndIndex, xScale, yScale, activeId, focusedItemInfo, hoveredItemInfo, isPointInsideMarquee, defaultFontSize, getTextDimensions }) => {
            return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: renderedSeries.map((lineAreaSeries, index) => {
                    if (lineAreaSeries.length === 0) {
                        /* TODO: need a better way to handle when a series is hidden. */
                        return;
                    }
                    const seriesItem = series[index];
                    const isLineRendered = lineType !== 'none';
                    const lineSegmentCoords = useChartDnd.getLineAreaSegments(yScale, xScale, lineAreaSeries, xStartIndex, xEndIndex, isHoriz, isLog, groups, index, renderedGetDataItem, timeAxisType, true);
                    const isHighlighted = highlightedIds === undefined ||
                        highlightedIds.length === 0 ||
                        highlightedSet.has(seriesItem.id);
                    return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [isLineRendered && (jsxRuntime.jsx(LineSeries.LineSeries, { lineType: lineType, 
                                /* TODO: confirm with UX if this is contrastLine (changes depending on dark/light mode) or always white.
                                  It's always white in legacy.*/
                                lineColor: seriesItem.lineColor, 
                                /* The area generated in legacy are bit apart and not touching when stacked. Preact areas are a bit closer than legacy when curved.
                                Increased the contrast linewidth (to 2.5 from legacy 1.25) to give legacy visual treatment.
                                TODO: investivage why legacy areas are not touching. maybe we want to do the same in preact svg utils that
                                generates this curve.
                               */
                                lineWidth: seriesItem.lineWidth, lineStyle: seriesItem.lineStyle, color: seriesItem.lineColor || colors[index % colors.length], lineSegmentCoords: lineSegmentCoords, isHorizontal: isHoriz, isHighlighted: isHighlighted, seriesIndex: index })), jsxRuntime.jsx(LineSeries.MarkersWithLabel, { yScale: yScale, xScale: xScale, groups: groups, series: seriesItem, timeAxisType: timeAxisType, color: seriesItem.lineColor ||
                                    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, highlightedIds: highlightedIds !== undefined ? highlightedSet : undefined, 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, isTestEnv: isTestEnv, isDataXAxis: true, getTextDimensions: getTextDimensions })] }));
                }) }));
        } }));
}

exports.ScatterChart = ScatterChart;
//# sourceMappingURL=ScatterChart-b2bdfc36.js.map
