/**
 * @file 文本軌道列表.js
 */
從 './track-list' 導入 TrackList;

/**
 * 媒體文件的當前 {@link TextTrack} 列表。
 *
 * @see [規範]{@link https://html.spec.whatwg.org/multipage/embedded-content.html#texttracklist}
 * @extends 曲目列表
 */
類 TextTrackList 擴展 TrackList {

  /**
   * 添加 {@link TextTrack} 到 `TextTrackList`
   *
   * @param {TextTrack} 軌道
   * 要添加到列表中的文本軌道。
   *
   * @fires TrackList#addtrack
   */
  添加軌道(軌道){
    super.addTrack(軌道);

    如果(!this.queueChange_){
      this.queueChange_ = () => this.queueTrigger('change');
    }
    如果(!this.triggerSelectedlanguagechange){
      this.triggerSelectedlanguagechange_ = () => this.trigger('selectedlanguagechange');
    }

    /**
     * @listens TextTrack#modechange
     * @fires 曲目列表#change
     */
    track.addEventListener('modechange', this.queueChange_);
    const nonLanguageTextTrackKind = ['元數據', '章節'];

    如果 (nonLanguageTextTrackKind.indexOf(track.kind) === -1) {
      track.addEventListener('modechange', this.triggerSelectedlanguagechange_);
    }
  }

  removeTrack(rtrack){
    super.removeTrack(rtrack);

    // 手動刪除我們添加的事件處理程序
    如果(rtrack.removeEventListener){
      如果(this.queueChange_){
        rtrack.removeEventListener('modechange', this.queueChange_);
      }
      如果(this.selectedlanguagechange_){
        rtrack.removeEventListener('modechange', this.triggerSelectedlanguagechange_);
      }
    }
  }
}
導出默認的 TextTrackList;