text: import { Injectable } from '@angular/core';
  import { Http } from '@angular/http';
  import { UserData } from './user-data';
  export var ConferenceData = (function () {
      function ConferenceData(http, user) {
          this.http = http;
          this.user = user;
      }
      ConferenceData.prototype.load = function () {
          var _this = this;
          if (this.data) {
              // already loaded data
              return Promise.resolve(this.data);
          }
          // don't have the data yet
          return new Promise(function (resolve) {
              // We're using Angular Http provider to request the data,
              // then on the response it'll map the JSON data to a parsed JS object.
              // Next we process the data and resolve the promise with the new data.
              _this.http.get('assets/data/data.json').subscribe(function (res) {
                  // we've got back the raw data, now generate the core schedule data
                  // and save the data for later reference
                  _this.data = _this.processData(res.json());
                  resolve(_this.data);
              });
          });
      };
      ConferenceData.prototype.processData = function (data) {
          // just some good 'ol JS fun with objects and arrays
          // build up the data by linking speakers to sessions
          var _this = this;
          data.tracks = [];
          // loop through each day in the schedule
          data.schedule.forEach(function (day) {
              // loop through each timeline group in the day
              day.groups.forEach(function (group) {
                  // loop through each session in the timeline group
                  group.sessions.forEach(function (session) {
                      _this.processSession(data, session);
                  });
              });
          });
          return data;
      };
      ConferenceData.prototype.processSession = function (data, session) {
          // loop through each speaker and load the speaker data
          // using the speaker name as the key
          session.speakers = [];
          if (session.speakerNames) {
              session.speakerNames.forEach(function (speakerName) {
                  var speaker = data.speakers.find(function (s) { return s.name === speakerName; });
                  if (speaker) {
                      session.speakers.push(speaker);
                      speaker.sessions = speaker.sessions || [];
                      speaker.sessions.push(session);
                  }
              });
          }
          if (session.tracks) {
              session.tracks.forEach(function (track) {
                  if (data.tracks.indexOf(track) < 0) {
                      data.tracks.push(track);
                  }
              });
          }
      };
      ConferenceData.prototype.getTimeline = function (dayIndex, queryText, excludeTracks, segment) {
          var _this = this;
          if (queryText === void 0) { queryText = ''; }
          if (excludeTracks === void 0) { excludeTracks = []; }
          if (segment === void 0) { segment = 'all'; }
          return this.load().then(function (data) {
              var day = data.schedule[dayIndex];
              day.shownSessions = 0;
              queryText = queryText.toLowerCase().replace(/,|\.|-/g, ' ');
              var queryWords = queryText.split(' ').filter(function (w) { return !!w.trim().length; });
              day.groups.forEach(function (group) {
                  group.hide = true;
                  group.sessions.forEach(function (session) {
                      // check if this session should show or not
                      _this.filterSession(session, queryWords, excludeTracks, segment);
                      if (!session.hide) {
                          // if this session is not hidden then this group should show
                          group.hide = false;
                          day.shownSessions++;
                      }
                  });
              });
              return day;
          });
      };
      ConferenceData.prototype.filterSession = function (session, queryWords, excludeTracks, segment) {
          var matchesQueryText = false;
          if (queryWords.length) {
              // of any query word is in the session name than it passes the query test
              queryWords.forEach(function (queryWord) {
                  if (session.name.toLowerCase().indexOf(queryWord) > -1) {
                      matchesQueryText = true;
                  }
              });
          }
          else {
              // if there are no query words then this session passes the query test
              matchesQueryText = true;
          }
          // if any of the sessions tracks are not in the
          // exclude tracks then this session passes the track test
          var matchesTracks = false;
          session.tracks.forEach(function (trackName) {
              if (excludeTracks.indexOf(trackName) === -1) {
                  matchesTracks = true;
              }
          });
          // if the segement is 'favorites', but session is not a user favorite
          // then this session does not pass the segment test
          var matchesSegment = false;
          if (segment === 'favorites') {
              if (this.user.hasFavorite(session.name)) {
                  matchesSegment = true;
              }
          }
          else {
              matchesSegment = true;
          }
          // all tests must be true if it should not be hidden
          session.hide = !(matchesQueryText && matchesTracks && matchesSegment);
      };
      ConferenceData.prototype.getSpeakers = function () {
          return this.load().then(function (data) {
              return data.speakers.sort(function (a, b) {
                  var aName = a.name.split(' ').pop();
                  var bName = b.name.split(' ').pop();
                  return aName.localeCompare(bName);
              });
          });
      };
      ConferenceData.prototype.getTracks = function () {
          return this.load().then(function (data) {
              return data.tracks.sort();
          });
      };
      ConferenceData.prototype.getMap = function () {
          return this.load().then(function (data) {
              return data.map;
          });
      };
      ConferenceData.decorators = [
          { type: Injectable },
      ];
      /** @nocollapse */
      ConferenceData.ctorParameters = [
          { type: Http, },
          { type: UserData, },
      ];
      return ConferenceData;
  }());
  