/*!
 * Copyright © 2024 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.
 */
module.exports =
/******/ (function(modules) { // webpackBootstrap
/******/ 	// The module cache
/******/ 	var installedModules = {};
/******/
/******/ 	// The require function
/******/ 	function __webpack_require__(moduleId) {
/******/
/******/ 		// Check if module is in cache
/******/ 		if(installedModules[moduleId]) {
/******/ 			return installedModules[moduleId].exports;
/******/ 		}
/******/ 		// Create a new module (and put it into the cache)
/******/ 		var module = installedModules[moduleId] = {
/******/ 			i: moduleId,
/******/ 			l: false,
/******/ 			exports: {}
/******/ 		};
/******/
/******/ 		// Execute the module function
/******/ 		modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ 		// Flag the module as loaded
/******/ 		module.l = true;
/******/
/******/ 		// Return the exports of the module
/******/ 		return module.exports;
/******/ 	}
/******/
/******/
/******/ 	// expose the modules object (__webpack_modules__)
/******/ 	__webpack_require__.m = modules;
/******/
/******/ 	// expose the module cache
/******/ 	__webpack_require__.c = installedModules;
/******/
/******/ 	// define getter function for harmony exports
/******/ 	__webpack_require__.d = function(exports, name, getter) {
/******/ 		if(!__webpack_require__.o(exports, name)) {
/******/ 			Object.defineProperty(exports, name, { enumerable: true, get: getter });
/******/ 		}
/******/ 	};
/******/
/******/ 	// define __esModule on exports
/******/ 	__webpack_require__.r = function(exports) {
/******/ 		if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ 			Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ 		}
/******/ 		Object.defineProperty(exports, '__esModule', { value: true });
/******/ 	};
/******/
/******/ 	// create a fake namespace object
/******/ 	// mode & 1: value is a module id, require it
/******/ 	// mode & 2: merge all properties of value into the ns
/******/ 	// mode & 4: return value when already ns object
/******/ 	// mode & 8|1: behave like require
/******/ 	__webpack_require__.t = function(value, mode) {
/******/ 		if(mode & 1) value = __webpack_require__(value);
/******/ 		if(mode & 8) return value;
/******/ 		if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
/******/ 		var ns = Object.create(null);
/******/ 		__webpack_require__.r(ns);
/******/ 		Object.defineProperty(ns, 'default', { enumerable: true, value: value });
/******/ 		if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
/******/ 		return ns;
/******/ 	};
/******/
/******/ 	// getDefaultExport function for compatibility with non-harmony modules
/******/ 	__webpack_require__.n = function(module) {
/******/ 		var getter = module && module.__esModule ?
/******/ 			function getDefault() { return module['default']; } :
/******/ 			function getModuleExports() { return module; };
/******/ 		__webpack_require__.d(getter, 'a', getter);
/******/ 		return getter;
/******/ 	};
/******/
/******/ 	// Object.prototype.hasOwnProperty.call
/******/ 	__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ 	// __webpack_public_path__
/******/ 	__webpack_require__.p = "";
/******/
/******/
/******/ 	// Load entry module and return exports
/******/ 	return __webpack_require__(__webpack_require__.s = 20);
/******/ })
/************************************************************************/
/******/ ({

/***/ 0:
/***/ (function(module, exports) {

module.exports = require("react");

/***/ }),

/***/ 20:
/***/ (function(module, exports, __webpack_require__) {

"use strict";


Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.convertToDashboardJSON = exports.extractDataFromReactCode = exports.formatCodeStringToObject = exports.extractDocItems = exports.getFormatterClassdesc = void 0;

var React = __webpack_require__(0);

var UtilPage_1 = __webpack_require__(21);

var sharedSelectors = ['getField', 'getType', 'min', 'max'];

var formatSidebarItemName = function formatSidebarItemName(name, className) {
  return sharedSelectors.find(function (sharedSelector) {
    return name === sharedSelector;
  }) ? "".concat(className, "#").concat(name) : name;
};

var removePrependedClassName = function removePrependedClassName() {
  var longname = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
  return longname.slice(longname.indexOf('#') + 1);
};

var formatDSLSelectorDocs = function formatDSLSelectorDocs(docs) {
  return docs.map(function (doc) {
    return Object.assign(Object.assign({}, doc), {
      longname: removePrependedClassName(doc.longname)
    });
  });
};

var getFormatterClassdesc = function getFormatterClassdesc(formatterDocs, name) {
  return {
    name: name,
    markdown: "# ".concat(name, "\n ").concat(formatterDocs.find(function (doc) {
      return doc.name === name && doc.kind === 'class';
    }).classdesc)
  };
};

exports.getFormatterClassdesc = getFormatterClassdesc;

var extractDocItems = function extractDocItems(docs, className) {
  var classHeaderDoc = docs[0];
  var fileDoc = docs[docs.length - 1];
  var filteredDocs = formatDSLSelectorDocs(docs).filter(function (_ref) {
    var access = _ref.access,
        comment = _ref.comment;
    return access === 'public' && comment;
  });
  return filteredDocs.map(function (doc) {
    return {
      name: formatSidebarItemName(doc.name, className),
      component: function UtilDoc() {
        // named function so linter doesnt raise react/display-name error
        return React.createElement(UtilPage_1.default, {
          title: "".concat(className, "#").concat(doc.name),
          status: 1,
          docs: [classHeaderDoc, doc, fileDoc]
        });
      }
    };
  }).sort(function (a, b) {
    return a.name.localeCompare(b.name);
  });
};

exports.extractDocItems = extractDocItems;

var formatCodeStringToObject = function formatCodeStringToObject(codeString, regexMatch) {
  var match = regexMatch.exec(codeString);
  if (!match) return null;
  var stringToParse = "{".concat(match[1], "}"); // remove trailing commas

  var removedCommas = stringToParse.replace(/,(?!\s*?[-{["'\w])/g, ''); // convert double quotes (which only occur inside strings) to back quotes

  var backQuotes = removedCommas.replace(/"/g, '`'); // replace single quotes with double quotes

  var doubleQuotes = backQuotes.replace(/'/g, '"'); // replace back quotes with single quotes

  var singleQuotes = doubleQuotes.replace(/`/g, "'"); // add quotes around keys

  var quotesAroundKeys = singleQuotes.replace(/\b(\w+)\s*:(?=\s)/g, '"$1":');
  var retval = null;

  try {
    retval = JSON.parse(quotesAroundKeys);
  } catch (e) {
    // eslint-disable-next-line no-console
    console.error(e);
  }

  return retval;
};

exports.formatCodeStringToObject = formatCodeStringToObject;

var extractDataFromReactCode = function extractDataFromReactCode(codeString) {
  var _a;

  var primaryRegex = /dataSources={{([\s\S]*?primary:[\s\S]*?)}}/;

  var _ref2 = (_a = (0, exports.formatCodeStringToObject)(codeString, primaryRegex)) !== null && _a !== void 0 ? _a : {},
      primary = _ref2.primary;

  var optionsRegex = /options={{([\s\S]*?)}}/;
  var options = (0, exports.formatCodeStringToObject)(codeString, optionsRegex);
  var contextRegex = /context={{([\s\S]*?)}}/;
  var context = (0, exports.formatCodeStringToObject)(codeString, contextRegex);
  return {
    primary: primary,
    options: options,
    context: context
  };
};

exports.extractDataFromReactCode = extractDataFromReactCode; // Takes a stringified react viz example and a viz type
// Returns a dashboard definition object.
// e.g. codeString: '<Area dataSources={{}} options={{}} />'
//      type: 'splunk.area'

var convertToDashboardJSON = function convertToDashboardJSON(codeString, type) {
  var _ref3 = (0, exports.extractDataFromReactCode)(codeString),
      options = _ref3.options,
      primary = _ref3.primary,
      context = _ref3.context;

  return Object.assign(Object.assign({
    visualizations: {
      test_viz: Object.assign(Object.assign(Object.assign({
        type: type
      }, options ? {
        options: options
      } : {}), primary ? {
        dataSources: {
          primary: 'primary'
        }
      } : {}), context ? {
        context: context
      } : {})
    }
  }, primary ? {
    dataSources: {
      primary: {
        type: 'ds.test',
        options: primary
      }
    }
  } : {}), {
    defaults: {
      dataSources: {
        global: {
          options: {
            queryParameters: {
              latest: '$global_time.latest$',
              earliest: '$global_time.earliest$'
            }
          }
        }
      }
    },
    inputs: {
      input_global_trp: {
        type: 'input.timerange',
        options: {
          token: 'global_time',
          defaultValue: '-24h@h,now'
        },
        title: 'Global Time Range'
      }
    },
    layout: {
      type: 'absolute',
      options: {},
      structure: [{
        item: 'test_viz',
        type: 'block',
        position: {
          x: 0,
          y: 0,
          w: 800,
          h: 500
        }
      }],
      globalInputs: ['input_global_trp']
    }
  });
};

exports.convertToDashboardJSON = convertToDashboardJSON;

/***/ }),

/***/ 21:
/***/ (function(module, exports) {

module.exports = require("@splunk/react-docs/UtilPage");

/***/ })

/******/ });
//# sourceMappingURL=docUtils.js.map