/* 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. */
import {
  exists,
  findClosest
} from "./chunk-6N4JNZ5S.js";
import {
  react_default,
  react_exports
} from "./chunk-V3S5WUKN.js";

// src/Pin.tsx
var Pin = ({ height, x, y, onPinHeadClick, isActive }) => {
  const onPinHeadClickInternal = () => {
    if (isActive && exists(onPinHeadClick)) {
      onPinHeadClick();
    }
  };
  const pinOuterRadius = 10;
  const pinInnerRadius = 7;
  const closeIconSize = 6;
  return /* @__PURE__ */ react_default.createElement("svg", { className: "pin", "data-test": "viz-pin" }, /* @__PURE__ */ react_default.createElement("g", { transform: `translate(${x}, ${y})` }, /* @__PURE__ */ react_default.createElement("line", { className: "pin-line", x1: 0, y1: 0, x2: 0, y2: height }), /* @__PURE__ */ react_default.createElement(
    "circle",
    {
      className: `pin-dot-inner ${isActive ? "" : "disabled"}`,
      r: pinInnerRadius,
      cx: 0,
      cy: 0,
      onClick: onPinHeadClickInternal
    }
  ), isActive && /* @__PURE__ */ react_default.createElement(react_default.Fragment, null, /* @__PURE__ */ react_default.createElement(
    "circle",
    {
      className: "pin-dot-outer",
      "data-test": "pin-dot-circle",
      r: pinOuterRadius,
      cx: 0,
      cy: 0,
      onClick: onPinHeadClickInternal
    }
  ), /* @__PURE__ */ react_default.createElement("g", { transform: `translate(-${closeIconSize / 2}, -${closeIconSize / 2})` }, /* @__PURE__ */ react_default.createElement(
    "line",
    {
      className: "pin-close-line",
      x1: 0,
      y1: 0,
      x2: closeIconSize,
      y2: closeIconSize
    }
  ), /* @__PURE__ */ react_default.createElement(
    "line",
    {
      className: "pin-close-line",
      x1: 0,
      y1: closeIconSize,
      x2: closeIconSize,
      y2: 0
    }
  )))));
};
var PinContainer = (props) => {
  const { plotUtilities, data, pinValue, onPinClose } = props;
  if (!pinValue || !plotUtilities) {
    return null;
  }
  const { height: overHeight } = plotUtilities.dimensions.over;
  const timeData = data.columns ? data.columns[0] : null;
  const xValue = pinValue.time;
  const closestXValue = timeData ? findClosest(timeData, xValue) : null;
  if (closestXValue === null || timeData && closestXValue < timeData[0] || timeData && closestXValue > timeData[timeData.length - 1]) {
    return null;
  }
  const pinX = plotUtilities.valToPos(closestXValue, "x");
  return /* @__PURE__ */ react_default.createElement(Pin, { x: pinX, y: 0, height: overHeight, onPinHeadClick: onPinClose, isActive: pinValue.isActive });
};

export {
  Pin,
  PinContainer
};
//# sourceMappingURL=chunk-SWCBFGHQ.js.map
