/* 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 __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
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);
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);

// src/components/CustomCell/index.tsx
var CustomCell_exports = {};
__export(CustomCell_exports, {
  default: () => CustomCell_default
});
module.exports = __toCommonJS(CustomCell_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-ui/Table
var Table_exports = {};
__export(Table_exports, {
  default: () => Table_default
});
var defaultImport3 = __toESM(require("@splunk/react-ui/Table"));
__reExport(Table_exports, require("@splunk/react-ui/Table"));
var Table_default = "default" in defaultImport3 ? defaultImport3.default : defaultImport3;

// esm-externals:@splunk/react-ui/JSONTree
var JSONTree_exports = {};
__export(JSONTree_exports, {
  default: () => JSONTree_default
});
var defaultImport4 = __toESM(require("@splunk/react-ui/JSONTree"));
__reExport(JSONTree_exports, require("@splunk/react-ui/JSONTree"));
var JSONTree_default = "default" in defaultImport4 ? defaultImport4.default : defaultImport4;

// esm-externals:@splunk/react-ui/Button
var Button_exports = {};
__export(Button_exports, {
  default: () => Button_default
});
var defaultImport5 = __toESM(require("@splunk/react-ui/Button"));
__reExport(Button_exports, require("@splunk/react-ui/Button"));
var Button_default = "default" in defaultImport5 ? defaultImport5.default : defaultImport5;

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

// esm-externals:@splunk/ui-utils/i18n
var i18n_exports = {};
__export(i18n_exports, {
  default: () => i18n_default
});
var defaultImport7 = __toESM(require("@splunk/ui-utils/i18n"));
__reExport(i18n_exports, require("@splunk/ui-utils/i18n"));
var i18n_default = "default" in defaultImport7 ? defaultImport7.default : defaultImport7;

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

// 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";
var testStringWithWildCardString = (wildCardString, stringToTest) => {
  const w = wildCardString.replace(/[.+^${}()|[\]\\]/g, "\\$&");
  const re = new RegExp(`^${w.replace(/\*/g, ".*").replace(/\?/g, ".")}$`, "i");
  return re.test(stringToTest);
};
function isJsonString(str) {
  if (!lodash_default.isString(str)) {
    return false;
  }
  try {
    JSON.parse(str);
  } catch (e) {
    return false;
  }
  return true;
}

// esm-externals:@splunk/visualization-context/FeatureFlagContext
var FeatureFlagContext_exports = {};
__export(FeatureFlagContext_exports, {
  default: () => FeatureFlagContext_default
});
var defaultImport9 = __toESM(require("@splunk/visualization-context/FeatureFlagContext"));
__reExport(FeatureFlagContext_exports, require("@splunk/visualization-context/FeatureFlagContext"));
var FeatureFlagContext_default = "default" in defaultImport9 ? defaultImport9.default : defaultImport9;

// esm-externals:lodash/has
var has_exports = {};
__export(has_exports, {
  default: () => has_default
});
var defaultImport10 = __toESM(require("lodash/has"));
__reExport(has_exports, require("lodash/has"));
var has_default = "default" in defaultImport10 ? defaultImport10.default : defaultImport10;

// esm-externals:@splunk/react-ui/Link
var Link_exports = {};
__export(Link_exports, {
  default: () => Link_default
});
var defaultImport11 = __toESM(require("@splunk/react-ui/Link"));
__reExport(Link_exports, require("@splunk/react-ui/Link"));
var Link_default = "default" in defaultImport11 ? defaultImport11.default : defaultImport11;

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

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

// src/components/FooterFields/index.tsx
var FooterFieldList = styled_components_default.dl`
    padding: 0;
    margin: 0;
`;
var FooterField = styled_components_default.div`
    &:not(:last-of-type) {
        border-right: 1px dashed ${themes_exports.variables.borderColor};
    }
    margin-right: ${themes_exports.variables.spacingSmall};
    list-style: none;
    display: inline;
`;
var FooterItem = styled_components_default.span`
    display: inline;
    margin: 0;
    padding: 0;
    color: ${themes_exports.variables.contentColorDefault};
`;
var FooterFields = (props) => {
  const { footerFields, fieldValueHighlightMap, allTagsMap } = props;
  const uniqueFooterFields = react_default.useMemo(() => {
    const fieldsThatExist = footerFields == null ? void 0 : footerFields.filter((field) => has_default(props.event, field));
    return [...new Set(fieldsThatExist)];
  }, [footerFields, props.event]);
  const featureFlagContext = react_default.useContext(FeatureFlagContext_default);
  const isTagFeatureFlagOn = featureFlagContext == null ? void 0 : featureFlagContext.visualizations_enableEventsViewerTags;
  const renderFooterField = (field, value) => {
    var _a;
    const valuesToHighlight = fieldValueHighlightMap == null ? void 0 : fieldValueHighlightMap[field];
    let isValueHighlighted = false;
    if (valuesToHighlight) {
      if (Array.isArray(valuesToHighlight)) {
        isValueHighlighted = valuesToHighlight.findIndex((v1) => {
          return testStringWithWildCardString(v1.toString(), value);
        }) > -1;
      } else {
        isValueHighlighted = testStringWithWildCardString(valuesToHighlight.toString(), value);
      }
    }
    const tagsKey = `${field}=${value}`;
    return /* @__PURE__ */ react_default.createElement(react_default.Fragment, { key: `${field}=${value}` }, /* @__PURE__ */ react_default.createElement(FooterItem, null, field, " ", /* @__PURE__ */ react_default.createElement("span", { "aria-hidden": "true" }, "="), " "), /* @__PURE__ */ react_default.createElement(FooterItem, null, /* @__PURE__ */ react_default.createElement(
      MaybeFieldValueLink,
      {
        field,
        value,
        onFieldValueClicked: props.onFieldValueClicked,
        isField: props.isField,
        isHighlighted: isValueHighlighted
      }
    ), isTagFeatureFlagOn && /* @__PURE__ */ react_default.createElement(
      MaybeTagsLink,
      {
        field,
        onTagClicked: props.onTagClicked,
        tags: (_a = allTagsMap[tagsKey]) != null ? _a : []
      }
    ), " "));
  };
  return /* @__PURE__ */ react_default.createElement(FooterFieldList, null, uniqueFooterFields.map((field) => {
    const value = props.event[field];
    if (!value) {
      return null;
    }
    return /* @__PURE__ */ react_default.createElement(FooterField, { key: `footer-entry-${field}` }, Array.isArray(value) ? value.map((valueItem) => renderFooterField(field, valueItem)) : renderFooterField(field, value));
  }));
};
var FooterFields_default = FooterFields;

// src/components/CustomCell/index.tsx
var TableCell = styled_components_default(Table_default.Cell)`
    font-family: ${themes_exports.variables.monoFontFamily};
    line-height: ${themes_exports.variables.lineHeight};
    div {
        flex-direction: column;
        align-items: flex-start;
        margin: 0;
        padding: 0;
    }
`;
var StyledButton = styled_components_default(Button_default)`
    margin-top: ${themes_exports.variables.spacingLarge};
    margin-bottom: ${themes_exports.variables.spacingXSmall};
    display: block;
    width: fit-content;
`;
var StyledJSONTree = styled_components_default(JSONTree_default)`
    span {
        min-height: 0px;
    }
`;
var JsonCell = class extends react_exports.Component {
  constructor(props) {
    super(props);
    /** Method to set the highlight state to false so that
     * raw event text is displayed in the table cell  */
    __publicField(this, "getRawText", () => {
      this.setState({
        highlight: false
      });
    });
    /** Method to the highlight state to true so that the
     * event is shown as a JSON tree */
    __publicField(this, "highlightSyntax", () => {
      this.setState({
        highlight: true
      });
    });
    this.state = {
      highlight: props.initialHighlight
    };
  }
  render() {
    const { rawEventString, wrapResults } = this.props;
    return this.state.highlight ? /* @__PURE__ */ react_default.createElement("div", null, /* @__PURE__ */ react_default.createElement(
      StyledJSONTree,
      {
        json: rawEventString,
        defaultExpanded: false,
        overflow: wrapResults ? "wrap" : "scroll"
      }
    ), /* @__PURE__ */ react_default.createElement(
      StyledButton,
      {
        appearance: "standalone",
        onClick: (e) => {
          e.preventDefault();
          this.getRawText();
        },
        "data-test": "show-raw-text-button"
      },
      (0, i18n_exports._)("Show as raw text")
    )) : /* @__PURE__ */ react_default.createElement("div", null, /* @__PURE__ */ react_default.createElement("div", null, rawEventString), /* @__PURE__ */ react_default.createElement(
      StyledButton,
      {
        appearance: "standalone",
        onClick: (e) => {
          e.preventDefault();
          this.highlightSyntax();
        },
        "data-test": "highlight-syntax-button"
      },
      (0, i18n_exports._)("Show syntax highlighted")
    ));
  }
};
var CustomCell = ({
  wrapResults,
  initialHighlight,
  rawEventString,
  event,
  showFooter,
  footerFields,
  fieldValueHighlightMap,
  allTagsMap,
  onFieldValueClicked,
  onTagClicked,
  isField
}) => /* @__PURE__ */ react_default.createElement(TableCell, { style: wrapResults ? {} : { whiteSpace: "nowrap" } }, isJsonString(rawEventString) ? /* @__PURE__ */ react_default.createElement(
  JsonCell,
  {
    initialHighlight,
    rawEventString,
    wrapResults
  }
) : rawEventString, showFooter && /* @__PURE__ */ react_default.createElement(
  FooterFields_default,
  {
    event,
    footerFields,
    fieldValueHighlightMap,
    onFieldValueClicked,
    onTagClicked,
    isField,
    allTagsMap
  }
));
var CustomCell_default = CustomCell;
//# sourceMappingURL=index.js.map
