import { parrotI18n } from '@cloudtower/parrot';
import ErrorBoundary from '../ErrorBoundary/index.js';
import Pointer from './Pointer.js';
import RenderChart from './RenderChart.js';
import { LineChartWrapper } from './styled.js';
import cs from 'classnames';
import React__default, { useState, useRef, useEffect } from 'react';

var __defProp = Object.defineProperty;
var __defProps = Object.defineProperties;
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __propIsEnum = Object.prototype.propertyIsEnumerable;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __spreadValues = (a, b) => {
  for (var prop in b || (b = {}))
    if (__hasOwnProp.call(b, prop))
      __defNormalProp(a, prop, b[prop]);
  if (__getOwnPropSymbols)
    for (var prop of __getOwnPropSymbols(b)) {
      if (__propIsEnum.call(b, prop))
        __defNormalProp(a, prop, b[prop]);
    }
  return a;
};
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
const LineChart = React__default.forwardRef(
  (props, ref) => {
    const {
      height = 154,
      showPointer = true,
      showLegend = true,
      showXaxis = false,
      chartProps
    } = props;
    const [width, setWidth] = useState(0);
    const wrapperRef = useRef(null);
    useEffect(() => {
      var _a;
      setWidth(((_a = wrapperRef.current) == null ? void 0 : _a.offsetWidth) || 0);
    }, []);
    return /* @__PURE__ */ React__default.createElement(ErrorBoundary, { i18n: parrotI18n }, /* @__PURE__ */ React__default.createElement(
      LineChartWrapper,
      {
        className: cs("metric-wrapper", !showXaxis && "hidden-xaxis"),
        ref: wrapperRef,
        style: { height: showLegend ? height + 30 : height }
      },
      /* @__PURE__ */ React__default.createElement(RenderChart, __spreadProps(__spreadValues({}, chartProps), { width })),
      showPointer && /* @__PURE__ */ React__default.createElement(Pointer, { uuid: chartProps.syncId, metricWidth: width })
    ));
  }
);
var LineChart$1 = LineChart;

export { LineChart$1 as default };
