text: 'use strict';
  
  exports.__esModule = true;
  
  var _eventTarget = require('../event-target');
  
  var _eventTarget2 = _interopRequireDefault(_eventTarget);
  
  var _browser = require('../utils/browser.js');
  
  var browser = _interopRequireWildcard(_browser);
  
  var _document = require('global/document');
  
  var _document2 = _interopRequireDefault(_document);
  
  function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj['default'] = obj; return newObj; } }
  
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  
  function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  
  function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } /**
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  * @file track-list.js
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  */
  
  
  /**
   * Common functionaliy between {@link TextTrackList}, {@link AudioTrackList}, and
   * {@link VideoTrackList}
   *
   * @extends EventTarget
   */
  var TrackList = function (_EventTarget) {
    _inherits(TrackList, _EventTarget);
  
    /**
     * Create an instance of this class
     *
     * @param {Track[]} tracks
     *        A list of tracks to initialize the list with.
     *
     * @param {Object} [list]
     *        The child object with inheritance done manually for ie8.
     *
     * @abstract
     */
    function TrackList() {
      var tracks = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
  
      var _ret;
  
      var list = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
  
      _classCallCheck(this, TrackList);
  
      var _this = _possibleConstructorReturn(this, _EventTarget.call(this));
  
      if (!list) {
        list = _this; // eslint-disable-line
        if (browser.IS_IE8) {
          list = _document2['default'].createElement('custom');
          for (var prop in TrackList.prototype) {
            if (prop !== 'constructor') {
              list[prop] = TrackList.prototype[prop];
            }
          }
        }
      }
  
      list.tracks_ = [];
  
      /**
       * @member {number} length
       *         The current number of `Track`s in the this Trackist.
       */
      Object.defineProperty(list, 'length', {
        get: function get() {
          return this.tracks_.length;
        }
      });
  
      for (var i = 0; i < tracks.length; i++) {
        list.addTrack_(tracks[i]);
      }
  
      // must return the object, as for ie8 it will not be this
      // but a reference to a document object
      return _ret = list, _possibleConstructorReturn(_this, _ret);
    }
  
    /**
     * Add a {@link Track} to the `TrackList`
     *
     * @param {Track} track
     *        The audio, video, or text track to add to the list.
     *
     * @fires TrackList#addtrack
     * @private
     */
  
  
    TrackList.prototype.addTrack_ = function addTrack_(track) {
      var index = this.tracks_.length;
  
      if (!('' + index in this)) {
        Object.defineProperty(this, index, {
          get: function get() {
            return this.tracks_[index];
          }
        });
      }
  
      // Do not add duplicate tracks
      if (this.tracks_.indexOf(track) === -1) {
        this.tracks_.push(track);
        /**
         * Triggered when a track is added to a track list.
         *
         * @event TrackList#addtrack
         * @type {EventTarget~Event}
         * @property {Track} track
         *           A reference to track that was added.
         */
        this.trigger({
          track: track,
          type: 'addtrack'
        });
      }
    };
  
    /**
     * Remove a {@link Track} from the `TrackList`
     *
     * @param {Track} track
     *        The audio, video, or text track to remove from the list.
     *
     * @fires TrackList#removetrack
     * @private
     */
  
  
    TrackList.prototype.removeTrack_ = function removeTrack_(rtrack) {
      var track = void 0;
  
      for (var i = 0, l = this.length; i < l; i++) {
        if (this[i] === rtrack) {
          track = this[i];
          if (track.off) {
            track.off();
          }
  
          this.tracks_.splice(i, 1);
  
          break;
        }
      }
  
      if (!track) {
        return;
      }
  
      /**
       * Triggered when a track is removed from track list.
       *
       * @event TrackList#removetrack
       * @type {EventTarget~Event}
       * @property {Track} track
       *           A reference to track that was removed.
       */
      this.trigger({
        track: track,
        type: 'removetrack'
      });
    };
  
    /**
     * Get a Track from the TrackList by a tracks id
     *
     * @param {String} id - the id of the track to get
     * @method getTrackById
     * @return {Track}
     * @private
     */
  
  
    TrackList.prototype.getTrackById = function getTrackById(id) {
      var result = null;
  
      for (var i = 0, l = this.length; i < l; i++) {
        var track = this[i];
  
        if (track.id === id) {
          result = track;
          break;
        }
      }
  
      return result;
    };
  
    return TrackList;
  }(_eventTarget2['default']);
  
  /**
   * Triggered when a different track is selected/enabled.
   *
   * @event TrackList#change
   * @type {EventTarget~Event}
   */
  
  /**
   * Events that can be called with on + eventName. See {@link EventHandler}.
   *
   * @property {Object} TrackList#allowedEvents_
   * @private
   */
  
  
  TrackList.prototype.allowedEvents_ = {
    change: 'change',
    addtrack: 'addtrack',
    removetrack: 'removetrack'
  };
  
  // emulate attribute EventHandler support to allow for feature detection
  for (var event in TrackList.prototype.allowedEvents_) {
    TrackList.prototype['on' + event] = null;
  }
  
  exports['default'] = TrackList;
  