/* 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/RangeSelection.tsx
var RangeSelection_exports = {};
__export(RangeSelection_exports, {
  RangeSelection: () => RangeSelection
});
module.exports = __toCommonJS(RangeSelection_exports);

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

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

// esm-externals:@splunk/react-icons/SVG
var SVG_exports = {};
__export(SVG_exports, {
  default: () => SVG_default
});
var defaultImport3 = __toESM(require("@splunk/react-icons/SVG"));
__reExport(SVG_exports, require("@splunk/react-icons/SVG"));
var SVG_default = "default" in defaultImport3 ? defaultImport3.default : defaultImport3;

// src/icons/CloseIcon.tsx
var CloseIcon = () => /* @__PURE__ */ react_default.createElement(
  SVG_default,
  {
    width: "12",
    height: "12",
    viewBox: "0 0 20 20",
    xmlns: "http://www.w3.org/2000/svg",
    "aria-label": "Close icon",
    inline: true
  },
  /* @__PURE__ */ react_default.createElement(
    "polygon",
    {
      points: "10 8.58578644 2.92893219 1.51471863 1.51471863 2.92893219 8.58578644 10 1.51471863 17.0710678 2.92893219 18.4852814 10 11.4142136 17.0710678 18.4852814 18.4852814 17.0710678 11.4142136 10 18.4852814 2.92893219 17.0710678 1.51471863 10 8.58578644",
      style: { fill: "rgba(0, 0, 0, 0.4)" }
    }
  )
);

// src/icons/ZoomIcon.tsx
var ZoomIcon = () => /* @__PURE__ */ react_default.createElement(
  SVG_default,
  {
    width: "12",
    height: "12",
    viewBox: "0 0 20 20",
    xmlns: "http://www.w3.org/2000/svg",
    "aria-label": "Close icon",
    inline: true
  },
  /* @__PURE__ */ react_default.createElement(
    "path",
    {
      d: "M7,7 L5,7 L5,9 L7,9 L7,11 L9,11 L9,9 L11,9 L11,7 L9,7 L9,5 L7,5 L7,7 Z M12.9056439,14.3198574 C11.5509601,15.3729184 9.84871145,16 8,16 C3.581722,16 0,12.418278 0,8 C0,3.581722 3.581722,0 8,0 C12.418278,0 16,3.581722 16,8 C16,9.84871145 15.3729184,11.5509601 14.3198574,12.9056439 L19.6568542,18.2426407 L18.2426407,19.6568542 L12.9056439,14.3198574 Z M8,14 C11.3137085,14 14,11.3137085 14,8 C14,4.6862915 11.3137085,2 8,2 C4.6862915,2 2,4.6862915 2,8 C2,11.3137085 4.6862915,14 8,14 Z",
      style: { fill: "rgba(0,0,0,0.4)" }
    }
  )
);

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

// 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/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/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;
}

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

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

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

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

// src/utilities/formatTimestamp.ts
var EPOCH_SECONDS_MAX_VALUE = Date.now() / 100;

// 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 DAY = 24 * 60 * 60;
function exists(value) {
  return value !== void 0 && value !== null;
}
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)}%`
});

// src/RangeSelection.tsx
var StyledIconWrapper = styled_components_default.div`
    display: flex;
    justify-content: center;
    align-items: center;
    background: rgba(255, 255, 255, 0.7);
    margin: 3px 6px;
    cursor: pointer;
    padding: 4px;
`;
var RangeSelection = react_default.memo((props) => {
  var _a;
  if ((_a = props.cursorState) == null ? void 0 : _a.selection) {
    return /* @__PURE__ */ react_default.createElement(react_default.Fragment, null, /* @__PURE__ */ react_default.createElement(
      "div",
      {
        className: "olly-viz-select-box",
        style: {
          position: "absolute",
          border: "3px solid #ccc",
          top: 0,
          bottom: 0,
          left: Math.max(0, props.cursorState.selection.left),
          width: Math.max(0, props.cursorState.selection.width)
        }
      }
    ));
  }
  if (!exists(props.rangeSelection) || !exists(props.plotUtilities)) {
    return null;
  }
  const left = props.plotUtilities.valToPos(props.rangeSelection.start, "x");
  const right = props.plotUtilities.valToPos(props.rangeSelection.end, "x");
  const width = right - left;
  return /* @__PURE__ */ react_default.createElement(react_default.Fragment, null, /* @__PURE__ */ react_default.createElement(
    "div",
    {
      className: "olly-viz-select-left",
      style: {
        position: "absolute",
        background: `rgba(100,100,100,0.3)`,
        borderRight: "3px solid rgba(100,100,100,0.5)",
        top: 0,
        bottom: 0,
        left: 0,
        width: left
      }
    }
  ), /* @__PURE__ */ react_default.createElement(
    "div",
    {
      className: "olly-viz-select-right",
      style: {
        position: "absolute",
        background: `rgba(100,100,100,0.3)`,
        borderLeft: "3px solid rgba(100,100,100,0.5)",
        top: 0,
        bottom: 0,
        left: left + width,
        right: 0
      }
    }
  ), /* @__PURE__ */ react_default.createElement(
    "div",
    {
      className: "olly-viz-select-controls",
      style: {
        display: "flex",
        flexDirection: "column",
        position: "absolute",
        left: left + width,
        top: 0,
        pointerEvents: "auto"
      }
    },
    props.onRangeDeselection && /* @__PURE__ */ react_default.createElement(
      StyledIconWrapper,
      {
        className: "olly-viz-select-controls-close",
        onClick: (e) => {
          var _a2;
          (_a2 = props.onRangeDeselection) == null ? void 0 : _a2.call(props, e.nativeEvent);
        }
      },
      /* @__PURE__ */ react_default.createElement(CloseIcon, null)
    ),
    props.onRangeZoom && /* @__PURE__ */ react_default.createElement(
      StyledIconWrapper,
      {
        className: "olly-viz-select-controls-zoom",
        onClick: (e) => {
          var _a2;
          if (props.rangeSelection) {
            (_a2 = props.onRangeZoom) == null ? void 0 : _a2.call(props, props.rangeSelection, e.nativeEvent);
          }
        }
      },
      /* @__PURE__ */ react_default.createElement(ZoomIcon, null)
    )
  ));
});
//# sourceMappingURL=RangeSelection.js.map
