from flask import Blueprint, render_template, redirect, url_for
from flask_login import current_user
from app.models.course import ShortCourse, LearningCourse
from app.models.team import TeamMember

main_bp = Blueprint('main', __name__)

@main_bp.route('/')
def index():
    if current_user.is_authenticated:
        if current_user.role == 'admin':
            return redirect(url_for('admin.dashboard'))
        elif current_user.role == 'teacher':
            return redirect(url_for('teacher.dashboard'))
        elif current_user.role == 'student':
            return redirect(url_for('student.dashboard'))
    return render_template('landing.html')

# --- Added for course navigation ---
@main_bp.route('/short-courses')
def short_courses():
    courses = ShortCourse.query.all()
    return render_template('short_courses.html', courses=courses)

@main_bp.route('/learning-courses')
def learning_courses():
    courses = LearningCourse.query.all()
    return render_template('learning_courses.html', courses=courses)

@main_bp.route('/about')
def about():
    """About page showing information about Try English AI, team, and timeline"""
    academic_team = TeamMember.query.filter_by(team_type='academic', is_active=True).order_by(TeamMember.order).all()
    technical_team = TeamMember.query.filter_by(team_type='technical', is_active=True).order_by(TeamMember.order).all()
    admin_team = TeamMember.query.filter_by(team_type='administrative', is_active=True).order_by(TeamMember.order).all()
    
    return render_template('about.html', 
                         academic_team=academic_team,
                         technical_team=technical_team,
                         admin_team=admin_team)

@main_bp.route('/mobile-test')
def mobile_test():
    """Test page for mobile HTTPS and microphone functionality"""
    return render_template('mobile_test.html')
