'use strict';
import { jsx, jsxs } from 'react/jsx-runtime';
import { ResponsiveContainer, RadialBarChart, Tooltip, Legend, RadialBar, RadarChart, PolarGrid, PolarAngleAxis, Radar, PieChart, Pie, Cell, BarChart, CartesianGrid, XAxis, YAxis, Bar, AreaChart, Area, LineChart, Line } from 'recharts';
import { chartTypes } from '../reports/report-enums.js';

var __defProp = Object.defineProperty;
var __name = (target, value) => __defProp(target, "name", {
  value,
  configurable: true
});
function Chart({
  series,
  chartType,
  data
}) {
  const getColor = /* @__PURE__ */__name(i => `hsl(var(--chart-${i % 5 + 1}))`, "getColor");
  let result = /* @__PURE__ */jsx("div", {
    children: "Unsupported chart type"
  });
  if (!series || series.length === 0 || !data || data.length === 0) {
    result = /* @__PURE__ */jsx("div", {
      children: "No data available"
    });
  } else {
    const xAxisKey = series.find(s => s.axisXPropertyName)?.axisXPropertyName ?? "x";
    switch (chartType) {
      case chartTypes.line:
        result = /* @__PURE__ */jsx(ResponsiveContainer, {
          className: "size-full",
          children: /* @__PURE__ */jsxs(LineChart, {
            data,
            children: [/* @__PURE__ */jsx(CartesianGrid, {
              strokeDasharray: "3 3"
            }), /* @__PURE__ */jsx(XAxis, {
              dataKey: xAxisKey
            }), /* @__PURE__ */jsx(YAxis, {}), /* @__PURE__ */jsx(Tooltip, {}), /* @__PURE__ */jsx(Legend, {}), series.map((s, i) => /* @__PURE__ */jsx(Line, {
              dataKey: s.axisYPropertyName,
              name: s.name,
              stroke: s.axisYColor ?? getColor(i),
              strokeWidth: 2,
              dot: false
            }, s.id))]
          })
        });
        break;
      case chartTypes.area:
      case chartTypes.areaExpanded:
        result = /* @__PURE__ */jsx(ResponsiveContainer, {
          className: "size-full",
          children: /* @__PURE__ */jsxs(AreaChart, {
            data,
            stackOffset: chartType === chartTypes.areaExpanded ? "expand" : void 0,
            children: [/* @__PURE__ */jsx(CartesianGrid, {
              strokeDasharray: "3 3"
            }), /* @__PURE__ */jsx(XAxis, {
              dataKey: xAxisKey
            }), /* @__PURE__ */jsx(YAxis, {}), /* @__PURE__ */jsx(Tooltip, {}), /* @__PURE__ */jsx(Legend, {}), series.map((s, i) => /* @__PURE__ */jsx(Area, {
              type: "natural",
              dataKey: s.axisYPropertyName,
              name: s.name,
              fill: s.axisYColor ?? getColor(i),
              stroke: s.axisYColor ?? getColor(i),
              fillOpacity: 0.4
            }, s.id))]
          })
        });
        break;
      case chartTypes.bar:
      case chartTypes.barStacked:
      case chartTypes.barMixed:
        result = /* @__PURE__ */jsx(ResponsiveContainer, {
          className: "size-full",
          children: /* @__PURE__ */jsxs(BarChart, {
            data,
            children: [/* @__PURE__ */jsx(CartesianGrid, {
              strokeDasharray: "3 3"
            }), /* @__PURE__ */jsx(XAxis, {
              dataKey: xAxisKey
            }), /* @__PURE__ */jsx(YAxis, {}), /* @__PURE__ */jsx(Tooltip, {}), /* @__PURE__ */jsx(Legend, {}), series.map((s, i) => /* @__PURE__ */jsx(Bar, {
              dataKey: s.axisYPropertyName,
              name: s.name,
              fill: s.axisYColor ?? getColor(i),
              stackId: chartType === chartTypes.barStacked ? "stack" : void 0
            }, s.id))]
          })
        });
        break;
      case chartTypes.pie:
      case chartTypes.donut:
        result = /* @__PURE__ */jsx(ResponsiveContainer, {
          className: "size-full",
          children: /* @__PURE__ */jsxs(PieChart, {
            children: [/* @__PURE__ */jsx(Tooltip, {}), /* @__PURE__ */jsx(Legend, {}), series.map((s, i) => /* @__PURE__ */jsx(Pie, {
              data,
              dataKey: s.axisYPropertyName,
              nameKey: s.axisXPropertyName,
              innerRadius: chartType === chartTypes.donut ? 40 : 0,
              outerRadius: 80,
              fill: s.axisYColor ?? getColor(i),
              label: true,
              children: data.map((item, j) => /* @__PURE__ */jsx(Cell, {
                fill: getColor(j)
              }, `${s.id}_${item[xAxisKey] ?? item[s.axisYPropertyName] ?? ""}`))
            }, s.id))]
          })
        });
        break;
      case chartTypes.radar:
      case chartTypes.radarLines:
        result = /* @__PURE__ */jsx(ResponsiveContainer, {
          className: "size-full",
          children: /* @__PURE__ */jsxs(RadarChart, {
            data,
            children: [/* @__PURE__ */jsx(PolarGrid, {}), /* @__PURE__ */jsx(PolarAngleAxis, {
              dataKey: xAxisKey
            }), /* @__PURE__ */jsx(Tooltip, {}), /* @__PURE__ */jsx(Legend, {}), series.map((s, i) => /* @__PURE__ */jsx(Radar, {
              name: s.name,
              dataKey: s.axisYPropertyName,
              stroke: s.axisYColor ?? getColor(i),
              fill: s.axisYColor ?? getColor(i),
              fillOpacity: chartType === chartTypes.radarLines ? 0 : 0.6,
              strokeWidth: chartType === chartTypes.radarLines ? 2 : 1
            }, s.id))]
          })
        });
        break;
      case chartTypes.radial:
      case chartTypes.radialStacked:
        result = /* @__PURE__ */jsx(ResponsiveContainer, {
          className: "size-full",
          children: /* @__PURE__ */jsxs(RadialBarChart, {
            data,
            innerRadius: 10,
            outerRadius: 110,
            startAngle: 180,
            endAngle: 0,
            children: [/* @__PURE__ */jsx(Tooltip, {}), /* @__PURE__ */jsx(Legend, {}), series.map((s, i) => /* @__PURE__ */jsx(RadialBar, {
              dataKey: s.axisYPropertyName,
              name: s.name,
              fill: s.axisYColor ?? getColor(i),
              cornerRadius: chartType === chartTypes.radialStacked ? 5 : 0
            }, s.id))]
          })
        });
        break;
      default:
        break;
    }
  }
  return result;
}
__name(Chart, "Chart");

export { Chart };
