import { isPositionMeasure } from "./measures/index.js";
import { isCommonMeasureEncoding, isMeasureTreeWithParentId } from "../advanced/chart/pipes/measures/utils.js";
import { unique } from "remeda";
import { ChartTypeEnum, DEFAULT_PARENT_ID } from "./constant.js";
const isTable = (vseed)=>vseed.chartType === ChartTypeEnum.Table;
const isPivotTable = (vseed)=>vseed.chartType === ChartTypeEnum.PivotTable;
const isRadar = (vseed)=>vseed.chartType === ChartTypeEnum.Radar;
const isAreaPercent = (vseed)=>vseed.chartType === ChartTypeEnum.AreaPercent;
const isColumnPercent = (vseed)=>vseed.chartType === ChartTypeEnum.ColumnPercent;
const isBarPercent = (vseed)=>vseed.chartType === ChartTypeEnum.BarPercent;
const isBarLikeChart = (vseed)=>vseed.chartType === ChartTypeEnum.Bar || vseed.chartType === ChartTypeEnum.BarPercent || vseed.chartType === ChartTypeEnum.BarParallel;
const isVTable = (vseed)=>[
        'table',
        'pivotTable'
    ].includes(vseed.chartType);
const isVChart = (vseed)=>!isVTable(vseed);
const isPivotChart = (vseed)=>{
    if (isVTable(vseed)) return false;
    if (isPivot(vseed)) return true;
    return isCombination(vseed);
};
const isPivot = (vseed)=>{
    const { dimensions = [], measures = [] } = vseed;
    if (dimensions && dimensions.some((dimension)=>'row' === dimension.encoding || 'column' === dimension.encoding)) return true;
    if (vseed.chartType === ChartTypeEnum.Scatter) {
        const xCount = measures.filter((m)=>'xAxis' === m.encoding).length;
        const yCount = measures.filter((m)=>'yAxis' === m.encoding).length;
        const otherCount = measures.filter((m)=>![
                'size',
                'xAxis',
                'yAxis'
            ].includes(m.encoding) && !isCommonMeasureEncoding(m.encoding)).length;
        let finalXCount;
        let finalYCount;
        if (xCount > 0) {
            finalXCount = xCount;
            finalYCount = yCount + otherCount;
        } else {
            finalXCount = otherCount > 0 ? 1 : 0;
            finalYCount = yCount + Math.max(otherCount - 1, 0);
        }
        if (finalXCount > 1 || finalYCount > 1) return true;
    }
    return false;
};
const isCombination = (vseed)=>{
    if (isMeasureTreeWithParentId(vseed.measures)) {
        const parentIds = vseed.measures?.filter((m)=>isPositionMeasure(m, vseed.chartType)).map((measure)=>measure.parentId || DEFAULT_PARENT_ID);
        return parentIds && unique(parentIds).length > 1;
    }
    const { measures = [] } = vseed;
    const hasMeasureGroup = measures && measures.some((measure)=>measure && measure.children);
    return hasMeasureGroup;
};
const isRectungularCoordinate = (chartType)=>[
        ChartTypeEnum.Bar,
        ChartTypeEnum.BarPercent,
        ChartTypeEnum.BarParallel,
        ChartTypeEnum.Column,
        ChartTypeEnum.ColumnPercent,
        ChartTypeEnum.ColumnParallel,
        ChartTypeEnum.Line,
        ChartTypeEnum.Area,
        ChartTypeEnum.AreaPercent,
        ChartTypeEnum.DualAxis,
        ChartTypeEnum.Boxplot,
        ChartTypeEnum.DualAxis,
        ChartTypeEnum.Scatter,
        ChartTypeEnum.Heatmap,
        ChartTypeEnum.Boxplot
    ].includes(chartType);
const DEFAULT_DUAL_CHART_TYPE = {
    primary: 'column',
    secondary: 'line'
};
const isDualAxisChartType = (chartType)=>chartType && [
        'column',
        'columnParallel',
        'columnPercent',
        'line',
        'area',
        'areaPercent',
        'scatter'
    ].includes(chartType);
export { DEFAULT_DUAL_CHART_TYPE, isAreaPercent, isBarLikeChart, isBarPercent, isColumnPercent, isCombination, isDualAxisChartType, isPivot, isPivotChart, isPivotTable, isRadar, isRectungularCoordinate, isTable, isVChart, isVTable };

//# sourceMappingURL=chatType.js.map