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

var jsxRuntime = require('preact/jsx-runtime');
var Marker = require('./Marker-fd400f9a.js');

var layoutUtils = require('./layoutUtils-0615d614.js');
var useChartDnd = require('./useChartDnd-765ad341.js');
var useTranslationBundle = require('./useTranslationBundle-38c0edae.js');
var dataStyleUtils = require('./dataStyleUtils-e5ab11d0.js');
var accUtils = require('./accUtils-dcffb3de.js');
var PRIVATE_Chart_themes_ChartStyles_css = require('./PRIVATE_Chart/themes/ChartStyles.css.js');
var classNames = require('./classNames-c14c6ef3.js');
var textUtils = require('./textUtils-e779c845.js');
var utils = require('./utils-606327d1.js');
var Common_themes_themeContract_css = require('./Common/themes/themeContract.css.js');

const DEFAULT_POSITION = 'center';
function MarkerLabel({ labelPosition, label, labelStyle, tx, ty, defaultFontSize, dataLabelEffect, isHighContrast, getTextDimensions }) {
    let markerLabel = null;
    const position = labelPosition ? labelPosition : DEFAULT_POSITION;
    const { dataLabelStyle, dataLabelContrast, highContrastLabelStyle } = PRIVATE_Chart_themes_ChartStyles_css.styles;
    const labelString = label;
    if (position && labelString) {
        const markerLabelStyle = {
            fontSize: defaultFontSize,
            ...textUtils.updateVisTextStyleProperties(labelStyle)
        };
        const labelDims = getTextDimensions?.(labelString, markerLabelStyle);
        const { x, y } = useChartDnd.getLabelPosition(position, tx, ty, labelDims);
        markerLabel = (jsxRuntime.jsx("text", { x: x, y: y, class: classNames.classNames([
                dataLabelStyle,
                dataLabelEffect === 'outline' ? dataLabelContrast : '',
                isHighContrast ? highContrastLabelStyle : ''
            ]), style: markerLabelStyle, children: labelString }));
    }
    return markerLabel;
}

const MARKER_DEFAULT_SIZE = 10;
function MarkersWithLabel({ yScale, xScale, color, seriesIndex, startIndex, endIndex, hiddenIds, selectedIds, highlightedIds, orientation, isLog, markerType, getDataItem, focusedItemIndex, hoveredItemIndex, isDrillEnabled, activeId, isSelectionEnabled, timeAxisType, isPointInsideMarquee, series, groups, defaultFontSize, dataLabelEffect, isHighContrast, isTestEnv, isDataXAxis, getTextDimensions }) {
    const isHoriz = orientation === 'horizontal';
    const items = [];
    const translations = useTranslationBundle.useTranslationBundle('@oracle/oraclejet-preact');
    for (let groupIndex = startIndex; groupIndex < endIndex + 1; groupIndex++) {
        const item = getDataItem(seriesIndex, groupIndex);
        if (!item || hiddenIds?.has(item.id)) {
            continue;
        }
        let x, y;
        const itemHasValue = 'value' in item;
        if (isDataXAxis && 'y' in item) {
            x = xScale.transform(item.x);
            y = yScale.transform(item.y);
        }
        else {
            const value = itemHasValue ? item?.value : undefined;
            if (value == null || (isLog && value <= 0)) {
                continue;
            }
            x = isHoriz
                ? yScale.transform(value)
                : layoutUtils.getGroupCenterCoord(groups[groupIndex], groupIndex, xScale, item, timeAxisType);
            y = isHoriz
                ? layoutUtils.getGroupCenterCoord(groups[groupIndex], groupIndex, xScale, item, timeAxisType)
                : yScale.transform(value);
        }
        const isFocused = focusedItemIndex === groupIndex;
        const isHovered = hoveredItemIndex === groupIndex;
        const isSelected = !!(selectedIds?.has(item.id) || isPointInsideMarquee?.(item.id, { x, y })); // TODO: tagcloud has isItemSelected we should look to leverage here
        const isDrillable = item.drilling === 'on' || (item.drilling != 'off' && isDrillEnabled);
        const isHighlighted = !highlightedIds || highlightedIds?.size === 0 || highlightedIds?.has(item.id); // TODO: tagcloud has isItemHighlighted we should look to leverage here
        const { fill, stroke, outerStroke } = useChartDnd.getMarkerFillAndStroke(!!item.isMarkerDisplayed, isSelectionEnabled, isHovered, isFocused, isSelected, color, item.markerColor);
        const itemMarkerType = item.isMarkerDisplayed ? item.markerType || markerType : markerType;
        const isActive = isFocused || isHovered;
        const ariaLabel = accUtils.supportsMobileScreenReader || isActive
            ? dataStyleUtils.getItemAriaLabel(translations, series.name || series.id.toString(), groups[groupIndex].name || groups[groupIndex].id, isSelectionEnabled, isSelected, isDrillable, item.accessibleLabel, itemHasValue ? item.value : undefined, item.x, 'y' in item ? item.y : undefined)
            : undefined;
        const dataInfo = {
            'data-oj-series-index': seriesIndex,
            'data-oj-group-index': groupIndex,
            'data-oj-object': 'item',
            id: isActive ? activeId : undefined,
            role: ariaLabel ? 'img' : undefined,
            'aria-label': ariaLabel,
            'data-oj-private-item-id': isTestEnv ? item.id : undefined
        };
        const markerSize = (item.markerSize || MARKER_DEFAULT_SIZE) + 2 * Marker.MARKER_PADDING;
        items.push(jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(Marker.Marker, { type: itemMarkerType, tx: x, ty: y, isInteractive: isDrillable || isSelectionEnabled, scale: 1, fill: fill, stroke: stroke, outerStroke: outerStroke, width: markerSize, height: markerSize, dataInfo: dataInfo, preserveRectAspectRatio: true, styleClass: isHighlighted ? undefined : PRIVATE_Chart_themes_ChartStyles_css.styles.dimmed }), jsxRuntime.jsx(MarkerLabel, { labelPosition: item.labelPosition, label: item.label, labelStyle: item.labelStyle, tx: x, ty: y, defaultFontSize: defaultFontSize, dataLabelEffect: dataLabelEffect, isHighContrast: isHighContrast, getTextDimensions: getTextDimensions })] }));
    }
    return jsxRuntime.jsx(jsxRuntime.Fragment, { children: items });
}

function LineSeries({ color, isHorizontal, lineType = 'straight', lineColor, lineStyle, lineWidth = 3, isHighlighted, lineSegmentCoords, seriesIndex }) {
    const style = {
        stroke: lineColor || color,
        strokeDasharray: lineStyle === 'dotted' ? 3 : lineStyle === 'dashed' ? 6 : undefined,
        strokeWidth: lineWidth,
        fill: utils.rgba(Common_themes_themeContract_css.colorSchemeVars.palette.neutral[0], 0)
    };
    return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: lineSegmentCoords.map((value) => {
            if (value.length < 2) {
                return;
            }
            const cmds = useChartDnd.getCmdsForLine(value, lineType, isHorizontal);
            return lineType === 'straight' ? (jsxRuntime.jsx("polyline", { points: cmds, style: style, className: isHighlighted ? undefined : PRIVATE_Chart_themes_ChartStyles_css.styles.dimmed, "data-oj-series-index": seriesIndex, "data-oj-object": 'line' })) : (jsxRuntime.jsx("path", { d: cmds, style: style, className: isHighlighted ? undefined : PRIVATE_Chart_themes_ChartStyles_css.styles.dimmed, "data-oj-series-index": seriesIndex, "data-oj-object": 'line' }));
        }) }));
}

exports.LineSeries = LineSeries;
exports.MarkersWithLabel = MarkersWithLabel;
//# sourceMappingURL=LineSeries-a658f2b0.js.map
