/* 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 __objRest = (source, exclude) => {
  var target = {};
  for (var prop in source)
    if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
      target[prop] = source[prop];
  if (source != null && __getOwnPropSymbols)
    for (var prop of __getOwnPropSymbols(source)) {
      if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
        target[prop] = source[prop];
    }
  return target;
};
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);
var __async = (__this, __arguments, generator) => {
  return new Promise((resolve, reject) => {
    var fulfilled = (value) => {
      try {
        step(generator.next(value));
      } catch (e) {
        reject(e);
      }
    };
    var rejected = (value) => {
      try {
        step(generator.throw(value));
      } catch (e) {
        reject(e);
      }
    };
    var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
    step((generator = generator.apply(__this, __arguments)).next());
  });
};

// src/utils/TableStyleSet.ts
var TableStyleSet_exports = {};
__export(TableStyleSet_exports, {
  default: () => TableStyleSet
});
module.exports = __toCommonJS(TableStyleSet_exports);

// esm-externals:@splunk/ui-utils/i18n
var i18n_exports = {};
__export(i18n_exports, {
  default: () => i18n_default
});
var defaultImport = __toESM(require("@splunk/ui-utils/i18n"));
__reExport(i18n_exports, require("@splunk/ui-utils/i18n"));
var i18n_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:@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: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/utils/actions.ts
var EVENT_ID_TUPLE = ["splunk_server", "index", "_cd"];
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 isInternalField = (field) => internalFields.has(field);
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 generateKey(event, index, pageNumber) {
  let key = "";
  for (const field of EVENT_ID_TUPLE) {
    if (event[field]) {
      key = key === "" ? event[field].toString() : `${key}-${event[field]}`;
    }
  }
  return pageNumber ? `${key}-${index}-${pageNumber}` : `${key}-${index}`;
}
function rawString(event) {
  if (lodash_default.isObject(event)) {
    if (event._raw !== void 0) {
      if (lodash_default.isString(event._raw)) {
        return event._raw;
      }
      if (lodash_default.isObject(event._raw) && lodash_default.isString(event._raw.value)) {
        return event._raw.value;
      }
    }
  } else if (lodash_default.isString(event)) {
    return event;
  }
  return JSON.stringify(event);
}
function isJsonString(str) {
  if (!lodash_default.isString(str)) {
    return false;
  }
  try {
    JSON.parse(str);
  } catch (e) {
    return false;
  }
  return true;
}

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

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

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

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

// 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: wrapResults2 } = this.props;
    return this.state.highlight ? /* @__PURE__ */ react_default.createElement("div", null, /* @__PURE__ */ react_default.createElement(
      StyledJSONTree,
      {
        json: rawEventString,
        defaultExpanded: false,
        overflow: wrapResults2 ? "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: wrapResults2,
  initialHighlight,
  rawEventString,
  event,
  showFooter,
  footerFields,
  fieldValueHighlightMap,
  allTagsMap,
  onFieldValueClicked,
  onTagClicked,
  isField
}) => /* @__PURE__ */ react_default.createElement(TableCell, { style: wrapResults2 ? {} : { whiteSpace: "nowrap" } }, isJsonString(rawEventString) ? /* @__PURE__ */ react_default.createElement(
  JsonCell,
  {
    initialHighlight,
    rawEventString,
    wrapResults: wrapResults2
  }
) : rawEventString, showFooter && /* @__PURE__ */ react_default.createElement(
  FooterFields_default,
  {
    event,
    footerFields,
    fieldValueHighlightMap,
    onFieldValueClicked,
    onTagClicked,
    isField,
    allTagsMap
  }
));
var CustomCell_default = CustomCell;

// src/components/Raw/index.tsx
var Raw = ({
  events,
  getExpansionRow,
  pageNumber,
  selection,
  onFieldValueClicked,
  footerFields,
  fieldValueHighlightMap,
  isField
}) => {
  const [expandedRowId, setExpandedRowId] = react_default.useState(null);
  const handleRowExpansion = (rowId) => {
    if (expandedRowId === rowId) {
      setExpandedRowId(null);
    } else {
      setExpandedRowId(rowId);
    }
  };
  return /* @__PURE__ */ react_default.createElement(
    Table_default,
    {
      stripeRows: true,
      rowExpansion: "controlled",
      "data-test": "workflow-components:Raw",
      onRequestToggleAllRows: selection ? () => selection.onTogglePage(events, pageNumber, selection.pageToggle) : void 0,
      rowSelection: selection ? selection.pageToggle : void 0
    },
    /* @__PURE__ */ react_default.createElement(Table_default.Head, null, /* @__PURE__ */ react_default.createElement(Table_default.HeadCell, null, "Event")),
    /* @__PURE__ */ react_default.createElement(Table_default.Body, null, events.map((event, index) => {
      const key = generateKey(event, index, pageNumber);
      const rawEventString = rawString(event);
      return /* @__PURE__ */ react_default.createElement(
        Table_default.Row,
        {
          key,
          expansionRow: getExpansionRow(event, key, index, pageNumber),
          onExpansion: () => handleRowExpansion(key),
          expanded: key === expandedRowId,
          onRequestToggle: selection ? () => selection.onToggleRow(event, index, pageNumber) : void 0,
          selected: selection ? selection.rows.some(
            (row) => row.index === index && row.pageNumber === pageNumber
          ) : void 0,
          rowScreenReaderText: event._time
        },
        /* @__PURE__ */ react_default.createElement(
          CustomCell_default,
          {
            rawEventString,
            initialHighlight: false,
            wrapResults: true,
            event,
            footerFields,
            fieldValueHighlightMap,
            showFooter: key !== expandedRowId,
            onFieldValueClicked,
            isField
          }
        )
      );
    }))
  );
};
var Raw_default = Raw;

// esm-externals:@splunk/moment
var moment_exports = {};
__export(moment_exports, {
  default: () => moment_default
});
var defaultImport13 = __toESM(require("@splunk/moment"));
__reExport(moment_exports, require("@splunk/moment"));
var moment_default = "default" in defaultImport13 ? defaultImport13.default : defaultImport13;

// src/components/TimeValue/index.tsx
var TimeLink = styled_components_default(Link_default)`
    color: ${themes_exports.variables.contentColorDefault};
    line-height: ${themes_exports.variables.lineHeight};

    &:hover,
    &focus {
        color: ${themes_exports.variables.linkColor};
    }
`;
var Part = styled_components_default.span`
    pointer-events: none;
    white-space: nowrap;
`;
var TimeValue = (_a) => {
  var _b = _a, {
    time,
    timeFormat,
    onTimeClicked,
    timeFieldAdditionalProps
  } = _b, rest = __objRest(_b, [
    "time",
    "timeFormat",
    "onTimeClicked",
    "timeFieldAdditionalProps"
  ]);
  if (!time) {
    return null;
  }
  const lmsTimeParts = [
    /* @__PURE__ */ react_default.createElement(Part, { key: "date" }, moment_default(time).splunkFormat("l")),
    /* @__PURE__ */ react_default.createElement("br", { key: "break" }),
    /* @__PURE__ */ react_default.createElement(Part, { key: "time" }, moment_default(time).splunkFormat("LTMS"))
  ];
  const parts = timeFormat === "lms" ? lmsTimeParts : moment_default(time).splunkFormat(timeFormat);
  if (!onTimeClicked) {
    return /* @__PURE__ */ react_default.createElement("span", __spreadValues({ "data-test": "time-value", "data-test-value": time }, rest), parts);
  }
  return /* @__PURE__ */ react_default.createElement(
    TimeLink,
    __spreadValues(__spreadValues({
      role: "button",
      "data-test": "time-value",
      "data-test-value": time,
      onClick: (e) => {
        e.preventDefault();
        onTimeClicked(e, { time });
      }
    }, timeFieldAdditionalProps), rest),
    parts
  );
};
var TimeValue_default = TimeValue;

// esm-externals:@splunk/splunk-utils/fetch
var fetch_exports = {};
__export(fetch_exports, {
  default: () => fetch_default
});
var defaultImport14 = __toESM(require("@splunk/splunk-utils/fetch"));
__reExport(fetch_exports, require("@splunk/splunk-utils/fetch"));
var fetch_default = "default" in defaultImport14 ? defaultImport14.default : defaultImport14;

// esm-externals:@splunk/splunk-utils/config
var config_exports = {};
__export(config_exports, {
  default: () => config_default
});
var defaultImport15 = __toESM(require("@splunk/splunk-utils/config"));
__reExport(config_exports, require("@splunk/splunk-utils/config"));
var config_default = "default" in defaultImport15 ? defaultImport15.default : defaultImport15;

// esm-externals:@splunk/splunk-utils/url
var url_exports = {};
__export(url_exports, {
  default: () => url_default
});
var defaultImport16 = __toESM(require("@splunk/splunk-utils/url"));
__reExport(url_exports, require("@splunk/splunk-utils/url"));
var url_default = "default" in defaultImport16 ? defaultImport16.default : defaultImport16;

// src/utils/tagAPI.ts
var tagsURL = `/servicesNS/${encodeURIComponent(config_exports.username)}/${encodeURIComponent(config_exports.app)}/saved/fvtags`;
var handleResponse = (response, expectedStatus = 200) => __async(void 0, null, function* () {
  var _a;
  if (!(response == null ? void 0 : response.ok)) {
    const defaultErrorMsg = `${response == null ? void 0 : response.status} - ${response == null ? void 0 : response.statusText}`;
    const JSONErrorMsg = (0, fetch_exports.findErrorMessage)(yield response == null ? void 0 : response.json());
    const error = new Error((_a = JSONErrorMsg == null ? void 0 : JSONErrorMsg.text) != null ? _a : defaultErrorMsg);
    throw error;
  }
  if (response.status !== expectedStatus) {
    throw new Error(`Received status code ${response.status} instead of expected ${expectedStatus}`);
  }
  return response.json();
});
var fetchRESTURL = (..._0) => __async(void 0, [..._0], function* (url = "", namespace = {}, queryParams = {}, fetchParams = {}, responseCode = 200) {
  const queryParamsObj = new URLSearchParams(queryParams);
  const validQueryParams = JSON.stringify(queryParams) === "{}" ? "" : `?${queryParamsObj.toString()}`;
  const splunkURL = (0, url_exports.createRESTURL)(url, namespace);
  const fetchArgs = __spreadValues(__spreadValues({}, fetch_exports.defaultFetchInit), fetchParams);
  const response = yield fetch(`${splunkURL}${validQueryParams}`, fetchArgs);
  return handleResponse(response, responseCode);
});
var fetchAllTags = () => __async(void 0, null, function* () {
  const url = tagsURL;
  const result = yield fetchRESTURL(
    url,
    {
      app: config_exports.app,
      username: config_exports.username
    },
    { output_mode: "json", count: 0 },
    { method: "GET" }
  );
  return result.entry.reduce((fvTagsMap, tagObject) => {
    if (!tagObject.content.disabled) {
      fvTagsMap[tagObject.name] = tagObject.content.tags;
    }
    return fvTagsMap;
  }, {});
});

// src/components/List/index.tsx
var TableRow = styled_components_default(Table_default.Row)`
    td {
        vertical-align: top;
    }

    /* HACK to work around http://go/j/SUI-2413, and also make expand button the full height of the row*/
    td[data-test='expand'] {
        svg {
            width: 32px;
            margin-top: 6px;
        }
        button {
            height: 100%;
            display: flex;
            align-items: flex-start;
        }
    }
`;
var StyledTableHeadCell = styled_components_default(Table_default.HeadCell)`
    span {
        font-size: ${themes_exports.mixins.typography({ size: 14 })};
    }
`;
var List = (_a) => {
  var _b = _a, {
    events,
    getExpansionRow,
    timeFormat = "lms",
    pageNumber,
    rowNumbers: rowNumbers2,
    wrapResults: wrapResults2,
    selection,
    onTimeClicked,
    onFieldValueClicked,
    onTagClicked,
    isField,
    footerFields,
    fieldValueHighlightMap,
    allTagsMap,
    timeFieldAdditionalProps,
    updateAllTags
  } = _b, otherProps = __objRest(_b, [
    "events",
    "getExpansionRow",
    "timeFormat",
    "pageNumber",
    "rowNumbers",
    "wrapResults",
    "selection",
    "onTimeClicked",
    "onFieldValueClicked",
    "onTagClicked",
    "isField",
    "footerFields",
    "fieldValueHighlightMap",
    "allTagsMap",
    "timeFieldAdditionalProps",
    "updateAllTags"
  ]);
  const featureFlagContext = (0, react_exports.useContext)(FeatureFlagContext_default);
  const isTagFeatureFlagOn = featureFlagContext == null ? void 0 : featureFlagContext.visualizations_enableEventsViewerTags;
  const [expandedRowId, setExpandedRowId] = react_default.useState(null);
  const getAllTags = () => __async(void 0, null, function* () {
    try {
      if (isTagFeatureFlagOn) {
        const result = yield fetchAllTags();
        updateAllTags(result);
      }
    } catch (e) {
      console.error(e);
    }
  });
  const handleRowExpansion = (rowId) => {
    if (expandedRowId === rowId) {
      setExpandedRowId(null);
    } else {
      setExpandedRowId(rowId);
    }
    getAllTags();
  };
  return /* @__PURE__ */ react_default.createElement(
    Table_default,
    __spreadValues({
      stripeRows: true,
      rowExpansion: "controlled",
      "data-test": "workflow-components:List",
      onRequestToggleAllRows: selection ? () => selection.onTogglePage(events, pageNumber, selection.pageToggle) : void 0,
      rowSelection: selection ? selection.pageToggle : void 0
    }, otherProps),
    /* @__PURE__ */ react_default.createElement(Table_default.Head, null, /* @__PURE__ */ react_default.createElement(StyledTableHeadCell, null, (0, i18n_exports._)("Time")), rowNumbers2 && /* @__PURE__ */ react_default.createElement(StyledTableHeadCell, { "data-test": "head-cell-rowNumbers" }), /* @__PURE__ */ react_default.createElement(StyledTableHeadCell, null, (0, i18n_exports._)("Event"))),
    /* @__PURE__ */ react_default.createElement(Table_default.Body, null, events.map((event, index) => {
      const key = generateKey(event, index, pageNumber);
      const rawEventString = rawString(event);
      return /* @__PURE__ */ react_default.createElement(
        TableRow,
        {
          key,
          expansionRow: getExpansionRow(event, key, index, pageNumber),
          onExpansion: () => handleRowExpansion(key),
          expanded: key === expandedRowId,
          onRequestToggle: selection ? () => selection.onToggleRow(event, index, pageNumber) : void 0,
          selected: selection ? selection.rows.some(
            (row) => row.index === index && row.pageNumber === pageNumber
          ) : void 0,
          rowScreenReaderText: event._time
        },
        /* @__PURE__ */ react_default.createElement(Table_default.Cell, null, /* @__PURE__ */ react_default.createElement(
          TimeValue_default,
          {
            time: event._time,
            timeFormat,
            onTimeClicked,
            timeFieldAdditionalProps
          }
        )),
        rowNumbers2 && /* @__PURE__ */ react_default.createElement(Table_default.Cell, null, index + 1),
        /* @__PURE__ */ react_default.createElement(
          CustomCell_default,
          {
            rawEventString,
            wrapResults: wrapResults2,
            initialHighlight: true,
            event,
            footerFields,
            fieldValueHighlightMap,
            showFooter: key !== expandedRowId,
            onFieldValueClicked,
            onTagClicked,
            isField,
            allTagsMap
          }
        )
      );
    }))
  );
};
var List_default = List;

// esm-externals:lodash/isArray
var isArray_exports = {};
__export(isArray_exports, {
  default: () => isArray_default
});
var defaultImport17 = __toESM(require("lodash/isArray"));
__reExport(isArray_exports, require("lodash/isArray"));
var isArray_default = "default" in defaultImport17 ? defaultImport17.default : defaultImport17;

// esm-externals:lodash/isObject
var isObject_exports = {};
__export(isObject_exports, {
  default: () => isObject_default
});
var defaultImport18 = __toESM(require("lodash/isObject"));
__reExport(isObject_exports, require("lodash/isObject"));
var isObject_default = "default" in defaultImport18 ? defaultImport18.default : defaultImport18;

// src/components/EventsTable/index.tsx
var TableRow2 = styled_components_default(Table_default.Row)`
    td {
        vertical-align: top;
    }

    /* HACK to work around http://go/j/SUI-2413 */
    td[data-role='expand'] {
        svg {
            width: 32px;
        }
    }
`;
var EventsTable = (_a) => {
  var _b = _a, {
    fields,
    events,
    pageNumber,
    getExpansionRow,
    timeFormat,
    rowNumbers: rowNumbers2,
    selection,
    onTimeClicked,
    timeFieldAdditionalProps
  } = _b, otherProps = __objRest(_b, [
    "fields",
    "events",
    "pageNumber",
    "getExpansionRow",
    "timeFormat",
    "rowNumbers",
    "selection",
    "onTimeClicked",
    "timeFieldAdditionalProps"
  ]);
  const columns = fields.reduce((agg, { name }) => {
    if (isTimeField(name)) {
      agg.unshift(name);
    } else if (!isInternalField(name)) {
      agg.push(name);
    }
    return agg;
  }, []);
  return /* @__PURE__ */ react_default.createElement(
    Table_default,
    __spreadValues({
      stripeRows: true,
      rowExpansion: "single",
      "data-test": "workflow-components:EventsTable",
      onRequestToggleAllRows: selection ? () => selection.onTogglePage(events, pageNumber, selection.pageToggle) : void 0,
      rowSelection: selection ? selection.pageToggle : void 0
    }, otherProps),
    /* @__PURE__ */ react_default.createElement(Table_default.Head, null, rowNumbers2 && /* @__PURE__ */ react_default.createElement(Table_default.HeadCell, { key: "row-numbers", style: { width: 10 } }, " "), columns.map((column) => /* @__PURE__ */ react_default.createElement(Table_default.HeadCell, { key: `field-${column}` }, isTimeField(column) ? (0, i18n_exports._)("Time") : column))),
    /* @__PURE__ */ react_default.createElement(Table_default.Body, null, events.map((event, index) => {
      const key = generateKey(event, index, pageNumber);
      return /* @__PURE__ */ react_default.createElement(
        TableRow2,
        {
          key,
          expansionRow: getExpansionRow(event, key, index, pageNumber),
          onRequestToggle: selection ? () => selection.onToggleRow(event, index, pageNumber) : void 0,
          selected: selection ? selection.rows.some(
            (row) => row.index === index && row.pageNumber === pageNumber
          ) : void 0,
          rowScreenReaderText: event._time
        },
        rowNumbers2 && /* @__PURE__ */ react_default.createElement(Table_default.Cell, null, index + 1),
        columns.map((column) => {
          let cellVal = event[column];
          if (isTimeField(column)) {
            cellVal = /* @__PURE__ */ react_default.createElement(
              TimeValue_default,
              {
                time: event._time,
                timeFormat,
                onTimeClicked,
                timeFieldAdditionalProps
              }
            );
          } else if (isArray_default(cellVal) || isObject_default(cellVal)) {
            cellVal = JSON.stringify(cellVal);
          }
          return /* @__PURE__ */ react_default.createElement(Table_default.Cell, { key: `${column}-${key}` }, cellVal);
        })
      );
    }))
  );
};
EventsTable.defaultProps = {
  timeFormat: "lms"
};
var EventsTable_default = EventsTable;

// src/utils/TableStyleSet.ts
var _TableStyleSet = class _TableStyleSet {
  // NOSONAR - assigned after class definition
  /**
   * Create a TableStyles object
   *
   * @param {Array} styles An array of styles.
   * When displayed to the user, the order of this
   * array will be preserved.
   *
   * @returns {TableStyles}
   */
  constructor(styles) {
    __publicField(this, "data", {
      // NOSONAR
      styles: [],
      dict: {}
    });
    this.data.styles = styles.slice();
    this.data.styles.forEach((style) => {
      this.data.dict[style.key] = style;
      if ([style.key, style.label, style.component].includes(void 0)) {
        throw Error("All table style definitions must have key, label, and component fields");
      }
    });
  }
  /**
   * Return all table style definitions from this set
   * @returns {Array} The table style definitions, in the same order they were defined.
   */
  getValues() {
    return this.data.styles.slice();
  }
  /**
   * Return all table style keys
   * @returns {Array} The keys
   */
  getKeys() {
    return this.data.styles.map((s) => s.key);
  }
  /**
   * Get a table style definition by its key
   * @param {String} key The key for the desired table style
   * @returns {Object} The table style definition requested
   */
  get(key) {
    return this.data.dict[key];
  }
  /**
   * Create a new table style set that is a concatenation of the table styles
   * from this set, plus those from the styles param, in that order.
   *
   * Intended to simplify the simple use case that a client would like to append some
   * custom table styles to the `TableStyleSet.builtin` set. For clients that would
   * like to include only some builtin styles, or would like to re-order them, it may
   * be helpful to grab the desired styles with `TableStyleSet.builtin.get(key)`,
   * and then create the TableStyleSet with the desired order manually.
   *
   * @param {(Array|TableStyleSet)} styles The styles to concatenate with this set.
   * @returns {TableStyleSet} The new TableStyleSet
   */
  concat(styles) {
    if (styles instanceof _TableStyleSet) {
      return new _TableStyleSet(this.data.styles.concat(styles.getValues()));
    }
    return new _TableStyleSet(this.data.styles.concat(styles));
  }
};
__publicField(_TableStyleSet, "builtin");
var TableStyleSet = _TableStyleSet;
var wrapResults = {
  key: "wrapResults",
  label: (0, i18n_exports._)("Wrap Results")
};
var rowNumbers = {
  key: "rowNumbers",
  label: (0, i18n_exports._)("Row Numbers")
};
var buildtinStyles = [
  {
    key: "raw",
    label: (0, i18n_exports._)("Raw"),
    component: Raw_default,
    formattingOptions: []
  },
  {
    key: "list",
    label: (0, i18n_exports._)("List"),
    component: List_default,
    formattingOptions: [wrapResults, rowNumbers]
  },
  {
    key: "table",
    label: (0, i18n_exports._)("Table"),
    component: EventsTable_default,
    formattingOptions: [wrapResults, rowNumbers]
  }
];
TableStyleSet.builtin = new TableStyleSet(buildtinStyles);
//# sourceMappingURL=TableStyleSet.js.map
