'use strict';

(({ App, _ }) => {
  const { utils } = App.Inspector;

  const replacer = (key, value) => {
    const type = utils.typeOf(value);

    if ((type === 'object' || type === 'array') && _.size(value) > 100) {
      if (type === 'array') return value.slice(0, 100);
      const clone = Object.assign({}, value);
      delete clone['__length__'];
      return clone;
    }

    return value;
  };

  App.Inspector.utils.copy = (value) => {
    BrowserAutomationStudio_SetClipboard(
      utf8_to_b64(value == null || typeof value === 'string' ? `${value}` : JSON.stringify(value, replacer)),
      false,
      true
    );
  };
})(window);
