/* 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 __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
var __getProtoOf = Object.getPrototypeOf;
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 __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/components/MaybeFieldLink/index.tsx
var MaybeFieldLink_exports = {};
__export(MaybeFieldLink_exports, {
  MaybeFieldValueLink: () => MaybeFieldValueLink,
  MaybeTagsLink: () => MaybeTagsLink,
  maybeFieldLink: () => maybeFieldLink
});
module.exports = __toCommonJS(MaybeFieldLink_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:@splunk/react-ui/Link
var Link_exports = {};
__export(Link_exports, {
  default: () => Link_default
});
var defaultImport2 = __toESM(require("@splunk/react-ui/Link"));
__reExport(Link_exports, require("@splunk/react-ui/Link"));
var Link_default = "default" in defaultImport2 ? defaultImport2.default : defaultImport2;

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

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

// esm-externals:@splunk/ui-utils/id
var id_exports = {};
__export(id_exports, {
  default: () => id_default
});
var defaultImport5 = __toESM(require("@splunk/ui-utils/id"));
__reExport(id_exports, require("@splunk/ui-utils/id"));
var id_default = "default" in defaultImport5 ? defaultImport5.default : defaultImport5;

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

// src/utils/actions.ts
var INTERNAL_FIELDS_ARRAY = [
  "_bkt",
  "_cd",
  "_eventtype_color",
  "_fulllinecount",
  "_has_time",
  "_indextime",
  "_kv",
  "_mkv_child",
  "_raw",
  "_serial",
  "_si",
  "_sourcetype",
  "_span",
  "_subsecond"
];
var internalFields = new Set(INTERNAL_FIELDS_ARRAY);
var isTimeField = (field) => field === "_time";

// src/components/MaybeFieldLink/index.tsx
var FieldValueContainer = styled_components_default.div`
    display: inline;
    color: ${themes_exports.variables.contentColorActive};

    ${// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
({ $highlighted }) => $highlighted && styled_components_exports.css`
                background-color: ${(0, themes_exports.pick)({
  dark: themes_exports.variables.static17,
  light: themes_exports.variables.static4
})};
            `}
`;
var StyledLink = styled_components_default(Link_default)`
    color: inherit;
    text-decoration: underline;
`;
var maybeFieldLink = (field, value, onFieldClicked, onTimeClicked, isField, timeFieldAdditionalProps, fieldAdditionalProps) => {
  if (onTimeClicked && isTimeField(field)) {
    return /* @__PURE__ */ react_default.createElement(
      StyledLink,
      __spreadValues({
        role: "button",
        onClick: (e) => {
          e.preventDefault();
          onTimeClicked(e, { time: value });
        }
      }, timeFieldAdditionalProps),
      field
    );
  }
  if (onFieldClicked && !isTimeField(field) && (!isField || isField(field))) {
    return /* @__PURE__ */ react_default.createElement(
      StyledLink,
      __spreadValues({
        role: "button",
        onClick: (e) => {
          e.preventDefault();
          onFieldClicked(e, { field, value });
        }
      }, fieldAdditionalProps),
      field
    );
  }
  return /* @__PURE__ */ react_default.createElement("span", null, field);
};
var MaybeFieldValueLink = (props) => {
  const { field, value, onFieldValueClicked, isField, isHighlighted } = props;
  const ref = react_default.useRef(null);
  const isLink = onFieldValueClicked && !isTimeField(field) && (!isField || isField(field));
  react_default.useEffect(() => {
    if (!isLink) {
      return void 0;
    }
    const handleLinkClick = (e) => e.preventDefault();
    const element = ref.current;
    element.addEventListener("click", handleLinkClick);
    return () => {
      element.removeEventListener("click", handleLinkClick);
    };
  }, [isLink]);
  const valueElement = isLink ? /* @__PURE__ */ react_default.createElement(
    StyledLink,
    {
      role: "button",
      elementRef: ref,
      onClick: (e) => {
        e.preventDefault();
        onFieldValueClicked(e, { field, value });
      }
    },
    value
  ) : /* @__PURE__ */ react_default.createElement("span", null, value);
  return /* @__PURE__ */ react_default.createElement(FieldValueContainer, { $highlighted: isHighlighted }, valueElement);
};
var MaybeTagsLink = (props) => {
  const { field, onTagClicked, tags } = props;
  if (!tags || tags.length === 0) {
    return /* @__PURE__ */ react_default.createElement("span", null);
  }
  if (onTagClicked) {
    return /* @__PURE__ */ react_default.createElement(react_default.Fragment, null, "\xA0( ", tags.map((tag) => /* @__PURE__ */ react_default.createElement("span", { key: (0, id_exports.createDOMID)() }, /* @__PURE__ */ react_default.createElement(
      StyledLink,
      {
        role: "button",
        onClick: (e) => {
          e.preventDefault();
          onTagClicked(e, { field, value: tag });
        }
      },
      tag
    ), "\xA0")), ")");
  }
  return /* @__PURE__ */ react_default.createElement("span", null, "\xA0(\xA0", tags.join(" "), "\xA0)\xA0");
};
//# sourceMappingURL=index.js.map
