import { jsxs, Fragment, jsx } from "react/jsx-runtime";
import { ReferenceArea, Line, Dot } from "recharts";
import { labeledReferenceLine } from "./labeledReferenceLine.js";
function renderReferenceBand({ peak, limit, unit, curveType }) {
  const peakOverLimit = peak > limit;
  const color = peakOverLimit ? "Red" : "Purple";
  const referenceAreaProps = {
    ifOverflow: "extendDomain",
    y1: Math.min(peak, limit),
    y2: Math.max(peak, limit)
  };
  return /* @__PURE__ */ jsxs(Fragment, { children: [
    /* @__PURE__ */ jsx(ReferenceArea, { fill: "url(#referenceAreaFill)", ...referenceAreaProps }),
    /* @__PURE__ */ jsx("defs", { children: /* @__PURE__ */ jsxs("linearGradient", { id: "referenceAreaFill", x1: ".5", x2: ".5", y2: "1", children: [
      /* @__PURE__ */ jsx("stop", { stopColor: "transparent" }),
      /* @__PURE__ */ jsx("stop", { offset: "1", stopColor: `var(--theme-ui-colors-${color})`, stopOpacity: 0.32 })
    ] }) }),
    labeledReferenceLine(
      { y: limit, stroke: color, strokeOpacity: 0.88, background: peakOverLimit ? "Red16" : void 0 },
      `Limit ${limit} ${unit}`
    ),
    labeledReferenceLine(
      {
        y: peak,
        stroke: color,
        strokeOpacity: 0.88,
        strokeDasharray: "8 8",
        background: peakOverLimit ? "Red16" : void 0
      },
      `Peak ${peak} ${unit}`
    ),
    peakOverLimit && /* @__PURE__ */ jsxs(Fragment, { children: [
      /* @__PURE__ */ jsx(
        ReferenceArea,
        {
          ...referenceAreaProps,
          shape: (props) => /* @__PURE__ */ jsx("defs", { children: /* @__PURE__ */ jsx("mask", { id: "chartBandMask", children: /* @__PURE__ */ jsx("rect", { x: props.x, y: props.y, width: props.width, height: props.height, fill: "#fff" }) }) })
        }
      ),
      /* @__PURE__ */ jsx(
        Line,
        {
          name: "",
          dataKey: "y",
          strokeWidth: 2,
          type: curveType,
          stroke: "var(--theme-ui-colors-Red)",
          dot: false,
          activeDot: (props) => {
            if ("value" in props && typeof props.value === "number" && props.value <= limit) return /* @__PURE__ */ jsx(Fragment, {});
            return /* @__PURE__ */ jsx(Dot, { ...props });
          },
          style: { mask: "url(#chartBandMask)" }
        }
      )
    ] })
  ] });
}
export {
  renderReferenceBand
};
