/* 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);

// src/components/EventsTable/index.tsx
var EventsTable_exports = {};
__export(EventsTable_exports, {
  default: () => EventsTable_default
});
module.exports = __toCommonJS(EventsTable_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:lodash/isArray
var isArray_exports = {};
__export(isArray_exports, {
  default: () => isArray_default
});
var defaultImport2 = __toESM(require("lodash/isArray"));
__reExport(isArray_exports, require("lodash/isArray"));
var isArray_default = "default" in defaultImport2 ? defaultImport2.default : defaultImport2;

// esm-externals:lodash/isObject
var isObject_exports = {};
__export(isObject_exports, {
  default: () => isObject_default
});
var defaultImport3 = __toESM(require("lodash/isObject"));
__reExport(isObject_exports, require("lodash/isObject"));
var isObject_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/react-ui/Table
var Table_exports = {};
__export(Table_exports, {
  default: () => Table_default
});
var defaultImport5 = __toESM(require("@splunk/react-ui/Table"));
__reExport(Table_exports, require("@splunk/react-ui/Table"));
var Table_default = "default" in defaultImport5 ? defaultImport5.default : defaultImport5;

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

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

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

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

// esm-externals:@splunk/react-ui/Link
var Link_exports = {};
__export(Link_exports, {
  default: () => Link_default
});
var defaultImport9 = __toESM(require("@splunk/react-ui/Link"));
__reExport(Link_exports, require("@splunk/react-ui/Link"));
var Link_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;

// 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;

// src/components/EventsTable/index.tsx
var TableRow = 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,
    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, rowNumbers && /* @__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(
        TableRow,
        {
          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
        },
        rowNumbers && /* @__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;
//# sourceMappingURL=index.js.map
