'use strict';

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

var _DataView = require('./_DataView.js');
var _Map = require('./_Map.js');
var _Promise = require('./_Promise.js');
var _Set = require('./_Set.js');
var _WeakMap = require('./_WeakMap.js');
var _baseGetTag = require('./_baseGetTag.js');
var _toSource = require('./_toSource.js');

/** `Object#toString` result references. */
var mapTag = '[object Map]',
    objectTag = '[object Object]',
    promiseTag = '[object Promise]',
    setTag = '[object Set]',
    weakMapTag = '[object WeakMap]';

var dataViewTag = '[object DataView]';

/** Used to detect maps, sets, and weakmaps. */
var dataViewCtorString = _toSource.default(_DataView.default),
    mapCtorString = _toSource.default(_Map.default),
    promiseCtorString = _toSource.default(_Promise.default),
    setCtorString = _toSource.default(_Set.default),
    weakMapCtorString = _toSource.default(_WeakMap.default);

/**
 * Gets the `toStringTag` of `value`.
 *
 * @private
 * @param {*} value The value to query.
 * @returns {string} Returns the `toStringTag`.
 */
exports.default = _baseGetTag.default;

// Fallback for data views, maps, sets, and weak maps in IE 11 and promises in Node.js < 6.
if ((_DataView.default && exports.default(new _DataView.default(new ArrayBuffer(1))) != dataViewTag) ||
    (_Map.default && exports.default(new _Map.default) != mapTag) ||
    (_Promise.default && exports.default(_Promise.default.resolve()) != promiseTag) ||
    (_Set.default && exports.default(new _Set.default) != setTag) ||
    (_WeakMap.default && exports.default(new _WeakMap.default) != weakMapTag)) {
  exports.default = function(value) {
    var result = _baseGetTag.default(value),
        Ctor = result == objectTag ? value.constructor : undefined,
        ctorString = Ctor ? _toSource.default(Ctor) : '';

    if (ctorString) {
      switch (ctorString) {
        case dataViewCtorString: return dataViewTag;
        case mapCtorString: return mapTag;
        case promiseCtorString: return promiseTag;
        case setCtorString: return setTag;
        case weakMapCtorString: return weakMapTag;
      }
    }
    return result;
  };
}
