from markupsafe import Markup

from odoo import models

FONT_LINK = Markup(
    '<link rel="preconnect" href="https://fonts.googleapis.com"/>'
    '<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin="anonymous"/>'
    '<link rel="stylesheet" '
    'href="https://fonts.googleapis.com/css2?family=Oswald:wght@400;500;700&amp;family=Roboto:wght@400;500&amp;display=swap"/>'
)


class IrHttp(models.AbstractModel):
    _inherit = 'ir.http'

    def webclient_rendering_context(self):
        context = super().webclient_rendering_context()
        context['title'] = 'Xenoptics App'
        context['x_icon'] = '/xeno_theme_slate/static/img/favicon.ico'
        context['head'] = (context.get('head') or Markup('')) + FONT_LINK
        return context

    def session_info(self):
        # session_info() (not lazy_session_info -- that's a separate lazily
        # RPC'd payload) is embedded directly in the initial webclient
        # bootstrap, so this flag is available client-side immediately on
        # first render, letting navbar_patch.js gate the mandatory
        # first-login policy pop-up without an extra round trip.
        info = super().session_info()
        user = self.env.user
        info['xenoNeedsPolicyAck'] = bool(
            user._is_internal() and user.employee_id and user.employee_id._xeno_needs_policy_ack())
        return info
