from flask import Blueprint
from flask_login import login_required, current_user
from app import db
from app.models import Folder

# Import blueprints from individual route files
from app.routes.folders import folders_bp
from app.routes.imap import imap_bp
from app.routes.emails import emails_bp

# Create the main blueprint
main = Blueprint('main', __name__)

# Register all blueprints
main.register_blueprint(folders_bp)
main.register_blueprint(imap_bp)
main.register_blueprint(emails_bp)

# Root route that redirects to the main index page
@main.route('/')
@login_required
def index():
    """Redirect to the folders index page."""
    # Get folders for the current authenticated user
    folders = Folder.query.filter_by(user_id=current_user.id).all()
    
    from flask import render_template
    return render_template('index.html',
                          folders=folders,
                          show_hidden=False)