// Tremor Spark Chart [v1.0.0]
/* eslint-disable @typescript-eslint/no-explicit-any */
"use client";
var __rest = (this && this.__rest) || function (s, e) {
    var t = {};
    for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
        t[p] = s[p];
    if (s != null && typeof Object.getOwnPropertySymbols === "function")
        for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
            if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
                t[p[i]] = s[p[i]];
        }
    return t;
};
import React from "react";
import { Area, Bar, Line, AreaChart as RechartsAreaChart, BarChart as RechartsBarChart, LineChart as RechartsLineChart, ResponsiveContainer, XAxis, YAxis, } from "recharts";
import { AvailableChartColors, constructCategoryColors, getColorClassName, } from "../Utils/ChartColors";
import { cx } from "../Utils/Cx";
import { getYAxisDomain } from "../Utils/GetYAxisDomain";
const SparkAreaChart = React.forwardRef((props, forwardedRef) => {
    const { data = [], categories = [], index, colors = AvailableChartColors, autoMinValue = false, minValue, maxValue, connectNulls = false, type = "default", className, fill = "gradient" } = props, other = __rest(props, ["data", "categories", "index", "colors", "autoMinValue", "minValue", "maxValue", "connectNulls", "type", "className", "fill"]);
    const categoryColors = constructCategoryColors(categories, colors);
    const yAxisDomain = getYAxisDomain(autoMinValue, minValue, maxValue);
    const stacked = type === "stacked" || type === "percent";
    const areaId = React.useId();
    const getFillContent = (fillType) => {
        switch (fillType) {
            case "none":
                return React.createElement("stop", { stopColor: "currentColor", stopOpacity: 0 });
            case "gradient":
                return (React.createElement(React.Fragment, null,
                    React.createElement("stop", { offset: "5%", stopColor: "currentColor", stopOpacity: 0.4 }),
                    React.createElement("stop", { offset: "95%", stopColor: "currentColor", stopOpacity: 0 })));
            case "solid":
                return React.createElement("stop", { stopColor: "currentColor", stopOpacity: 0.3 });
            default:
                return React.createElement("stop", { stopColor: "currentColor", stopOpacity: 0.3 });
        }
    };
    return (React.createElement("div", Object.assign({ ref: forwardedRef, className: cx("h-12 w-28", className), "data-tremor-id": "tremor-raw" }, other),
        React.createElement(ResponsiveContainer, null,
            React.createElement(RechartsAreaChart, Object.assign({ data: data, margin: {
                    bottom: 1,
                    left: 1,
                    right: 1,
                    top: 1,
                } }, (type === "percent" && { stackOffset: "expand" })),
                React.createElement(XAxis, { hide: true, dataKey: index }),
                React.createElement(YAxis, { hide: true, domain: yAxisDomain }),
                categories.map((category) => {
                    const categoryId = `${areaId}-${category.replace(/[^a-zA-Z0-9]/g, "")}`;
                    return (React.createElement(React.Fragment, { key: category },
                        React.createElement("defs", null,
                            React.createElement("linearGradient", { key: category, className: cx(getColorClassName(categoryColors.get(category), "text")), id: categoryId, x1: "0", y1: "0", x2: "0", y2: "1" }, getFillContent(fill))),
                        React.createElement(Area, Object.assign({ className: cx(getColorClassName(categoryColors.get(category), "stroke")), dot: false, strokeOpacity: 1, name: category, type: "linear", dataKey: category, stroke: "", strokeWidth: 2, strokeLinejoin: "round", strokeLinecap: "round", isAnimationActive: false, connectNulls: connectNulls }, (stacked && { stackId: "stack" }), { fill: `url(#${categoryId})` }))));
                })))));
});
SparkAreaChart.displayName = "SparkAreaChart";
const SparkLineChart = React.forwardRef((props, forwardedRef) => {
    const { data = [], categories = [], index, colors = AvailableChartColors, autoMinValue = false, minValue, maxValue, connectNulls = false, className } = props, other = __rest(props, ["data", "categories", "index", "colors", "autoMinValue", "minValue", "maxValue", "connectNulls", "className"]);
    const categoryColors = constructCategoryColors(categories, colors);
    const yAxisDomain = getYAxisDomain(autoMinValue, minValue, maxValue);
    return (React.createElement("div", Object.assign({ ref: forwardedRef, className: cx("h-12 w-28", className), "data-tremor-id": "tremor-raw" }, other),
        React.createElement(ResponsiveContainer, null,
            React.createElement(RechartsLineChart, { data: data, margin: {
                    bottom: 1,
                    left: 1,
                    right: 1,
                    top: 1,
                } },
                React.createElement(XAxis, { hide: true, dataKey: index }),
                React.createElement(YAxis, { hide: true, domain: yAxisDomain }),
                categories.map((category) => {
                    return (React.createElement(Line, { className: cx(getColorClassName(categoryColors.get(category), "stroke")), dot: false, strokeOpacity: 1, key: category, name: category, type: "linear", dataKey: category, stroke: "", strokeWidth: 2, strokeLinejoin: "round", strokeLinecap: "round", isAnimationActive: false, connectNulls: connectNulls }));
                })))));
});
SparkLineChart.displayName = "SparkLineChart";
const SparkBarChart = React.forwardRef((props, forwardedRef) => {
    const { data = [], categories = [], index, colors = AvailableChartColors, autoMinValue = false, minValue, maxValue, barCategoryGap, type = "default", className } = props, other = __rest(props, ["data", "categories", "index", "colors", "autoMinValue", "minValue", "maxValue", "barCategoryGap", "type", "className"]);
    const categoryColors = constructCategoryColors(categories, colors);
    const yAxisDomain = getYAxisDomain(autoMinValue, minValue, maxValue);
    const stacked = type === "stacked" || type === "percent";
    return (React.createElement("div", Object.assign({ ref: forwardedRef, className: cx("h-12 w-28", className), "data-tremor-id": "tremor-raw" }, other),
        React.createElement(ResponsiveContainer, null,
            React.createElement(RechartsBarChart, Object.assign({ data: data, margin: {
                    bottom: 1,
                    left: 1,
                    right: 1,
                    top: 1,
                } }, (type === "percent" && { stackOffset: "expand" }), (barCategoryGap !== undefined && { barCategoryGap })),
                React.createElement(XAxis, { hide: true, dataKey: index }),
                React.createElement(YAxis, { hide: true, domain: yAxisDomain }),
                categories.map((category) => {
                    return (React.createElement(Bar, Object.assign({ className: cx(getColorClassName(categoryColors.get(category), "fill")), key: category, name: category, type: "linear", dataKey: category }, (stacked && { stackId: "stack" }), { isAnimationActive: false, fill: "" })));
                })))));
});
SparkBarChart.displayName = "SparkBarChart";
export { SparkAreaChart, SparkLineChart, SparkBarChart };
//# sourceMappingURL=SparkChart.js.map