from flask import Blueprint

bp = Blueprint('core', __name__, template_folder='templates')

from app.core.services.settings import SettingsService

@bp.app_context_processor
def inject_globals():
    """Injects globally required variables like settings and attendance state into all templates."""
    from flask_login import current_user
    from datetime import date
    
    global_attendance = None
    if current_user.is_authenticated:
        # Avoid heavy imports or errors if HRIS is disabled, but safely try to fetch today's attendance
        try:
            from app.modules.hris.models.employee import Attendance, Employee
            emp = Employee.query.filter_by(user_id=current_user.id).first()
            if emp:
                global_attendance = Attendance.query.filter_by(employee_id=emp.id, date=date.today()).first()
        except Exception:
            pass

    return dict(
        settings_service=SettingsService,
        global_today_attendance=global_attendance
    )

# Import routes to register them with the blueprint
from . import routes, errors, routes_category, routes_settings, routes_status, routes_employee, routes_contact, routes_office, routes_audit, routes_planner
