/*!
 * 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 = 48);
/******/ })
/************************************************************************/
/******/ ({

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

module.exports = require("react");

/***/ }),

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

module.exports = require("prop-types");

/***/ }),

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

/***/ }),

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

"use strict";


var _slicedToArray = __webpack_require__(8);

Object.defineProperty(exports, "__esModule", {
  value: true
});

var React = __webpack_require__(0);

var DocExample_1 = __webpack_require__(49);

var Button_1 = __webpack_require__(50);

var Code_1 = __webpack_require__(51);

var TransitionOpen_1 = __webpack_require__(52);

var SquaresLayered_1 = __webpack_require__(53);

var Checkmark_1 = __webpack_require__(54);

var EyeSlashed_1 = __webpack_require__(55);

var WindowChevronsSlash_1 = __webpack_require__(56);

var i18n_1 = __webpack_require__(5);

var T = __webpack_require__(1);

var docUtils_1 = __webpack_require__(20);

var DocExampleWithVizSandbox = function DocExampleWithVizSandbox(props) {
  var type = props.type,
      title = props.title,
      code = props.code,
      example = props.example,
      _props$hideSandbox = props.hideSandbox,
      hideSandbox = _props$hideSandbox === void 0 ? false : _props$hideSandbox,
      description = props.description;

  var _React$useState = React.useState(false),
      _React$useState2 = _slicedToArray(_React$useState, 2),
      isCopied = _React$useState2[0],
      setIsCopied = _React$useState2[1];

  var _React$useState3 = React.useState(false),
      _React$useState4 = _slicedToArray(_React$useState3, 2),
      showCode = _React$useState4[0],
      setShowCode = _React$useState4[1];

  var isMounted = React.useRef(true);
  var toggleShowCode = React.useCallback(function () {
    setShowCode(function (state) {
      return !state;
    });
  }, []);
  React.useEffect(function () {
    return function () {
      isMounted.current = false;
      setIsCopied(false);
    }; // eslint-disable-next-line react-hooks/exhaustive-deps
  }, []);
  if (hideSandbox) return React.createElement(DocExample_1.default, {
    title: title,
    code: code,
    example: example
  });
  var objDefn = (0, docUtils_1.convertToDashboardJSON)(code, type); // set spacing level to 4

  var prettyJson = JSON.stringify(objDefn, null, 4);

  var copyToClipBoard = function copyToClipBoard() {
    if ('clipboard' in navigator) {
      navigator.clipboard.writeText(prettyJson);
      setIsCopied(true);
    }

    setTimeout(function () {
      if (isMounted.current) {
        setIsCopied(false);
      }
    }, 5000);
  };

  var renderAdditionalActions = function renderAdditionalActions() {
    return [React.createElement(Button_1.default, {
      key: "show-dashboard-definition",
      appearance: "toggle",
      onClick: toggleShowCode,
      icon: showCode ? React.createElement(EyeSlashed_1.default, null) : React.createElement(WindowChevronsSlash_1.default, null),
      label: showCode ? (0, i18n_1._)('Hide dashboard definition') : (0, i18n_1._)('Show dashboard definition')
    })];
  };

  return React.createElement(DocExample_1.default, {
    renderAdditionalActions: renderAdditionalActions,
    title: title,
    code: code,
    example: example,
    description: description
  }, React.createElement(TransitionOpen_1.default, {
    animation: "slideFromTop",
    open: showCode,
    retainFocus: false,
    takeFocus: false,
    renderChildrenWhenCollapsed: false,
    animateOnMount: false
  }, React.createElement("div", {
    style: {
      display: 'flex',
      justifyContent: 'space-between'
    }
  }, React.createElement(Code_1.default, {
    value: prettyJson,
    language: "json"
  }), React.createElement(Button_1.default, {
    onClick: copyToClipBoard,
    icon: isCopied ? React.createElement(Checkmark_1.default, null) : React.createElement(SquaresLayered_1.default, null),
    label: isCopied ? (0, i18n_1._)('Copied') : (0, i18n_1._)('Copy to clipboard'),
    style: {
      height: '30px',
      maxWidth: '164px'
    }
  }))));
};

DocExampleWithVizSandbox.propTypes = {
  type: T.string,
  title: T.string,
  code: T.string,
  example: T.func,
  hideSandbox: T.bool
};
exports.default = DocExampleWithVizSandbox;

/***/ }),

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

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

/***/ }),

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

module.exports = require("@splunk/ui-utils/i18n");

/***/ }),

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

module.exports = require("@splunk/react-ui/Button");

/***/ }),

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

module.exports = require("@splunk/react-ui/Code");

/***/ }),

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

module.exports = require("@splunk/react-ui/TransitionOpen");

/***/ }),

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

module.exports = require("@splunk/react-icons/SquaresLayered");

/***/ }),

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

module.exports = require("@splunk/react-icons/Checkmark");

/***/ }),

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

module.exports = require("@splunk/react-icons/EyeSlashed");

/***/ }),

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

module.exports = require("@splunk/react-icons/WindowChevronsSlash");

/***/ }),

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

module.exports = require("@babel/runtime/helpers/slicedToArray");

/***/ })

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