/* 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 __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 __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 __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/components/RowExpander/index.tsx
var RowExpander_exports = {};
__export(RowExpander_exports, {
  default: () => RowExpander_default
});
module.exports = __toCommonJS(RowExpander_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/Dropdown
var Dropdown_exports = {};
__export(Dropdown_exports, {
  default: () => Dropdown_default
});
var defaultImport4 = __toESM(require("@splunk/react-ui/Dropdown"));
__reExport(Dropdown_exports, require("@splunk/react-ui/Dropdown"));
var Dropdown_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/react-ui/Menu
var Menu_exports = {};
__export(Menu_exports, {
  default: () => Menu_default
});
var defaultImport6 = __toESM(require("@splunk/react-ui/Menu"));
__reExport(Menu_exports, require("@splunk/react-ui/Menu"));
var Menu_default = "default" in defaultImport6 ? defaultImport6.default : defaultImport6;

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

// esm-externals:@splunk/react-ui/Switch
var Switch_exports = {};
__export(Switch_exports, {
  default: () => Switch_default
});
var defaultImport8 = __toESM(require("@splunk/react-ui/Switch"));
__reExport(Switch_exports, require("@splunk/react-ui/Switch"));
var Switch_default = "default" in defaultImport8 ? defaultImport8.default : defaultImport8;

// esm-externals:@splunk/react-icons/enterprise/ChevronDown
var ChevronDown_exports = {};
__export(ChevronDown_exports, {
  default: () => ChevronDown_default
});
var defaultImport9 = __toESM(require("@splunk/react-icons/enterprise/ChevronDown"));
__reExport(ChevronDown_exports, require("@splunk/react-icons/enterprise/ChevronDown"));
var ChevronDown_default = "default" in defaultImport9 ? defaultImport9.default : defaultImport9;

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

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

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

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

// 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 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);
};
var createWildcardRegex = (value) => {
  if (typeof value !== "string") {
    return false;
  }
  const wordBoundary = "\\b";
  const pattern = value === "*" ? ".*" : `${wordBoundary}${value.replace(/\*/g, ".*")}${wordBoundary}`;
  try {
    return new RegExp(pattern, "g");
  } catch (e) {
    return false;
  }
};
var isFuzzySubset = (subsetArray = [], supersetArray = []) => {
  const intersection = subsetArray.filter((subsetValue) => {
    const subsetValueRegex = createWildcardRegex(subsetValue.toString());
    return subsetValueRegex ? supersetArray.find(
      (supersetValue) => supersetValue && supersetValue.toString().match(subsetValueRegex) !== null
    ) : false;
  });
  return intersection.length === subsetArray.length;
};
var shouldShowActionAfterEventtypeFilter = (event, eventtypeValues = []) => {
  const eventtypeValuesCount = eventtypeValues.length;
  const isStarValue = eventtypeValuesCount === 1 && eventtypeValues[0] === "*";
  if (eventtypeValuesCount === 0 || isStarValue) {
    return true;
  }
  if ("eventtype" in event) {
    const eventtypeArray = Array.isArray(event.eventtype) ? event.eventtype : [event.eventtype];
    return isFuzzySubset(eventtypeValues, eventtypeArray);
  }
  return false;
};
var shouldShowEventActionAfterFieldFilter = (event, fieldFilters = []) => {
  const fieldFiltersCount = fieldFilters.length;
  const isStarValue = fieldFiltersCount === 1 && fieldFilters[0] === "*";
  if (fieldFiltersCount === 0 || isStarValue) {
    return true;
  }
  const fields = Object.keys(event);
  return isFuzzySubset(fieldFilters, fields);
};
var isWildcardMatch = (substring, superstring) => {
  const substringRegex = createWildcardRegex(substring);
  if (!substringRegex) {
    return false;
  }
  return substringRegex.exec(superstring) !== null;
};
var getFieldActionsMap = (event, renderFieldActions = {}, fields = []) => {
  const fieldActionsMap = {};
  Object.keys(renderFieldActions).forEach((fieldActionFieldRaw) => {
    fields.forEach((field) => {
      const currentActions = fieldActionsMap[field] || [];
      const fieldActionsByField = renderFieldActions[fieldActionFieldRaw];
      fieldActionsByField.forEach(({ eventtypeValues, fieldActionComponent }) => {
        if (isWildcardMatch(fieldActionFieldRaw, field) && shouldShowActionAfterEventtypeFilter(event, eventtypeValues)) {
          currentActions.push(fieldActionComponent);
          fieldActionsMap[field] = currentActions;
        }
      });
    });
  });
  return fieldActionsMap;
};
var getFilteredEventActionComponents = (event, renderEventActions = []) => {
  const renderEventActionComponents = [];
  renderEventActions.forEach((eventAction) => {
    const { eventtypeValues, fieldFilters, eventActionComponent } = eventAction;
    if (shouldShowActionAfterEventtypeFilter(event, eventtypeValues) && shouldShowEventActionAfterFieldFilter(event, fieldFilters)) {
      renderEventActionComponents.push(eventActionComponent);
    }
  });
  return renderEventActionComponents;
};

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

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

// esm-externals:@splunk/react-ui/ControlGroup
var ControlGroup_exports = {};
__export(ControlGroup_exports, {
  default: () => ControlGroup_default
});
var defaultImport15 = __toESM(require("@splunk/react-ui/ControlGroup"));
__reExport(ControlGroup_exports, require("@splunk/react-ui/ControlGroup"));
var ControlGroup_default = "default" in defaultImport15 ? defaultImport15.default : defaultImport15;

// esm-externals:@splunk/react-ui/Modal
var Modal_exports = {};
__export(Modal_exports, {
  default: () => Modal_default
});
var defaultImport16 = __toESM(require("@splunk/react-ui/Modal"));
__reExport(Modal_exports, require("@splunk/react-ui/Modal"));
var Modal_default = "default" in defaultImport16 ? defaultImport16.default : defaultImport16;

// esm-externals:@splunk/react-ui/TextArea
var TextArea_exports = {};
__export(TextArea_exports, {
  default: () => TextArea_default
});
var defaultImport17 = __toESM(require("@splunk/react-ui/TextArea"));
__reExport(TextArea_exports, require("@splunk/react-ui/TextArea"));
var TextArea_default = "default" in defaultImport17 ? defaultImport17.default : defaultImport17;

// esm-externals:@splunk/react-ui/ComboBox
var ComboBox_exports = {};
__export(ComboBox_exports, {
  default: () => ComboBox_default
});
var defaultImport18 = __toESM(require("@splunk/react-ui/ComboBox"));
__reExport(ComboBox_exports, require("@splunk/react-ui/ComboBox"));
var ComboBox_default = "default" in defaultImport18 ? defaultImport18.default : defaultImport18;

// esm-externals:@splunk/react-ui/Message
var Message_exports = {};
__export(Message_exports, {
  default: () => Message_default
});
var defaultImport19 = __toESM(require("@splunk/react-ui/Message"));
__reExport(Message_exports, require("@splunk/react-ui/Message"));
var Message_default = "default" in defaultImport19 ? defaultImport19.default : defaultImport19;

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

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

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

// src/utils/tagAPI.ts
var tagsURL = `/servicesNS/${encodeURIComponent(config_exports.username)}/${encodeURIComponent(config_exports.app)}/saved/fvtags`;
var getTagsHash = (tags) => {
  return tags.reduce((hash, tag) => {
    hash[`tag.${tag}`] = tag;
    return hash;
  }, {});
};
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 fetchTags = (fname = "", fvalue = "") => __async(void 0, null, function* () {
  const url = `${tagsURL}/${encodeURIComponent(fname)}%3D${encodeURIComponent(fvalue)}`;
  const result = yield fetchRESTURL(
    url,
    {
      app: config_exports.app,
      username: config_exports.username
    },
    {
      output_mode: "json"
    },
    { method: "GET" }
  );
  return result.entry[0].content.tags;
});
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;
  }, {});
});
var createTags = (..._0) => __async(void 0, [..._0], function* (fname = "", fvalue = "", tags = []) {
  const url = tagsURL;
  const data = __spreadValues({
    name: `${fname}=${fvalue}`,
    output_mode: "json"
  }, getTagsHash(tags));
  const dataObj = new URLSearchParams(data);
  const result = yield fetchRESTURL(
    url,
    {
      app: config_exports.app,
      username: config_exports.username
    },
    {},
    {
      method: "POST",
      body: dataObj.toString()
    },
    201
  );
  return result.entry[0].content.tags;
});
var updateTags = (..._0) => __async(void 0, [..._0], function* (fname = "", fvalue = "", tags = []) {
  const url = `${tagsURL}/${encodeURIComponent(fname)}%3D${encodeURIComponent(fvalue)}`;
  const data = __spreadValues({
    output_mode: "json"
  }, getTagsHash(tags));
  const dataObj = new URLSearchParams(data);
  const result = yield fetchRESTURL(
    url,
    {
      app: config_exports.app,
      username: config_exports.username
    },
    {},
    {
      method: "POST",
      body: dataObj.toString()
    }
  );
  return result.entry[0].content.tags;
});
var deleteTags = (fname = "", fvalue = "") => __async(void 0, null, function* () {
  const url = `${tagsURL}/${encodeURIComponent(fname)}%3D${encodeURIComponent(fvalue)}`;
  const result = yield fetchRESTURL(
    url,
    {
      app: config_exports.app,
      username: config_exports.username
    },
    { output_mode: "json" },
    { method: "DELETE" }
  );
  return result.entry;
});

// src/components/EditTagsModal/index.tsx
var formatTagsToArray = (tagsString) => {
  return tagsString ? tagsString.trim().replace(/,/g, " ").split(/\s+/) : [];
};
var EditTagsModal = (props) => {
  var _a;
  const { fieldName, fieldValue, tags, isOpen, updateIsModalOpen, updateAllTags } = props;
  const formattedTags = (_a = tags == null ? void 0 : tags.join(", ")) != null ? _a : "";
  const [tagsString, setTagsString] = (0, react_exports.useState)(formattedTags);
  const [errorMessage, setErrorMessage] = (0, react_exports.useState)("");
  const [isNew, setIsNew] = (0, react_exports.useState)(!tags);
  const handleRequestClose = () => {
    updateIsModalOpen(false);
  };
  const handleSave = () => __async(void 0, null, function* () {
    setErrorMessage("");
    const tagArray = formatTagsToArray(tagsString);
    try {
      if (isNew) {
        yield createTags(fieldName, fieldValue, tagArray);
      } else if (tagArray.length === 0) {
        yield deleteTags(fieldName, fieldValue);
      } else {
        yield updateTags(fieldName, fieldValue, tagArray);
      }
      handleRequestClose();
      const allTags = yield fetchAllTags();
      updateAllTags(allTags);
    } catch (e) {
      setErrorMessage(e.message);
    }
  });
  const onChange = (e) => {
    const tagString = e.target.value;
    setTagsString(tagString);
  };
  const TEXT = {
    TITLE: (0, i18n_exports._)("Create tags"),
    FIELD_LABEL: (0, i18n_exports._)("Field value"),
    TAGS_LABEL: (0, i18n_exports._)("Tag(s)"),
    HELP: (0, i18n_exports._)("Comma or space separated list of tags."),
    CANCEL: (0, i18n_exports._)("Cancel"),
    SAVE: (0, i18n_exports._)("Save"),
    FIELD_PLACEHOLDER: `${fieldName}=${fieldValue}`
  };
  (0, react_exports.useEffect)(() => {
    const resetModal = () => {
      setErrorMessage("");
      setTagsString(formattedTags);
    };
    const checkTagsExist = () => __async(void 0, null, function* () {
      var _a2;
      try {
        const tagsIncludingDisabled = yield fetchTags(fieldName, fieldValue);
        setTagsString((_a2 = tagsIncludingDisabled == null ? void 0 : tagsIncludingDisabled.join(", ")) != null ? _a2 : "");
        setIsNew(false);
      } catch (e) {
        setIsNew(true);
      }
    });
    if (isOpen) {
      resetModal();
      checkTagsExist();
    }
  }, [isOpen, fieldName, fieldValue, formattedTags]);
  return /* @__PURE__ */ react_default.createElement(
    Modal_default,
    {
      "data-test": "edit-tags-modal",
      onRequestClose: handleRequestClose,
      open: isOpen,
      style: { width: "550px" },
      onClick: (syntheticEvent) => {
        syntheticEvent.stopPropagation();
      },
      onMouseDown: (syntheticEvent) => {
        syntheticEvent.stopPropagation();
      },
      onMouseUp: (syntheticEvent) => {
        syntheticEvent.stopPropagation();
      },
      returnFocus: () => {
      }
    },
    /* @__PURE__ */ react_default.createElement(Modal_default.Header, { title: TEXT.TITLE }),
    /* @__PURE__ */ react_default.createElement(Modal_default.Body, null, errorMessage && /* @__PURE__ */ react_default.createElement(Message_default, { type: "error" }, errorMessage), /* @__PURE__ */ react_default.createElement(ControlGroup_default, { label: TEXT.FIELD_LABEL }, /* @__PURE__ */ react_default.createElement(
      ComboBox_default,
      {
        "data-test": "edit-tags-modal-field",
        disabled: true,
        placeholder: TEXT.FIELD_PLACEHOLDER
      }
    )), /* @__PURE__ */ react_default.createElement(ControlGroup_default, { label: TEXT.TAGS_LABEL, help: TEXT.HELP }, /* @__PURE__ */ react_default.createElement(TextArea_default, { "data-test": "edit-tags-modal-textarea", value: tagsString, onChange }))),
    /* @__PURE__ */ react_default.createElement(Modal_default.Footer, null, /* @__PURE__ */ react_default.createElement(Button_default, { appearance: "secondary", onClick: handleRequestClose, label: TEXT.CANCEL }), /* @__PURE__ */ react_default.createElement(Button_default, { appearance: "primary", onClick: handleSave, label: TEXT.SAVE }))
  );
};
var EditTagsModal_default = EditTagsModal;

// src/components/RowExpander/index.tsx
var TableHead = styled_components_default(Table_default.Head)`
    border-bottom: 1px solid ${themes_exports.variables.borderColorWeak};
`;
var TableRow = styled_components_default(Table_default.Row)`
    border-bottom: 1px solid ${themes_exports.variables.borderColorWeak};
`;
var StyledSpan = styled_components_default.span`
    font-size: ${themes_exports.mixins.typography({ size: 14 })};
    font-weight: ${themes_exports.mixins.typography({ weight: "bold" })};
    white-space: nowrap;
`;
var StyledTableCell = styled_components_default(Table_default.Cell)`
    padding: 0 0 0 15px;
    div {
        min-height: 0;
    }
`;
var StyledWrapper = styled_components_default.div`
    width: 100%;
`;
var RowExpander = (_a) => {
  var _b = _a, {
    renderEventActions = [],
    renderFieldActions = {},
    fieldValueHighlightMap = {},
    allTagsMap = {},
    updateAllTags,
    event,
    onFieldValueClicked,
    isField,
    onTagClicked,
    index,
    pageNumber,
    onFieldClicked,
    onTimeClicked,
    timeFieldAdditionalProps,
    fieldAdditionalProps
  } = _b, otherProps = __objRest(_b, [
    "renderEventActions",
    "renderFieldActions",
    "fieldValueHighlightMap",
    "allTagsMap",
    "updateAllTags",
    "event",
    "onFieldValueClicked",
    "isField",
    "onTagClicked",
    "index",
    "pageNumber",
    "onFieldClicked",
    "onTimeClicked",
    "timeFieldAdditionalProps",
    "fieldAdditionalProps"
  ]);
  const featureFlagContext = (0, react_exports.useContext)(FeatureFlagContext_default);
  const isTagFeatureFlagOn = featureFlagContext == null ? void 0 : featureFlagContext.visualizations_enableEventsViewerTags;
  const [editTagsModalData, setEditTagsModalData] = (0, react_exports.useState)({
    isOpen: false,
    fieldName: "",
    fieldValue: "",
    tags: []
  });
  const updateIsModalOpen = (0, react_exports.useCallback)(
    (isOpen) => {
      setEditTagsModalData(__spreadProps(__spreadValues({}, editTagsModalData), { isOpen }));
    },
    [editTagsModalData]
  );
  const updateEditTagsModalData = (0, react_exports.useCallback)(
    (isOpen, fieldName, fieldValue, tags) => {
      setEditTagsModalData({ isOpen, fieldName, fieldValue, tags });
    },
    []
  );
  const eventActionsToggle = /* @__PURE__ */ react_default.createElement(
    Button_default,
    {
      label: (0, i18n_exports._)("Event Actions"),
      isMenu: true,
      style: { marginBottom: 10 },
      "data-test": "event-actions-dropdown"
    }
  );
  const parsedata = (0, lodash_exports.pickBy)(event, (val) => (0, lodash_exports.isString)(val) || (0, lodash_exports.isArray)(val));
  const fields = Object.keys(parsedata).filter((field) => !isInternalField(field));
  const headCellStyle = { backgroundColor: "transparent" };
  const actionCellStyle = { padding: "0 0 0 0" };
  const tableCellDropdownStyle = { marginTop: 3 };
  const haveFieldSelection = false;
  const fieldActionsMap = getFieldActionsMap(event, renderFieldActions, fields);
  const haveFieldActions = Object.keys(fieldActionsMap).length !== 0;
  const haveFieldValueActions = isTagFeatureFlagOn ? true : haveFieldActions;
  const eventActionComponents = getFilteredEventActionComponents(event, renderEventActions);
  const getValueRow = (field, value) => {
    var _a2;
    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 fieldActions = fieldActionsMap[field] || [];
    const tagsKey = `${field}=${value}`;
    if (isTagFeatureFlagOn) {
      const handleModalOpen = () => {
        updateEditTagsModalData(true, field, value, allTagsMap[tagsKey]);
      };
      const editTagsAction = () => /* @__PURE__ */ react_default.createElement(
        Menu_default.Item,
        {
          key: "field-action-edit-tags",
          "data-test": "field-action-edit-tags",
          onClick: handleModalOpen
        },
        (0, i18n_exports._)("Edit tags")
      );
      fieldActions.unshift(editTagsAction);
    }
    const actionToggle = /* @__PURE__ */ react_default.createElement(
      Link_default,
      {
        "data-test": "field-actions-dropdown",
        "aria-label": `${field} actions`,
        style: tableCellDropdownStyle,
        role: "button",
        onClick: (e) => e.preventDefault()
      },
      /* @__PURE__ */ react_default.createElement(ChevronDown_default, { screenReaderText: null })
    );
    return /* @__PURE__ */ react_default.createElement(react_default.Fragment, null, /* @__PURE__ */ react_default.createElement(StyledTableCell, null, /* @__PURE__ */ react_default.createElement(
      MaybeFieldValueLink,
      {
        field,
        value,
        onFieldValueClicked,
        isField,
        isHighlighted: isValueHighlighted
      }
    ), isTagFeatureFlagOn && /* @__PURE__ */ react_default.createElement(
      MaybeTagsLink,
      {
        onTagClicked,
        field,
        tags: (_a2 = allTagsMap[tagsKey]) != null ? _a2 : []
      }
    )), haveFieldValueActions && /* @__PURE__ */ react_default.createElement(StyledTableCell, { align: "center", style: actionCellStyle }, fieldActions.length > 0 && field !== "_time" && /* @__PURE__ */ react_default.createElement(Dropdown_default, { toggle: actionToggle }, /* @__PURE__ */ react_default.createElement(Menu_default, { style: { width: 280, maxHeight: 270, overflowY: "auto" } }, fieldActions.map((Child, fieldActionsIndex) => {
      const actionKey = `field-action-${field}-${value}-${fieldActionsIndex}`;
      return /* @__PURE__ */ react_default.createElement(react_default.Fragment, { key: actionKey }, /* @__PURE__ */ react_default.createElement(
        Child,
        {
          event,
          field,
          value,
          rowIndex: index,
          pageNumber
        }
      ));
    })))));
  };
  return /* @__PURE__ */ react_default.createElement(Table_default.Row, __spreadValues({}, otherProps), /* @__PURE__ */ react_default.createElement(StyledTableCell, { colSpan: 1e3 }, /* @__PURE__ */ react_default.createElement(StyledWrapper, { "data-test": "workflow-components:RowExpander" }, eventActionComponents.length > 0 && /* @__PURE__ */ react_default.createElement(Dropdown_default, { toggle: eventActionsToggle }, /* @__PURE__ */ react_default.createElement(Menu_default, { style: { width: 150, maxHeight: 270, overflowY: "auto" } }, eventActionComponents.map((Child, eventActionsIndex) => {
    const actionKey = `event-action-${index}-${pageNumber}-${eventActionsIndex}`;
    return /* @__PURE__ */ react_default.createElement(react_default.Fragment, { key: actionKey }, /* @__PURE__ */ react_default.createElement(Child, { event, rowIndex: index, pageNumber }));
  }))), /* @__PURE__ */ react_default.createElement(Table_default, { stripeRows: false }, /* @__PURE__ */ react_default.createElement(TableHead, null, haveFieldSelection && /* @__PURE__ */ react_default.createElement(Table_default.HeadCell, { style: headCellStyle }), /* @__PURE__ */ react_default.createElement(Table_default.HeadCell, { style: headCellStyle }, /* @__PURE__ */ react_default.createElement(StyledSpan, null, (0, i18n_exports._)("Field"))), /* @__PURE__ */ react_default.createElement(Table_default.HeadCell, { style: headCellStyle }, /* @__PURE__ */ react_default.createElement(StyledSpan, null, (0, i18n_exports._)("Value"))), haveFieldValueActions && /* @__PURE__ */ react_default.createElement(Table_default.HeadCell, { align: "center", style: headCellStyle }, /* @__PURE__ */ react_default.createElement(StyledSpan, null, (0, i18n_exports._)("Actions")))), /* @__PURE__ */ react_default.createElement(Table_default.Body, null, fields.map((data) => {
    var _a2;
    const field = data;
    let fieldDropdown;
    const value = event[data];
    const rowSpan = (0, lodash_exports.isArray)(value) && value.length > 0 ? value.length : 1;
    return /* @__PURE__ */ react_default.createElement(react_exports.Fragment, { key: field }, /* @__PURE__ */ react_default.createElement(TableRow, { key: `${field}=${value.toString()}` }, haveFieldSelection && /* @__PURE__ */ react_default.createElement(StyledTableCell, null, /* @__PURE__ */ react_default.createElement(Switch_default, { appearance: "checkbox" })), /* @__PURE__ */ react_default.createElement(StyledTableCell, { rowSpan }, fieldDropdown || maybeFieldLink(
      field,
      value.toString(),
      onFieldClicked,
      onTimeClicked,
      isField,
      timeFieldAdditionalProps,
      fieldAdditionalProps
    )), (0, lodash_exports.isArray)(value) ? getValueRow(data, (_a2 = value[0]) != null ? _a2 : "") : getValueRow(data, value)), (0, lodash_exports.isArray)(value) && value.map(
      (valueItem, i) => i > 0 && /* @__PURE__ */ react_default.createElement(TableRow, { key: `${field}=${valueItem}` }, getValueRow(data, valueItem))
    ));
  })))), /* @__PURE__ */ react_default.createElement(
    EditTagsModal_default,
    {
      fieldName: editTagsModalData.fieldName,
      fieldValue: editTagsModalData.fieldValue,
      isOpen: editTagsModalData.isOpen,
      updateIsModalOpen,
      tags: editTagsModalData.tags,
      updateAllTags
    }
  )));
};
var RowExpander_default = RowExpander;
//# sourceMappingURL=index.js.map
