/* 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 __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/MockedProvider.js
var MockedProvider_exports = {};
__export(MockedProvider_exports, {
  default: () => MockedProvider_default
});
module.exports = __toCommonJS(MockedProvider_exports);

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

// esm-externals:@splunk/visualization-context/Provider
var Provider_exports = {};
__export(Provider_exports, {
  default: () => Provider_default
});
var defaultImport2 = __toESM(require("@splunk/visualization-context/Provider"));
__reExport(Provider_exports, require("@splunk/visualization-context/Provider"));
var Provider_default = "default" in defaultImport2 ? defaultImport2.default : defaultImport2;

// src/MockedProvider.js
var MockedProvider = class extends Provider_default {
  constructor() {
    super();
    this.id = 0;
    this.items = {};
  }
  /**
   * return provider type
   */
  getType() {
    return "mock";
  }
  upload(dataURI, metaData) {
    try {
      const obj = { dataURI, metaData };
      const { id, items } = this;
      this.items = __spreadProps(__spreadValues({}, items), { [id]: obj });
      this.id += 1;
      return id;
    } catch (error) {
      throw new Error((0, i18n_exports._)("The obj cannot be uploaded."));
    }
  }
  /**
   * get by id
   */
  getById(id) {
    if (this.items[id]) {
      return this.items[id];
    }
    throw new Error((0, i18n_exports._)("The obj is not found."));
  }
  /**
   * get all obj ids
   */
  listIds({ offset = 0, count = 100, meta = [], search = null }) {
    try {
      const icons = __spreadValues({}, this.items);
      const results = [];
      Object.keys(icons).slice(offset, count).forEach((id) => {
        const icon = { id };
        const iconMeta = icons[id].metaData || {};
        const isSearchedIcon = search != null && Object.keys(iconMeta).some((attr) => {
          const iconMetaValue = iconMeta[attr].toLowerCase();
          return iconMetaValue.indexOf(search.toLowerCase()) > -1;
        });
        if (search == null || isSearchedIcon) {
          if (meta && meta.length) {
            icon.metaData = {};
            meta.forEach((attr) => {
              if (iconMeta[attr] != null) {
                icon.metaData[attr] = iconMeta[attr];
              }
            });
          }
          results.push(icon);
        }
      });
      return results;
    } catch (error) {
      throw new Error((0, i18n_exports._)("The ids cannot be listed."));
    }
  }
  /**
   * delete by id
   */
  deleteById(id) {
    try {
      const obj = this.getById(id);
      delete this.items[id];
      return obj;
    } catch (error) {
      throw new Error((0, i18n_exports._)("The obj cannot be deleted."));
    }
  }
  clean() {
    this.id = 0;
    this.items = {};
  }
};
var MockedProvider_default = MockedProvider;
//# sourceMappingURL=MockedProvider.js.map
