text: 'use.strict'
  var __importDefault = (this && this.__importDefault) || function (mod) {
      return (mod && mod.__esModule) ? mod : { "default": mod };
  };
  let express = require('express');
  //let mongoose = require('mongoose');
  let MongoClient = require('mongodb').MongoClient;
  let db = require('../config/db');
  let passport = require('passport');
  let localStrategy = passport.default.Strategy;
  let router = express.Router();
  let ProfileModel = require('../models/profile');
  let Profile = ProfileModel.Profile;
  let UserModel = require('../models/users')
  let User = UserModel.User;
  const Util_1 = require('../Utils/index');
  let indexController = require("../controllers/indexController");
  
  let ApptModel = require('../models/appointment');
  let Appt = ApptModel.Appointment;
  let seekerModel = require('../models/tennisTrainerSeeker.js');
  const tennisTrainerSeeker = __importDefault(require("../models/tennisTrainerSeeker"));
  router.use(passport.initialize());
  router.use(passport.session());
  passport.use(seekerModel.default.createStrategy());
  
  
  //render the schedule page for the seeker
  module.exports.renderSeekerSchedule = (req, res, next) => {
    let localUser = req.user;
    Appt.find((err, mainList) => {
        if(err) {
            return console.error(err);
        }
        else {
            /*let list = [];
            for(let a in mainList)
            {
                if(localUser.username == mainList[a].ApptSeeker)
                {
                    list.push(mainList[a]);
                    
                }
                //console.log(mainList[a]);
            }
            let toSend = JSON.stringify(list);
            console.log(toSend);*/
            res.render('seekerViews/seekerScheduleView', { title : "Schedule", 
                list : mainList });
        }
    });
    //res.render('seekerViews/seekerScheduleView', { title: "Schedule", list : mainList });
  }
  //handle the request for the detailed view of the schedule
  module.exports.renderDetailedView = (req, res, next) => {
    let apptDate = req.body.dateLookup;
    console.log(apptDate);
    Appt.findById(apptDate, (err, date) => {
        if(err)
        {
            console.log(err);
        }
        else{
            console.log(date);
            res.render('seekerViews/detailedApptView', { title : 'details', appt : date });        
        }
    });
  }
  
  function DisplayRegisterSeekerPage(req, res, next) {
      if (!req.user) {
          return res.render('seekerViews/seekerIndex', { title: 'Seeker registration', page: 'registerSeeker', messages: req.flash('registerMessage'), displayName: (0, Util_1.UserDisplayName)(req) });
      }
      
      return res.redirect('/tennis');
  }
  exports.DisplayRegisterSeekerPage = DisplayRegisterSeekerPage;
  
  function ProcessRegisterSeekerPage(req, res, next) {
      let newUser = new tennisTrainerSeeker.default({
          userType: "seeker",
          username: req.body.username,
          emailAddress: req.body.emailAddress,
          displayName: req.body.FirstName + " " + req.body.LastName
      });
      tennisTrainerSeeker.default.register(newUser, req.body.password, (err) => {
          if (err) {
              console.error('Error: Inserting New User');
              if (err.name == "UserExistsError") {
                  req.flash('registerMessage', 'Registration Error');
              }
              console.log('Error: User Already Exists');
              return res.redirect('/seeker/registerSeeker');
          }
          return passport.authenticate('local')(req, res, () => {
              return res.redirect('/home');
          });
      });
  }
  exports.ProcessRegisterSeekerPage = ProcessRegisterSeekerPage;