import WidgetCard from "../../WidgetCard.mjs";
import FluentStatsSnippet from "../../FluentComponents/atoms/FluentStatsSnippet.mjs";
import { convertISODate } from "../../utils/ConvertISODate.mjs";
import { c } from "react-compiler-runtime";
import React, { forwardRef } from "react";
import { Box, Grid, Typography } from "@material-ui/core";
import { MuiVegaLite } from "@material-vega/material-ui";
//#region src/UI/widgets/library/BarChartWidget/BarChartWidget.jsx
const layout = {
	w: {
		default: 2,
		min: 0,
		max: 4
	},
	h: {
		default: 2,
		min: 0,
		max: 4
	}
};
const params = { mode: { defaultValue: "chart" } };
const BarChartWidget = (props, ref) => {
	const $ = c(14);
	let children;
	let other;
	let params;
	if ($[0] !== props) {
		const { children: t0, params: t1, setParam, ...t2 } = props;
		children = t0;
		params = t1;
		other = t2;
		$[0] = props;
		$[1] = children;
		$[2] = other;
		$[3] = params;
	} else {
		children = $[1];
		other = $[2];
		params = $[3];
	}
	const { mockData, theme, dateRange } = params;
	const t0 = mockData?.title;
	const t1 = theme && theme;
	let t2;
	if ($[4] !== children || $[5] !== dateRange || $[6] !== mockData) {
		t2 = mockData ? /* @__PURE__ */ React.createElement(React.Fragment, null, dateRange && /* @__PURE__ */ React.createElement(Typography, {
			gutterBottom: true,
			variant: "caption",
			component: "h3"
		}, "From: ", convertISODate(dateRange.from), " to:", " ", convertISODate(dateRange.to)), mockData?.stats && /* @__PURE__ */ React.createElement(Grid, { container: true }, mockData?.stats.map(_temp)), /* @__PURE__ */ React.createElement(Box, {
			clone: true,
			flex: 1,
			mt: 1,
			overflow: "hidden"
		}, /* @__PURE__ */ React.createElement(MuiVegaLite, {
			width: "container",
			height: "container",
			autoResize: "true",
			variant: "verticalBarChart",
			spec: {
				$schema: "https://vega.github.io/schema/vega-lite/v4.json",
				data: { values: mockData?.data },
				mark: "bar",
				encoding: {
					x: {
						field: "xAxis",
						type: mockData?.xAxisType,
						axis: { ticks: false },
						band: .5
					},
					y: {
						field: "yAxis",
						type: mockData?.yAxisType,
						axis: { format: mockData?.yAxisFormat }
					}
				}
			}
		})), children) : /* @__PURE__ */ React.createElement(Typography, { variant: "subtitle2" }, "Could not retrieve widget data. Please contact support.");
		$[4] = children;
		$[5] = dateRange;
		$[6] = mockData;
		$[7] = t2;
	} else t2 = $[7];
	let t3;
	if ($[8] !== other || $[9] !== ref || $[10] !== t0 || $[11] !== t1 || $[12] !== t2) {
		t3 = /* @__PURE__ */ React.createElement(WidgetCard, {
			ref,
			...other,
			title: t0,
			theme: t1
		}, t2);
		$[8] = other;
		$[9] = ref;
		$[10] = t0;
		$[11] = t1;
		$[12] = t2;
		$[13] = t3;
	} else t3 = $[13];
	return t3;
};
var BarChartWidget_default = forwardRef(BarChartWidget);
function _temp(stat) {
	return /* @__PURE__ */ React.createElement(Grid, {
		item: true,
		xs: 3,
		key: stat.label
	}, /* @__PURE__ */ React.createElement(FluentStatsSnippet, {
		label: stat.label,
		amount: stat.currentValue,
		prevAmount: stat.previousValue
	}));
}
//#endregion
export { BarChartWidget_default as default, layout, params };

//# sourceMappingURL=BarChartWidget.mjs.map