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

var __defProp = Object.defineProperty;
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;
};
const Metric = (props) => {
  const {
    height = 154,
    showPointer = true,
    showLegend = true,
    showXaxis = false,
    chartProps
  } = props;
  const [width, setWidth] = useState();
  const wrapperRef = useRef(null);
  useEffect(() => {
    var _a;
    setWidth((_a = wrapperRef.current) == null ? void 0 : _a.offsetWidth);
  }, []);
  return /* @__PURE__ */ React__default.createElement(ErrorBoundary, { i18n: parrotI18n }, /* @__PURE__ */ React__default.createElement(
    MetricWrapper,
    {
      className: cs("metric-wrapper", !showXaxis && "hidden-xaxis"),
      ref: wrapperRef,
      style: { height: showLegend ? height + 30 : height }
    },
    /* @__PURE__ */ React__default.createElement(RenderChart, __spreadValues({}, chartProps)),
    showPointer && /* @__PURE__ */ React__default.createElement(Pointer, { uuid: chartProps.syncId, metricWidth: width })
  ));
};
var Metric$1 = Metric;

export { Pointer, RenderChart, Metric$1 as default };
