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

var jsxRuntime = require('preact/jsx-runtime');
var useChartDnd = require('./useChartDnd-765ad341.js');
var Common_themes_themeContract_css = require('./Common/themes/themeContract.css.js');

function AreaSeries({ yScale, lineType = 'straight', color, isHorizontal, isLog, areaColorOpacity, lineSegments, bottomCoords, isHighlighted, isBottomSegmentCurved, seriesIndex }) {
    const style = {
        fill: color,
        opacity: isHighlighted
            ? areaColorOpacity
            : `calc(${Common_themes_themeContract_css.dvtVars.dimmedOpacity} * ${areaColorOpacity})`
    };
    return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: lineSegments.map((lineSegment) => {
            if (lineSegment.length < 2) {
                return;
            }
            let baseCoords;
            if (bottomCoords) {
                // custom bottom coords. eg: top of last series in stacked area
                baseCoords = bottomCoords;
            }
            else {
                // TODO: make this more generic when we support apps setting baseline
                // for log assume domain min is the baseline, otherwise use 0 baseline
                const baselineCoord = yScale.transform(isLog ? yScale.domain()[0] : 0);
                baseCoords = isHorizontal
                    ? [
                        [baselineCoord, lineSegment[0][1]],
                        [baselineCoord, lineSegment[lineSegment.length - 1][1]]
                    ]
                    : [
                        [lineSegment[0][0], baselineCoord],
                        [lineSegment[lineSegment.length - 1][0], baselineCoord]
                    ];
            }
            const cmds = useChartDnd.getCmdsForArea(lineSegment, baseCoords, lineType, isHorizontal, isBottomSegmentCurved);
            return (jsxRuntime.jsx("path", { d: cmds, style: style, "data-oj-series-index": seriesIndex, "data-oj-object": 'area' }));
        }) }));
}

const getLineAreaChartItemPosition = (seriesIndex, groupIndex, 
// TODO: JET-71332 ; should only be (number | undefined)[][]
// scatter chart does not call this function
renderedSeries, getDataItem, groups, isHoriz, xScale, yScale, timeAxisType) => {
    // TODO: JET-71332; remove as number after JET-71332 is fixed
    const value = renderedSeries[seriesIndex][groupIndex];
    if (value == null) {
        return undefined;
    }
    let xVal = groupIndex;
    if (timeAxisType) {
        const val = timeAxisType === 'mixedFrequency'
            ? getDataItem(seriesIndex, groupIndex)?.x
            : groups[groupIndex].id;
        xVal = new Date(val).getTime();
    }
    const x = isHoriz ? yScale.transform(value) : xScale.transform(xVal);
    const y = isHoriz ? xScale.transform(xVal) : yScale.transform(value);
    return { x, y, height: 0, width: 0 };
};

exports.AreaSeries = AreaSeries;
exports.getLineAreaChartItemPosition = getLineAreaChartItemPosition;
//# sourceMappingURL=chartUtils-851ca0ed.js.map
