/* Copyright © 2020 Splunk Inc.
SPLUNK CONFIDENTIAL – Use or disclosure of this material in whole or
in part without a valid written license from Splunk Inc. is PROHIBITED. */
var __create = Object.create;
var __defProp = Object.defineProperty;
var __defProps = Object.defineProperties;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __propIsEnum = Object.prototype.propertyIsEnumerable;
var __pow = Math.pow;
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));
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/Tooltips.tsx
var Tooltips_exports = {};
__export(Tooltips_exports, {
  BasicMultiValueTooltip: () => BasicMultiValueTooltip,
  BasicMultiValueTooltipFactory: () => BasicMultiValueTooltipFactory,
  BasicSingleValueTooltip: () => BasicSingleValueTooltip,
  BasicSingleValueTooltipFactory: () => BasicSingleValueTooltipFactory,
  DataSeriesTooltipContainer: () => DataSeriesTooltipContainer,
  EventAnnotationTooltipContainer: () => EventAnnotationTooltipContainer,
  TooltipContainer: () => TooltipContainer,
  TooltipOutsideChart: () => TooltipOutsideChart
});
module.exports = __toCommonJS(Tooltips_exports);

// esm-externals:lodash
var lodash_exports = {};
__export(lodash_exports, {
  default: () => lodash_default
});
var defaultImport = __toESM(require("lodash"));
__reExport(lodash_exports, require("lodash"));
var lodash_default = "default" in defaultImport ? defaultImport.default : defaultImport;

// esm-externals:react
var react_exports = {};
__export(react_exports, {
  default: () => react_default
});
var defaultImport2 = __toESM(require("react"));
__reExport(react_exports, require("react"));
var react_default = "default" in defaultImport2 ? defaultImport2.default : defaultImport2;

// esm-externals:styled-components
var styled_components_exports = {};
__export(styled_components_exports, {
  default: () => styled_components_default
});
var defaultImport3 = __toESM(require("styled-components"));
__reExport(styled_components_exports, require("styled-components"));
var styled_components_default = "default" in defaultImport3 ? defaultImport3.default : defaultImport3;

// esm-externals:@splunk/themes
var themes_exports = {};
__export(themes_exports, {
  default: () => themes_default
});
var defaultImport4 = __toESM(require("@splunk/themes"));
__reExport(themes_exports, require("@splunk/themes"));
var themes_default = "default" in defaultImport4 ? defaultImport4.default : defaultImport4;

// esm-externals:temporal-polyfill
var temporal_polyfill_exports = {};
__export(temporal_polyfill_exports, {
  default: () => temporal_polyfill_default
});
var defaultImport5 = __toESM(require("temporal-polyfill"));
__reExport(temporal_polyfill_exports, require("temporal-polyfill"));
var temporal_polyfill_default = "default" in defaultImport5 ? defaultImport5.default : defaultImport5;

// esm-externals:string-format-obj
var string_format_obj_exports = {};
__export(string_format_obj_exports, {
  default: () => string_format_obj_default
});
var defaultImport6 = __toESM(require("string-format-obj"));
__reExport(string_format_obj_exports, require("string-format-obj"));
var string_format_obj_default = "default" in defaultImport6 ? defaultImport6.default : defaultImport6;

// src/utilities/formatTimestamp.ts
var EPOCH_SECONDS_MAX_VALUE = Date.now() / 100;
var TWELVEHOUR = {
  AM: "AM",
  PM: "PM"
};
var datePartInput = {
  name: "date",
  valueFormatString: "{day} {month} {year}",
  labelFormatString: "{month} {day} {year}"
};
var dateCompactPartInput = {
  name: "date",
  valueFormatString: "{day} {month}",
  labelFormatString: "{month} {day}"
};
var dateVerbosePartInput = {
  name: "date",
  valueFormatString: "{weekday} {day} {month} {year}",
  labelFormatString: "{weekday} {month} {day} {year}"
};
var timePartInput = {
  name: "time",
  valueFormatString: "{hour}:{minute}{meridiem}",
  labelFormatString: "{hour} {minute}{meridiem}"
};
var timePrecisePartInput = {
  name: "time",
  valueFormatString: "{hour}:{minute}:{second}{meridiem}",
  labelFormatString: "{hour} {minute} and {second} seconds{meridiem}"
};
var timeExtraPrecisePartInput = {
  name: "time",
  valueFormatString: "{hour}:{minute}:{second}.{fractionalSecond}{meridiem}",
  labelFormatString: "{hour} {minute} and {second} point {fractionalSecond} seconds{meridiem}"
};
var timezonePartInput = {
  name: "timeZone",
  valueFormatString: "{timeZoneName}",
  labelFormatString: "{timeZoneName}"
};
var formatPartsMap = {
  date: [datePartInput],
  dateCompact: [dateCompactPartInput],
  dateVerbose: [dateVerbosePartInput],
  time: [timePartInput, timezonePartInput],
  timeCompact: [timePartInput],
  timePrecise: [timePrecisePartInput, timezonePartInput],
  timeExtraPrecise: [timeExtraPrecisePartInput, timezonePartInput],
  dateTime: [datePartInput, timePartInput, timezonePartInput],
  dateTimeNoTimezone: [datePartInput, timePartInput],
  dateCompactTime: [dateCompactPartInput, timePartInput, timezonePartInput],
  dateTimeCompact: [datePartInput, timePartInput],
  dateCompactTimeCompact: [dateCompactPartInput, timePartInput],
  dateTimePrecise: [datePartInput, timePrecisePartInput, timezonePartInput],
  dateTimePreciseNoTimezone: [datePartInput, timePrecisePartInput],
  dateTimeExtraPrecise: [datePartInput, timeExtraPrecisePartInput, timezonePartInput],
  dateVerboseTime: [dateVerbosePartInput, timePartInput, timezonePartInput],
  dateVerboseTimePrecise: [dateVerbosePartInput, timePrecisePartInput, timezonePartInput],
  dateVerboseTimeExtraPrecise: [dateVerbosePartInput, timeExtraPrecisePartInput, timezonePartInput],
  isoDate: [
    {
      name: "date",
      valueFormatString: "{year}-{monthNumeric}-{dayPadded}",
      labelFormatString: ""
    }
  ],
  isoTime: [
    {
      name: "time",
      valueFormatString: "{hourPadded}:{minute}:{second}",
      labelFormatString: ""
    }
  ],
  isoLocal: [
    {
      name: "dateTime",
      valueFormatString: "{year}-{monthNumeric}-{dayPadded}T{hourPadded}:{minute}:{second}.{fractionalSecond}",
      labelFormatString: ""
    }
  ],
  isoWithOffset: [
    {
      name: "dateTime",
      valueFormatString: "{year}-{monthNumeric}-{dayPadded}T{hourPadded}:{minute}:{second}.{fractionalSecond}{timeZoneOffset}",
      labelFormatString: ""
    }
  ]
};
var zdtToValueObject = (zdt, twelveHourTimeFormat) => {
  const fmt = new Intl.DateTimeFormat("en-US", {
    hour: "numeric",
    minute: "2-digit",
    second: "2-digit",
    fractionalSecondDigits: 3,
    year: "numeric",
    month: "short",
    day: "numeric",
    weekday: "short",
    timeZone: zdt.timeZone.toString(),
    hourCycle: "h23"
  });
  const timeZoneName = (0, lodash_exports.last)(
    Intl.DateTimeFormat(void 0, {
      timeZoneName: "short",
      timeZone: zdt.timeZone.toString()
    }).format(zdt.epochMilliseconds).split(" ")
  ) || "";
  const parts = fmt.formatToParts(zdt.epochMilliseconds);
  const obj = Object.fromEntries(parts.map((part) => [part.type, part.value]));
  const hour = twelveHourTimeFormat ? String(zdt.hour % 12 || 12) : obj.hour;
  const twelveFormatMeridiem = ` ${zdt.hour >= 12 ? TWELVEHOUR.PM : TWELVEHOUR.AM}`;
  return __spreadProps(__spreadValues({}, obj), {
    timeZoneName,
    hour,
    hourPadded: obj.hour,
    dayPadded: parseInt(obj.day, 10) > 9 ? obj.day : `0${obj.day}`,
    monthNumeric: zdt.month > 9 ? String(zdt.month) : `0${zdt.month}`,
    meridiem: twelveHourTimeFormat ? twelveFormatMeridiem : "",
    timeZoneOffset: zdt.offset
  });
};
var formatTimestamp = (ts, formatName, localeInfo) => {
  const tsAsMillis = Math.abs(ts) <= EPOCH_SECONDS_MAX_VALUE ? ts * 1e3 : ts;
  const tsAsInstant = temporal_polyfill_exports.Temporal.Instant.fromEpochMilliseconds(tsAsMillis);
  const tsAsZdt = tsAsInstant.toZonedDateTimeISO(localeInfo.tz);
  const formatString = formatPartsMap[formatName].map((part) => part.valueFormatString).join(" ");
  const obj = zdtToValueObject(tsAsZdt, localeInfo.twelveHourTimeFormat);
  return string_format_obj_default(formatString, obj);
};

// src/utilities/scaleTime.ts
var timeScaleMap = {
  ["w" /* Weeks */]: { unit: "w", scaleUp: null, scaleUpValue: null, decimalPlaces: 0 },
  ["d" /* Days */]: {
    unit: "d",
    scaleUp: "w" /* Weeks */,
    scaleUpValue: 7,
    decimalPlaces: 0
  },
  ["h" /* Hours */]: { unit: "h", scaleUp: "d" /* Days */, scaleUpValue: 24, decimalPlaces: 1 },
  ["m" /* Minutes */]: {
    unit: "m",
    scaleUp: "h" /* Hours */,
    scaleUpValue: 60,
    decimalPlaces: 1
  },
  ["s" /* Seconds */]: {
    unit: "s",
    scaleUp: "m" /* Minutes */,
    scaleUpValue: 60,
    decimalPlaces: 2
  },
  ["ms" /* Milliseconds */]: {
    unit: "ms",
    scaleUp: "s" /* Seconds */,
    scaleUpValue: 1e3,
    decimalPlaces: 0
  },
  ["us" /* Microseconds */]: {
    unit: `${String.fromCharCode(181)}s`,
    scaleUp: "ms" /* Milliseconds */,
    scaleUpValue: 1e3,
    decimalPlaces: 0
  },
  ["ns" /* Nanoseconds */]: {
    unit: "ns",
    scaleUp: "us" /* Microseconds */,
    scaleUpValue: 1e3,
    decimalPlaces: 0
  }
};
function scaleTime(time, startingScale = "us" /* Microseconds */, decimalPlaces) {
  if (!time || time === 0) {
    return {
      scale: timeScaleMap["ms" /* Milliseconds */].unit,
      value: 0
    };
  }
  let iScale = timeScaleMap[startingScale];
  let timeValue = time;
  let sign = 1;
  if (time < 0) {
    sign = -1;
    timeValue = Math.abs(time);
  }
  while (iScale.scaleUpValue !== null && timeValue >= iScale.scaleUpValue && iScale.scaleUp) {
    timeValue /= iScale.scaleUpValue;
    iScale = timeScaleMap[iScale.scaleUp];
  }
  timeValue *= sign;
  return {
    scale: iScale.unit,
    value: timeValue.toFixed(typeof decimalPlaces !== "undefined" ? decimalPlaces : iScale.decimalPlaces)
  };
}

// src/utilities/formatDuration.ts
var formatDurationMicros = (tickValue, decimalPlaces) => {
  const { value, scale } = scaleTime(tickValue, "us" /* Microseconds */, decimalPlaces || void 0);
  return parseFloat(value.toString()).toString() + scale;
};

// src/utilities/def.ts
var def = (value) => value !== void 0 && value !== null;

// src/utilities/shortenNumber.ts
var generateShortenNumberComponents = (num, decimalPlaces) => {
  let str;
  let suffix = "";
  let value;
  if (num === 0 || !num) {
    value = 0;
    return { value, str: "0", suffix };
  }
  if (typeof decimalPlaces === "undefined") {
    decimalPlaces = num < 10 ? 2 : 1;
  }
  num = +num.toFixed(decimalPlaces);
  const factor = __pow(10, decimalPlaces);
  if (num === 0) {
    if (decimalPlaces === 0) {
      str = "<1";
    } else {
      str = `<0.${"0".repeat(decimalPlaces - 1)}1`;
    }
  } else if (num < 1e3) {
    value = num;
    str = value;
  } else if (num < 1e6) {
    value = Math.floor(num / (1e3 / factor)) / factor;
    str = value;
    suffix = "k";
  } else if (num < 1e9) {
    value = Math.floor(num / (1e6 / factor)) / factor;
    str = value;
    suffix = "m";
  } else if (num < 1e12) {
    value = Math.floor(num / (1e9 / factor)) / factor;
    str = value;
    suffix = "b";
  } else if (num < 1e15) {
    value = Math.floor(num / (1e12 / factor)) / factor;
    str = value;
    suffix = "t";
  }
  return { value, str: String(str), suffix };
};
function shortenNumber(num, decimalPlaces) {
  const { str, suffix } = generateShortenNumberComponents(num, decimalPlaces);
  return str + suffix;
}

// src/utilities/shortenByte.ts
function shortenByte(num, decimalPlaces = 1) {
  let str;
  let suffix = "";
  if (!num) {
    return "0B";
  }
  decimalPlaces = decimalPlaces || 0;
  num = +num.toFixed(decimalPlaces);
  const factor = __pow(10, decimalPlaces);
  if (num < 1e3) {
    str = num;
    suffix = "B";
  } else if (num < 1e6) {
    str = Math.floor(num / (1e3 / factor)) / factor;
    suffix = "KB";
  } else if (num < 1e9) {
    str = Math.floor(num / (1e6 / factor)) / factor;
    suffix = "MB";
  } else if (num < 1e12) {
    str = Math.floor(num / (1e9 / factor)) / factor;
    suffix = "GB";
  } else if (num < 1e15) {
    str = Math.floor(num / (1e12 / factor)) / factor;
    suffix = "TB";
  } else if (num < 1e18) {
    str = Math.floor(num / (1e15 / factor)) / factor;
    suffix = "PB";
  }
  return str + suffix;
}

// src/constants.ts
var Alert = "alert";
var Event = "event";
var InfoSeverity = "info";
var WarningSeverity = "warning";
var CriticalSeverity = "critical";
var MajorSeverity = "major";
var MinorSeverity = "minor";
var DefaultAnnotationLabels = {
  info: "Info alert",
  warning: "Warning alert",
  minor: "Minor alert",
  major: "Major alert",
  critical: "Critical alert",
  event: "Event"
};

// esm-externals:@splunk/react-icons/ArrowTriangleDown
var ArrowTriangleDown_exports = {};
__export(ArrowTriangleDown_exports, {
  default: () => ArrowTriangleDown_default
});
var defaultImport7 = __toESM(require("@splunk/react-icons/ArrowTriangleDown"));
__reExport(ArrowTriangleDown_exports, require("@splunk/react-icons/ArrowTriangleDown"));
var ArrowTriangleDown_default = "default" in defaultImport7 ? defaultImport7.default : defaultImport7;

// esm-externals:@splunk/react-icons/Circle
var Circle_exports = {};
__export(Circle_exports, {
  default: () => Circle_default
});
var defaultImport8 = __toESM(require("@splunk/react-icons/Circle"));
__reExport(Circle_exports, require("@splunk/react-icons/Circle"));
var Circle_default = "default" in defaultImport8 ? defaultImport8.default : defaultImport8;

// esm-externals:@splunk/react-icons/Diamond
var Diamond_exports = {};
__export(Diamond_exports, {
  default: () => Diamond_default
});
var defaultImport9 = __toESM(require("@splunk/react-icons/Diamond"));
__reExport(Diamond_exports, require("@splunk/react-icons/Diamond"));
var Diamond_default = "default" in defaultImport9 ? defaultImport9.default : defaultImport9;

// esm-externals:@splunk/react-icons/Triangle
var Triangle_exports = {};
__export(Triangle_exports, {
  default: () => Triangle_default
});
var defaultImport10 = __toESM(require("@splunk/react-icons/Triangle"));
__reExport(Triangle_exports, require("@splunk/react-icons/Triangle"));
var Triangle_default = "default" in defaultImport10 ? defaultImport10.default : defaultImport10;

// esm-externals:@splunk/react-icons/TrianglesLayeredDouble
var TrianglesLayeredDouble_exports = {};
__export(TrianglesLayeredDouble_exports, {
  default: () => TrianglesLayeredDouble_default
});
var defaultImport11 = __toESM(require("@splunk/react-icons/TrianglesLayeredDouble"));
__reExport(TrianglesLayeredDouble_exports, require("@splunk/react-icons/TrianglesLayeredDouble"));
var TrianglesLayeredDouble_default = "default" in defaultImport11 ? defaultImport11.default : defaultImport11;

// src/icons/AlertIcon.tsx
var AlertIcon = (props) => {
  switch (props.severity) {
    case WarningSeverity:
      return /* @__PURE__ */ react_default.createElement(
        Diamond_default,
        {
          width: `${props.dimensions.width}px`,
          height: `${props.dimensions.width}px`,
          viewBox: "0 0 24 24",
          style: { color: props.theme.annotationIcon.alertIconColor.warning },
          variant: `${props.isCleared ? "outlined" : "filled"}`
        }
      );
    case InfoSeverity:
      return /* @__PURE__ */ react_default.createElement(
        Circle_default,
        {
          width: `${props.dimensions.width}px`,
          height: `${props.dimensions.width}px`,
          viewBox: "0 0 24 24",
          style: { color: props.theme.annotationIcon.alertIconColor.info },
          variant: `${props.isCleared ? "outlined" : "filled"}`
        }
      );
    case MinorSeverity:
      return /* @__PURE__ */ react_default.createElement(
        ArrowTriangleDown_default,
        {
          width: `${props.dimensions.width}px`,
          height: `${props.dimensions.width}px`,
          viewBox: "0 0 24 24",
          style: { color: props.theme.annotationIcon.alertIconColor.minor },
          variant: `${props.isCleared ? "outlined" : "filled"}`
        }
      );
    case MajorSeverity:
      return /* @__PURE__ */ react_default.createElement(
        Triangle_default,
        {
          width: `${props.dimensions.width}px`,
          height: `${props.dimensions.width}px`,
          viewBox: "0 0 24 24",
          style: { color: props.theme.annotationIcon.alertIconColor.major },
          variant: `${props.isCleared ? "outlined" : "filled"}`
        }
      );
    case CriticalSeverity:
    default:
      return /* @__PURE__ */ react_default.createElement(
        TrianglesLayeredDouble_default,
        {
          width: `${props.dimensions.width}px`,
          height: `${props.dimensions.width}px`,
          viewBox: "0 0 24 24",
          style: { color: props.theme.annotationIcon.alertIconColor.critical },
          variant: `${props.isCleared ? "outlined" : "filled"}`
        }
      );
  }
};

// esm-externals:@splunk/react-icons/CheckBox
var CheckBox_exports = {};
__export(CheckBox_exports, {
  default: () => CheckBox_default
});
var defaultImport12 = __toESM(require("@splunk/react-icons/CheckBox"));
__reExport(CheckBox_exports, require("@splunk/react-icons/CheckBox"));
var CheckBox_default = "default" in defaultImport12 ? defaultImport12.default : defaultImport12;

// src/icons/CustomEventIcon.tsx
var CustomEventIcon = (props) => /* @__PURE__ */ react_default.createElement(
  CheckBox_default,
  {
    width: `${props.dimensions.width}px`,
    height: `${props.dimensions.width}px`,
    viewBox: "0 0 24 24",
    style: { color: props.theme.annotationIcon.customEventIconColor },
    variant: `${props.isCleared ? "outlined" : "filled"}`
  }
);

// src/theme.tsx
var lightVizTheme = {
  name: "light",
  color: "#2C2C2C",
  font: "10px Arial",
  labelFont: "12px Arial",
  axis: {
    axisStroke: "#E6E6E6",
    gridStroke: "#DDDDDD",
    xLabelStroke: "#6B6B6B",
    yLabelStroke: "#4D4D4D"
  },
  tooltip: {
    lineStroke: "rgba(44, 44, 44, 0.85)",
    inactiveLineStroke: "#999",
    backgroundColor: "rgba(44, 44, 44, 0.85)",
    color: "white",
    secondaryColor: "#999"
  },
  pin: {
    iconStroke: "white",
    lineStroke: "#9e9e9e",
    dotFill: "#9e9e9e"
  },
  heatmap: {
    axisStroke: "#2c2c2c",
    axisFontSize: 12,
    colorScheme: [
      "#ffffff",
      "#ccd6d7",
      "#aec8cd",
      "#8fb8c7",
      "#6ea8c1",
      "#4b96bd",
      "#2181bb",
      "#0067ba",
      "#0047bd",
      "#0502ca"
    ]
  },
  annotationIcon: {
    customEventIconColor: "#818285",
    alertIconColor: {
      critical: "#E00000",
      major: "#C97705",
      minor: "#155A4E",
      warning: "#006BE5",
      info: "#7B4DF5"
    }
  }
};
var darkVizTheme = {
  name: "dark",
  color: "#FAFAFA",
  font: "10px Arial",
  labelFont: "12px Arial",
  axis: {
    axisStroke: "#43454B",
    gridStroke: "#43454B",
    xLabelStroke: "#909090",
    yLabelStroke: "#B5B5B5"
  },
  tooltip: {
    lineStroke: "white",
    inactiveLineStroke: "#666",
    backgroundColor: "rgba(64, 64, 64, 0.85)",
    color: "white",
    secondaryColor: "#999"
  },
  pin: {
    iconStroke: "white",
    lineStroke: "white",
    dotFill: "#bdbdbd"
  },
  heatmap: {
    axisStroke: "#fafafa",
    axisFontSize: 12,
    colorScheme: [
      "#000000",
      "#15355a",
      "#315272",
      "#496d89",
      "#60869e",
      "#759db3",
      "#89b4c7",
      "#9ccad9",
      "#afdfec",
      "#c2f5ff"
    ]
  },
  annotationIcon: {
    customEventIconColor: "#818285",
    alertIconColor: {
      critical: "#FF4242",
      major: "#F49106",
      minor: "#2CBDA3",
      warning: "#61CAFA",
      info: "#AB74F1"
    }
  }
};
function getVizThemeForKey(key) {
  switch (key) {
    case "dark": {
      return darkVizTheme;
    }
    case "light":
    default: {
      return lightVizTheme;
    }
  }
}
function useVizTheme() {
  const { colorScheme } = (0, themes_exports.useSplunkTheme)();
  return getVizThemeForKey(colorScheme);
}

// src/EventAnnotations.tsx
var EVENT_ANNOTATION_DIMENSIONS = {
  width: 12,
  height: 12
};
var getEventAnnotationRenderer = (eventAnnotationConfig) => {
  const defaultAnnotationRenderer = ({
    event,
    theme,
    dimensions
  }) => {
    switch (event.type) {
      case Alert:
        return /* @__PURE__ */ react_default.createElement(
          AlertIcon,
          {
            theme,
            dimensions,
            severity: event.severity,
            isCleared: event.isCleared
          }
        );
      case Event:
      default:
        return /* @__PURE__ */ react_default.createElement(CustomEventIcon, { theme, dimensions, isCleared: event.isCleared });
    }
  };
  return (eventAnnotationConfig == null ? void 0 : eventAnnotationConfig.renderer) || defaultAnnotationRenderer;
};

// src/AnnotationTooltip.tsx
var StyledAnnotationContainer = styled_components_default.div`
    display: flex;
    flex-direction: row;
    align-items: center;
`;
var StyledAnnotationIconContainer = styled_components_default.div`
    margin-right: 10px;
    display: flex;
    align-items: center;
`;
var StyledAnnotationSeverityContainer = styled_components_default.div`
    color: ${(props) => props.theme.tooltip.color};
    margin-right: 10px;
    display: flex;
    align-items: center;
`;
var StyledAnnotationTriggeredContainer = styled_components_default.div`
    color: ${(props) => props.theme.tooltip.color};
`;
var StyledAnnotationTimeContainer = styled_components_default.div`
    color: #ccc;
    font-size: 12px;
    margin-bottom: 1;
`;
var StyledAnnotationDetailsContainer = styled_components_default.div`
    color: #ccc;
    font-size: 12px;
    margin-bottom: 1;
`;
var StyledAnnotationTooltip = styled_components_default.div`
    border-radius: 5px;
    background-color: ${(props) => props.theme.tooltip.backgroundColor};
    color: ${(props) => props.theme.tooltip.color};
    margin: 0 5px;
    padding: 5px 10px;
    font-size: 14px;
    text-align: left;
`;
var CLICK_ANNOTATION_DETAILS_LABEL = "Click on annotation for details";
var BasicEventAnnotationTooltip = (props) => {
  var _a;
  const theme = useVizTheme();
  const locale = props == null ? void 0 : props.userLocale;
  let formattedDate = null;
  if (props.eventAnnotationCursorState.time) {
    formattedDate = formatTimestamp(
      props.eventAnnotationCursorState.time * 1e3,
      "dateVerboseTimePrecise",
      locale
    );
  }
  const onClickAnnotationEnabled = def((_a = props.eventAnnotationConfig) == null ? void 0 : _a.onEventAnnotationClick);
  const annotationRenderer = getEventAnnotationRenderer(props.eventAnnotationConfig);
  const getAnnotationInfoRow = (eventAnnotationCursorState) => {
    if (eventAnnotationCursorState.type === Alert) {
      return /* @__PURE__ */ react_default.createElement(react_default.Fragment, null, /* @__PURE__ */ react_default.createElement(StyledAnnotationSeverityContainer, { theme }, DefaultAnnotationLabels[eventAnnotationCursorState.severity || CriticalSeverity]), /* @__PURE__ */ react_default.createElement(StyledAnnotationIconContainer, null, annotationRenderer({
        event: eventAnnotationCursorState,
        theme,
        dimensions: EVENT_ANNOTATION_DIMENSIONS
      })), /* @__PURE__ */ react_default.createElement(StyledAnnotationTriggeredContainer, { theme }, "1 triggered"));
    }
    return /* @__PURE__ */ react_default.createElement(StyledAnnotationTriggeredContainer, { theme }, eventAnnotationCursorState.key);
  };
  return /* @__PURE__ */ react_default.createElement(StyledAnnotationTooltip, { theme }, formattedDate && /* @__PURE__ */ react_default.createElement(StyledAnnotationTimeContainer, null, formattedDate), /* @__PURE__ */ react_default.createElement(StyledAnnotationContainer, null, getAnnotationInfoRow(props.eventAnnotationCursorState)), onClickAnnotationEnabled && /* @__PURE__ */ react_default.createElement(StyledAnnotationDetailsContainer, null, CLICK_ANNOTATION_DETAILS_LABEL));
};

// esm-externals:lodash/some
var some_exports = {};
__export(some_exports, {
  default: () => some_default
});
var defaultImport13 = __toESM(require("lodash/some"));
__reExport(some_exports, require("lodash/some"));
var some_default = "default" in defaultImport13 ? defaultImport13.default : defaultImport13;

// esm-externals:uplot
var uplot_exports = {};
__export(uplot_exports, {
  default: () => uplot_default
});
var defaultImport14 = __toESM(require("uplot"));
__reExport(uplot_exports, require("uplot"));
var uplot_default = "default" in defaultImport14 ? defaultImport14.default : defaultImport14;

// src/renderers/uplot-utils.ts
var { bars } = uplot_default.paths;
var bars90PercentGap100MaxWidthPaths = bars ? bars({ size: [0.9, 100] }) : void 0;

// src/utilities/utils.ts
var SECOND_TO_MICROSECOND = 1e6;
var DAY = 24 * 60 * 60;
function exists(value) {
  return value !== void 0 && value !== null;
}
function getMergedSeriesConfigForField(seriesConfigMap = {}, scaleConfigMap = {}, field) {
  const defaults = { scale: "y" };
  if (!exists(field)) {
    return defaults;
  }
  const seriesConfig = seriesConfigMap[field];
  const scale = (seriesConfig == null ? void 0 : seriesConfig.scale) || "y";
  const scaleConfig = scaleConfigMap[scale] || {};
  const mergedSeriesConfig = __spreadValues(__spreadValues(__spreadValues({}, defaults), scaleConfig.seriesConfig), seriesConfig);
  return mergedSeriesConfig;
}
var formatKibBytes = (bytes, decimals = 2) => {
  if (!+bytes) {
    return "0B";
  }
  const k = 1024;
  const dm = decimals < 0 ? 0 : decimals;
  const sizes = ["B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB"];
  const i = Math.floor(Math.log(bytes) / Math.log(k));
  return `${parseFloat((bytes / __pow(k, i)).toFixed(dm))}${sizes[i]}`;
};
var namedFormatters = {
  durationMicros: (value) => formatDurationMicros(value),
  rate: (value, xAxisResolution) => `${shortenNumber(value / (xAxisResolution || 1))} /s`,
  count: (value) => `${shortenNumber(value)}`,
  bytes: (value) => `${shortenByte(value)}`,
  percentage: (value) => `${shortenNumber(value)}%`,
  kibBytes: (value) => `${formatKibBytes(value, 0)}`
};
var scaleNamedFormatters = __spreadProps(__spreadValues({}, namedFormatters), {
  percentage: (value) => `${shortenNumber(value, value < 10 ? 3 : 2)}%`
});
var getXAxisResolution = (data) => {
  if ((0, lodash_exports.isEmpty)(data.columns)) {
    return 0;
  }
  const timeSeries = data.columns[0];
  const firstNonNullIndex = timeSeries.findIndex((val, i) => val !== null && timeSeries[i + 1] !== null);
  if (firstNonNullIndex === -1) {
    return 0;
  }
  return timeSeries[firstNonNullIndex + 1] - timeSeries[firstNonNullIndex];
};
var formatValueWithSeriesConfig = (value, seriesConfig, data) => {
  const formatter = seriesConfig.valueFmt;
  if (!formatter) {
    return String(value);
  }
  const formatFn = typeof formatter === "string" ? namedFormatters[formatter] : formatter;
  const xAxisResolution = getXAxisResolution(data);
  return formatFn(value, xAxisResolution);
};

// src/Tooltips.tsx
var StyledPointValue = styled_components_default.div`
    display: flex;
    flex-direction: row;
`;
var StyledSeriesIcon = styled_components_default.div`
    margin-top: 7px;
    margin-right: 8px;
    width: 7px;
    height: 7px;
    border-radius: 5px;
    background-color: ${(props) => {
  var _a, _b;
  return ((_a = props.series.fill) == null ? void 0 : _a.toString()) || ((_b = props.series.stroke) == null ? void 0 : _b.toString()) || "transparent";
}};
`;
var StyledResolution = styled_components_default.div`
    color: #999999;
    margin-left: 8px;
`;
var StyledSeriesLabel = styled_components_default.div`
    margin-top: 7px;
    color: white;
`;
var StyledWrapper = styled_components_default.div`
    display: flex;
    align-items: center;
    gap: ${themes_exports.variables.spacingXSmall};
    align-self: stretch;
`;
var StyledFormattedDate = styled_components_default.div`
    color: ${themes_exports.variables.contentColorDefault};
    font-size: 10px;
    font-style: normal;
    line-height: ${themes_exports.variables.spacingLarge};
`;
var StyledFormattedValue = styled_components_default.div`
    color: ${themes_exports.variables.contentColorActive};
    font-size: 10px;
    font-style: normal;
    font-weight: ${themes_exports.variables.fontWeightBold};
    line-height: ${themes_exports.variables.spacingLarge};
    flex: 1 0 0;
`;
var getFormattedDate = (cursorState, data, locale) => {
  var _a;
  let formattedDate = null;
  if (cursorState.cursor) {
    const time = data.columns[0][(_a = cursorState.cursor) == null ? void 0 : _a.index];
    if (time) {
      formattedDate = formatTimestamp(time * 1e3, "dateVerboseTimePrecise", locale);
    }
  }
  return formattedDate;
};
var getFormattedValue = (plotUtilities, cursorState, data, seriesConfig, scaleConfig, seriesIndex) => {
  var _a;
  const selectedSeries = plotUtilities.allSeries[seriesIndex];
  let formattedValue = "-";
  if (cursorState.cursor) {
    const v = data.columns[seriesIndex][(_a = cursorState.cursor) == null ? void 0 : _a.index];
    const config = getMergedSeriesConfigForField(seriesConfig, scaleConfig, selectedSeries.field);
    if (v !== null) {
      formattedValue = formatValueWithSeriesConfig(v, config, data);
    }
  }
  return formattedValue;
};
var hasCursorState = (cursorState, lowerBound, upperBound) => cursorState != null && cursorState.state !== "off" && cursorState.cursor != null && cursorState.cursor.left >= lowerBound && cursorState.cursor.left <= upperBound && cursorState.seriesIndex != null;
var BasicMultiValueTooltip = (props) => {
  var _a;
  const {
    plotUtilities,
    seriesConfig,
    scaleConfig,
    data,
    cursorState,
    userLocale,
    isTimeSeries,
    rawXaxisValues,
    tooltipLabelComponent
  } = props;
  const theme = useVizTheme();
  const cursorIndex = (_a = cursorState.cursor) == null ? void 0 : _a.index;
  const rawFormattedData = rawXaxisValues && rawXaxisValues[cursorIndex] ? rawXaxisValues[cursorIndex] : "";
  const formattedData = isTimeSeries ? getFormattedDate(cursorState, data, userLocale) : rawFormattedData;
  let { precomponent } = props;
  if ((0, lodash_exports.isFunction)(precomponent)) {
    precomponent = precomponent(props);
  }
  return /* @__PURE__ */ react_default.createElement(
    "div",
    {
      style: {
        borderRadius: 5,
        backgroundColor: theme.tooltip.backgroundColor,
        color: theme.tooltip.color,
        margin: "0 5px",
        padding: "5px 10px",
        fontSize: "14px",
        textAlign: "left"
      }
    },
    tooltipLabelComponent && /* @__PURE__ */ react_default.createElement("div", null, tooltipLabelComponent),
    formattedData && /* @__PURE__ */ react_default.createElement(
      "div",
      {
        style: {
          color: "#ccc",
          fontSize: "12px",
          marginBottom: 1
        }
      },
      formattedData
    ),
    precomponent && /* @__PURE__ */ react_default.createElement("div", null, precomponent),
    plotUtilities.allSeries.slice(1).map((s, i) => {
      var _a2, _b;
      const formattedValue = getFormattedValue(
        plotUtilities,
        cursorState,
        data,
        seriesConfig,
        scaleConfig,
        i + 1
      );
      return /* @__PURE__ */ react_default.createElement(
        "div",
        {
          key: s.label,
          style: {
            display: "flex",
            flexDirection: "row",
            fontWeight: i + 1 === cursorState.seriesIndex ? "bolder" : void 0
          }
        },
        /* @__PURE__ */ react_default.createElement(
          "div",
          {
            style: {
              marginTop: 8,
              marginRight: 8,
              width: 7,
              height: 7,
              borderRadius: 5,
              backgroundColor: ((_a2 = s.fill) == null ? void 0 : _a2.toString()) || ((_b = s.stroke) == null ? void 0 : _b.toString()) || "transparent"
            }
          }
        ),
        /* @__PURE__ */ react_default.createElement("div", null, s.label, ": ", formattedValue)
      );
    })
  );
};
var BasicMultiValueTooltipFactory = ({ precomponent: label, tooltipLabelComponent }) => {
  const component = (componentProps) => /* @__PURE__ */ react_default.createElement(
    BasicMultiValueTooltip,
    __spreadProps(__spreadValues({}, componentProps), {
      precomponent: label,
      tooltipLabelComponent
    })
  );
  return component;
};
var BasicSingleValueTooltip = (props) => {
  var _a;
  const {
    plotUtilities,
    seriesConfig,
    scaleConfig,
    data,
    cursorState,
    chartTitle,
    xAxisResolution,
    userLocale,
    hideTooltipSeriesLabel,
    isTimeSeries,
    rawXaxisValues,
    tooltipLabelComponent
  } = props;
  const resolutionInSeconds = xAxisResolution || getXAxisResolution(props.data);
  const resolutionText = formatDurationMicros(resolutionInSeconds * SECOND_TO_MICROSECOND);
  const theme = useVizTheme();
  if (cursorState.state === "off" || cursorState.seriesIndex === null) {
    return null;
  }
  const selectedSeries = plotUtilities.allSeries[cursorState.seriesIndex];
  const showTooltipSeriesLabel = chartTitle !== selectedSeries.label && !hideTooltipSeriesLabel;
  const cursorIndex = (_a = cursorState.cursor) == null ? void 0 : _a.index;
  const rawFormattedData = rawXaxisValues && rawXaxisValues[cursorIndex] ? rawXaxisValues[cursorIndex] : "";
  const formattedData = isTimeSeries ? getFormattedDate(cursorState, data, userLocale) : rawFormattedData;
  const formattedValue = getFormattedValue(
    plotUtilities,
    cursorState,
    data,
    seriesConfig,
    scaleConfig,
    cursorState.seriesIndex
  );
  let { precomponent } = props;
  if ((0, lodash_exports.isFunction)(precomponent)) {
    precomponent = precomponent(props);
  }
  return /* @__PURE__ */ react_default.createElement(
    "div",
    {
      style: {
        borderRadius: 5,
        backgroundColor: theme.tooltip.backgroundColor,
        color: theme.tooltip.color,
        margin: "0 5px",
        padding: "5px 10px",
        fontSize: "14px",
        textAlign: "left"
      }
    },
    tooltipLabelComponent && /* @__PURE__ */ react_default.createElement("div", null, tooltipLabelComponent),
    formattedData && /* @__PURE__ */ react_default.createElement(
      "div",
      {
        style: {
          color: "#ccc",
          fontSize: "12px",
          marginBottom: 1
        }
      },
      formattedData
    ),
    precomponent && /* @__PURE__ */ react_default.createElement("div", null, precomponent),
    /* @__PURE__ */ react_default.createElement("div", { key: selectedSeries.label }, /* @__PURE__ */ react_default.createElement(StyledSeriesLabel, null, showTooltipSeriesLabel && /* @__PURE__ */ react_default.createElement("div", null, chartTitle), /* @__PURE__ */ react_default.createElement("div", { "data-test": "timeseries-tooltip-label" }, selectedSeries.label)), /* @__PURE__ */ react_default.createElement(StyledPointValue, null, /* @__PURE__ */ react_default.createElement(StyledSeriesIcon, { series: selectedSeries }), /* @__PURE__ */ react_default.createElement("div", { "data-test": "timeseries-tooltip-value" }, formattedValue), isTimeSeries && /* @__PURE__ */ react_default.createElement(StyledResolution, { "data-test": "timeseries-tooltip-resolution" }, "resolution ", resolutionText)))
  );
};
var TooltipOutsideChart = ({
  plotUtilities,
  seriesConfig = {},
  scaleConfig = {},
  data,
  cursorState,
  userLocale,
  eventAnnotationCursorState,
  isTimeSeries = true,
  rawXaxisValues
}) => {
  var _a, _b;
  if (plotUtilities === void 0 || data === void 0 || !hasCursorState(cursorState, 0, plotUtilities.dimensions.over.width) && !eventAnnotationCursorState) {
    return null;
  }
  let formattedData = null;
  let formattedValue = "-";
  if (eventAnnotationCursorState) {
    formattedData = `${formatTimestamp(
      eventAnnotationCursorState.time * 1e3,
      "dateVerboseTimePrecise",
      userLocale
    )}:`;
    formattedValue = eventAnnotationCursorState.type === Alert ? DefaultAnnotationLabels[eventAnnotationCursorState.severity || CriticalSeverity] : eventAnnotationCursorState.key;
  } else if (cursorState && cursorState.seriesIndex) {
    const rawFormattedData = rawXaxisValues && rawXaxisValues[(_a = cursorState.cursor) == null ? void 0 : _a.index] ? rawXaxisValues[(_b = cursorState.cursor) == null ? void 0 : _b.index] : "";
    formattedData = isTimeSeries ? `${getFormattedDate(cursorState, data, userLocale)}:` : rawFormattedData;
    formattedValue = getFormattedValue(
      plotUtilities,
      cursorState,
      data,
      seriesConfig,
      scaleConfig,
      cursorState.seriesIndex
    );
  }
  return /* @__PURE__ */ react_default.createElement(StyledWrapper, null, formattedData && /* @__PURE__ */ react_default.createElement(StyledFormattedDate, { "data-test": "tooltip-data" }, formattedData), /* @__PURE__ */ react_default.createElement(StyledFormattedValue, { "data-test": "tooltip-value" }, formattedValue));
};
var BasicSingleValueTooltipFactory = ({ precomponent: label, tooltipLabelComponent }) => {
  const component = (componentProps) => /* @__PURE__ */ react_default.createElement(
    BasicSingleValueTooltip,
    __spreadProps(__spreadValues({}, componentProps), {
      precomponent: label,
      tooltipLabelComponent
    })
  );
  return component;
};
var InternalTooltipContainer = (props) => {
  const { direction, left, plotWidth, active } = props;
  const theme = useVizTheme();
  return /* @__PURE__ */ react_default.createElement(react_default.Fragment, null, /* @__PURE__ */ react_default.createElement(
    "div",
    {
      className: "olly-viz-tooltip-line",
      style: {
        position: "absolute",
        backgroundColor: active ? theme.tooltip.lineStroke : theme.tooltip.inactiveLineStroke,
        width: "1px",
        top: 0,
        bottom: 0,
        left: `${left - 0.5}px`
      }
    }
  ), active && /* @__PURE__ */ react_default.createElement(
    "div",
    {
      className: "olly-viz-tooltip-body",
      style: {
        position: "absolute",
        top: 0,
        left: direction === "right" ? `${left}px` : void 0,
        right: direction === "left" ? `${plotWidth - left}px` : void 0
      }
    },
    props.children
  ));
};
var DataSeriesTooltipContainer = (props) => {
  const {
    cursorState,
    data,
    plotUtilities,
    seriesConfig = {},
    scaleConfig = {},
    tooltip: tooltipBody = BasicSingleValueTooltip,
    chartTitle,
    xAxisResolution,
    userLocale,
    hideTooltipSeriesLabel,
    showTooltipOutsideChart = false,
    isTimeSeries = true,
    rawXaxisValues = []
  } = props;
  if (plotUtilities === void 0 || !cursorState || cursorState.state === "off" || cursorState.cursor === null || cursorState.cursor.left < 0 || cursorState.cursor.left > plotUtilities.dimensions.over.width || data === void 0) {
    return null;
  }
  const { width: plotWidth } = plotUtilities.dimensions.over;
  const { left } = cursorState.cursor;
  const direction = left < plotWidth / 2 ? "right" : "left";
  return /* @__PURE__ */ react_default.createElement(
    InternalTooltipContainer,
    {
      left,
      plotWidth,
      direction,
      active: cursorState.active && !showTooltipOutsideChart
    },
    react_default.createElement(tooltipBody, {
      data,
      plotUtilities,
      cursorState,
      direction,
      seriesConfig,
      scaleConfig,
      chartTitle,
      xAxisResolution,
      userLocale,
      hideTooltipSeriesLabel,
      isTimeSeries,
      rawXaxisValues
    })
  );
};
var EventAnnotationTooltipContainer = (props) => {
  const {
    plotUtilities,
    eventAnnotationCursorState,
    eventAnnotationConfig,
    eventAnnotationTooltip = BasicEventAnnotationTooltip,
    showTooltipOutsideChart = false,
    userLocale
  } = props;
  const theme = useVizTheme();
  if (!eventAnnotationCursorState || !plotUtilities) {
    return null;
  }
  const { width: plotWidth } = plotUtilities.dimensions.over;
  const left = plotUtilities.valToPos(eventAnnotationCursorState.time, "x");
  const direction = left < plotWidth / 2 ? "right" : "left";
  return /* @__PURE__ */ react_default.createElement(
    InternalTooltipContainer,
    {
      left,
      plotWidth,
      direction,
      active: !showTooltipOutsideChart
    },
    react_default.createElement(eventAnnotationTooltip, {
      eventAnnotationCursorState,
      eventAnnotationConfig,
      direction,
      theme,
      userLocale
    })
  );
};
var TooltipContainer = (props) => {
  const {
    plotUtilities,
    tooltip,
    cursorState,
    data,
    seriesConfig,
    scaleConfig,
    eventAnnotationCursorState,
    eventAnnotationConfig,
    eventAnnotationTooltip,
    chartTitle,
    xAxisResolution,
    userLocale,
    hideTooltipSeriesLabel,
    showTooltipOutsideChart = false,
    isTimeSeries = true,
    rawXaxisValues = []
  } = props;
  if (tooltip === false) {
    return null;
  }
  if (exists(eventAnnotationCursorState)) {
    return /* @__PURE__ */ react_default.createElement(
      EventAnnotationTooltipContainer,
      {
        plotUtilities,
        eventAnnotationCursorState,
        eventAnnotationConfig,
        eventAnnotationTooltip,
        showTooltipOutsideChart,
        userLocale
      }
    );
  }
  return /* @__PURE__ */ react_default.createElement(
    DataSeriesTooltipContainer,
    {
      cursorState,
      data,
      plotUtilities,
      tooltip,
      seriesConfig,
      scaleConfig,
      chartTitle,
      xAxisResolution,
      userLocale,
      hideTooltipSeriesLabel,
      showTooltipOutsideChart,
      isTimeSeries,
      rawXaxisValues
    }
  );
};
//# sourceMappingURL=Tooltips.js.map
