/*!
 * Copyright © 2018 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 = 23);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ (function(module, exports) {

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

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

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

/***/ }),
/* 2 */
/***/ (function(module, exports) {

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

/***/ }),
/* 3 */
/***/ (function(module, exports) {

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

/***/ }),
/* 4 */
/***/ (function(module, exports) {

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

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

module.exports = require("@splunk/visualization-context/Provider");

/***/ }),
/* 6 */
/***/ (function(module, exports) {

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

/***/ }),
/* 7 */
/***/ (function(module, exports) {

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

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

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

/***/ }),
/* 9 */
/***/ (function(module, exports) {

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

/***/ }),
/* 10 */
/***/ (function(module, exports) {

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

/***/ }),
/* 11 */,
/* 12 */
/***/ (function(module, __webpack_exports__, __webpack_require__) {

"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1);
/* harmony import */ var _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_0__);
/* harmony import */ var _babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(4);
/* harmony import */ var _babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_1__);
/* harmony import */ var _babel_runtime_helpers_slicedToArray__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(10);
/* harmony import */ var _babel_runtime_helpers_slicedToArray__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_slicedToArray__WEBPACK_IMPORTED_MODULE_2__);
/* harmony import */ var _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(2);
/* harmony import */ var _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_3__);
/* harmony import */ var _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(3);
/* harmony import */ var _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_4__);
/* harmony import */ var _splunk_ui_utils_i18n__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(0);
/* harmony import */ var _splunk_ui_utils_i18n__WEBPACK_IMPORTED_MODULE_5___default = /*#__PURE__*/__webpack_require__.n(_splunk_ui_utils_i18n__WEBPACK_IMPORTED_MODULE_5__);
/* harmony import */ var _splunk_visualization_context_Provider__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(5);
/* harmony import */ var _splunk_visualization_context_Provider__WEBPACK_IMPORTED_MODULE_6___default = /*#__PURE__*/__webpack_require__.n(_splunk_visualization_context_Provider__WEBPACK_IMPORTED_MODULE_6__);






/* eslint-disable class-methods-use-this */


/**
 * Base Registry
 */

var BaseRegistry =
/*#__PURE__*/
function () {
  function BaseRegistry() {
    _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_3___default()(this, BaseRegistry);

    this.cachedProviders = {};
    this.defaultProvider = null;
  }

  _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_4___default()(BaseRegistry, [{
    key: "isValidProvider",

    /**
     * check whether user defined provider extends the base provider
     * @param {Provider} provider
     * @returns {Boolean}
     */
    value: function isValidProvider(provider) {
      if (provider instanceof _splunk_visualization_context_Provider__WEBPACK_IMPORTED_MODULE_6___default.a) {
        return true;
      }

      throw new Error(Object(_splunk_ui_utils_i18n__WEBPACK_IMPORTED_MODULE_5__["_"])('Invalid Provider'));
    }
    /**
     * add default provider to cache
     * @param {Provider} provider
     */

  }, {
    key: "addDefaultProvider",
    value: function addDefaultProvider(provider) {
      if (this.isValidProvider(provider)) {
        this.addProvider(provider);
        this.defaultProvider = provider;
      }
    }
    /**
     * add provider to cache
     * @param {Provider} provider
     */

  }, {
    key: "addProvider",
    value: function addProvider(provider) {
      if (this.isValidProvider(provider)) {
        if (this.cachedProviders[provider.getType()]) {
          // eslint-disable-next-line
          console.warn("The provider \"".concat(provider.getType(), "\" existed already."));
        }

        this.cachedProviders[provider.getType()] = provider;
      }
    }
    /**
     * delete provider
     * @param {String} providerType
     */

  }, {
    key: "deleteProvider",
    value: function deleteProvider(providerType) {
      var cachedProvider = this.cachedProviders[providerType];

      if (!cachedProvider) {
        // eslint-disable-next-line
        console.warn("The provider \"".concat(providerType, "\" does not existed"));
        return;
      }

      if (this.defaultProvider && providerType === this.defaultProvider.getType()) {
        this.defaultProvider = null;
      }

      delete this.cachedProviders[providerType];
    }
    /**
     * find provider from cache
     * @param {String} type
     * @returns {Provider} provider
     */

  }, {
    key: "findProvider",
    value: function findProvider(type) {
      var provider = this.cachedProviders[type];

      if (provider) {
        return provider;
      }

      throw new Error(Object(_splunk_ui_utils_i18n__WEBPACK_IMPORTED_MODULE_5__["_"])('Provider not found'));
    }
    /**
     * list all providers
     * @return {Object} provider = { type: 'local', isDefault: true }
     */

  }, {
    key: "listProviders",
    value: function listProviders() {
      var _this = this;

      return Object.keys(this.cachedProviders).map(function (type) {
        return {
          type: type,
          isDefault: type === _this.defaultProvider.getType()
        };
      });
    }
    /**
     * check whether src is a http url or a url used for icon/image-registry (e.g. 'kvstore://image123')
     */

  }, {
    key: "isResourceURL",
    value: function isResourceURL(url) {
      if (!url || url.indexOf('://') < 0) {
        return false;
      }

      var _this$parseURL = this.parseURL(url),
          type = _this$parseURL.type;

      return type !== 'http' && type !== 'https';
    }
    /**
     * parse provider type and id from the url
     * @params {String} url     'kvstore://image123'
     * @returns {Object} obj
     * @returns {String} obj.type   'kvstore'
     * @returns {String} obj.id     'image123'
     */

  }, {
    key: "parseURL",
    value: function parseURL(url) {
      if (url) {
        var _url$split = url.split('://'),
            _url$split2 = _babel_runtime_helpers_slicedToArray__WEBPACK_IMPORTED_MODULE_2___default()(_url$split, 2),
            type = _url$split2[0],
            id = _url$split2[1];

        if (type && id) {
          return {
            type: type,
            id: id
          };
        }
      }

      throw new Error(Object(_splunk_ui_utils_i18n__WEBPACK_IMPORTED_MODULE_5__["_"])('Invalid url'));
    }
    /**
     * upload
     * @param {DataURI} dataURI
     * @param {Object} metaData
     * @param {String} providerType      e.g. 'kvstore' or 'sui' or 'local'
     * @returns {String} id               e.g. 'kvstore://image123'
     */

  }, {
    key: "upload",
    value: function () {
      var _upload = _babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_1___default()(
      /*#__PURE__*/
      _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_0___default.a.mark(function _callee(dataURI, metaData, providerType) {
        var provider, id;
        return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_0___default.a.wrap(function _callee$(_context) {
          while (1) {
            switch (_context.prev = _context.next) {
              case 0:
                if (!(providerType == null && this.defaultProvider == null)) {
                  _context.next = 2;
                  break;
                }

                throw new Error(Object(_splunk_ui_utils_i18n__WEBPACK_IMPORTED_MODULE_5__["_"])('No valid provider was found. Please add a provider'));

              case 2:
                provider = providerType ? this.findProvider(providerType) : this.defaultProvider;
                _context.next = 5;
                return provider.upload(dataURI, metaData);

              case 5:
                id = _context.sent;
                return _context.abrupt("return", "".concat(provider.getType(), "://").concat(id));

              case 7:
              case "end":
                return _context.stop();
            }
          }
        }, _callee, this);
      }));

      function upload(_x, _x2, _x3) {
        return _upload.apply(this, arguments);
      }

      return upload;
    }()
    /**
     * get object by url
     * @param {String} url     'kvstore://image123'
     * @returns {Object} obj    e.g. an image object or icon
     */

  }, {
    key: "getByURL",
    value: function () {
      var _getByURL = _babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_1___default()(
      /*#__PURE__*/
      _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_0___default.a.mark(function _callee2(url) {
        var _this$parseURL2, type, id, provider, obj;

        return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_0___default.a.wrap(function _callee2$(_context2) {
          while (1) {
            switch (_context2.prev = _context2.next) {
              case 0:
                _this$parseURL2 = this.parseURL(url), type = _this$parseURL2.type, id = _this$parseURL2.id;
                provider = this.findProvider(type);
                _context2.next = 4;
                return provider.getById(id);

              case 4:
                obj = _context2.sent;
                return _context2.abrupt("return", obj);

              case 6:
              case "end":
                return _context2.stop();
            }
          }
        }, _callee2, this);
      }));

      function getByURL(_x4) {
        return _getByURL.apply(this, arguments);
      }

      return getByURL;
    }()
    /**
     * delete object by url
     * @param {String} url     'kvstore://image123' || 'sui://icon123'
     * @returns {Object} obj    e.g. an image object or icon
     */

  }, {
    key: "deleteByURL",
    value: function () {
      var _deleteByURL = _babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_1___default()(
      /*#__PURE__*/
      _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_0___default.a.mark(function _callee3(url) {
        var _this$parseURL3, type, id, provider, obj;

        return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_0___default.a.wrap(function _callee3$(_context3) {
          while (1) {
            switch (_context3.prev = _context3.next) {
              case 0:
                _this$parseURL3 = this.parseURL(url), type = _this$parseURL3.type, id = _this$parseURL3.id;
                provider = this.findProvider(type);
                _context3.next = 4;
                return provider.deleteById(id);

              case 4:
                obj = _context3.sent;
                return _context3.abrupt("return", obj);

              case 6:
              case "end":
                return _context3.stop();
            }
          }
        }, _callee3, this);
      }));

      function deleteByURL(_x5) {
        return _deleteByURL.apply(this, arguments);
      }

      return deleteByURL;
    }()
    /**
     * list all object ids
     * @params {String} providerType       e.g. 'kvstore' or 'sui'
     * @params {Object} options
     * @returns {Array} ids
     */

  }, {
    key: "listIds",
    value: function () {
      var _listIds = _babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_1___default()(
      /*#__PURE__*/
      _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_0___default.a.mark(function _callee4(providerType) {
        var options,
            provider,
            ids,
            _args4 = arguments;
        return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_0___default.a.wrap(function _callee4$(_context4) {
          while (1) {
            switch (_context4.prev = _context4.next) {
              case 0:
                options = _args4.length > 1 && _args4[1] !== undefined ? _args4[1] : {
                  offset: 0,
                  count: 100
                };
                provider = this.findProvider(providerType);
                _context4.next = 4;
                return provider.listIds(options);

              case 4:
                ids = _context4.sent;
                return _context4.abrupt("return", ids);

              case 6:
              case "end":
                return _context4.stop();
            }
          }
        }, _callee4, this);
      }));

      function listIds(_x6) {
        return _listIds.apply(this, arguments);
      }

      return listIds;
    }()
  }], [{
    key: "create",
    value: function create() {
      return new BaseRegistry();
    }
  }]);

  return BaseRegistry;
}();

/* harmony default export */ __webpack_exports__["default"] = (BaseRegistry);

/***/ }),
/* 13 */,
/* 14 */
/***/ (function(module, exports) {

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

/***/ }),
/* 15 */,
/* 16 */,
/* 17 */,
/* 18 */,
/* 19 */,
/* 20 */,
/* 21 */,
/* 22 */,
/* 23 */
/***/ (function(module, __webpack_exports__, __webpack_require__) {

"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(2);
/* harmony import */ var _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0__);
/* harmony import */ var _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(3);
/* harmony import */ var _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1__);
/* harmony import */ var _babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(7);
/* harmony import */ var _babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2__);
/* harmony import */ var _babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(6);
/* harmony import */ var _babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3__);
/* harmony import */ var _babel_runtime_helpers_get__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(14);
/* harmony import */ var _babel_runtime_helpers_get__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_get__WEBPACK_IMPORTED_MODULE_4__);
/* harmony import */ var _babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(8);
/* harmony import */ var _babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_5___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_5__);
/* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(9);
/* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_6___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_6__);
/* harmony import */ var _splunk_ui_utils_i18n__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(0);
/* harmony import */ var _splunk_ui_utils_i18n__WEBPACK_IMPORTED_MODULE_7___default = /*#__PURE__*/__webpack_require__.n(_splunk_ui_utils_i18n__WEBPACK_IMPORTED_MODULE_7__);
/* harmony import */ var _BaseRegistry__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(12);








/* eslint-disable class-methods-use-this */


/**
 * Icon Registry
 */

var IconRegistry =
/*#__PURE__*/
function (_BaseRegistry) {
  _babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_5___default()(IconRegistry, _BaseRegistry);

  function IconRegistry() {
    _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0___default()(this, IconRegistry);

    return _babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2___default()(this, _babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3___default()(IconRegistry).apply(this, arguments));
  }

  _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1___default()(IconRegistry, [{
    key: "isValidMediaType",

    /**
     * check if the the media type from the dataURI belongs to the supported types
     * @param {DataURI} dataURI
     * @returns {Boolean}
     */
    value: function isValidMediaType(dataURI) {
      return IconRegistry.VALID_MEDIA_TYPES.some(function (type) {
        return dataURI.indexOf("image/".concat(type)) > -1;
      });
    }
    /**
     * upload image if the image format is supported
     * @param {DataURI} dataURI
     * @param {Object} metaData
     * @param {String} providerType   e.g. 'kvstore', or 'sui'
     * @returns {String} id           e.g. 'kvstore://image123'
     */

  }, {
    key: "upload",
    value: function upload(dataURI, metaData, providerType) {
      if (!this.isValidMediaType(dataURI)) {
        throw new Error(Object(_splunk_ui_utils_i18n__WEBPACK_IMPORTED_MODULE_7__["_"])('The format of the uploaded file is not supported. Please upload svg file.'));
      }

      return _babel_runtime_helpers_get__WEBPACK_IMPORTED_MODULE_4___default()(_babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3___default()(IconRegistry.prototype), "upload", this).call(this, dataURI, metaData, providerType);
    }
  }], [{
    key: "create",
    value: function create() {
      return new IconRegistry();
    }
  }]);

  return IconRegistry;
}(_BaseRegistry__WEBPACK_IMPORTED_MODULE_8__["default"]);

_babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_6___default()(IconRegistry, "VALID_MEDIA_TYPES", ['svg']);

/* harmony default export */ __webpack_exports__["default"] = (IconRegistry);

/***/ })
/******/ ]);
//# sourceMappingURL=IconRegistry.js.map