<!doctype html>
<html lang="fr" class="<%= nativeAppSurface ? 'native-app' : '' %>">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
  <title><%= title ? `${title} - ` : '' %><%= settings.site_name || 'Le Conseil Foot' %></title>
  <meta name="theme-color" content="#08172f">
  <link rel="manifest" href="/manifest.webmanifest">
  <link rel="icon" type="image/png" sizes="192x192" href="/icons/icon-192.png">
  <link rel="apple-touch-icon" href="/icons/icon-192.png">
  <script>
    window.LCF_ASSET_VERSION = '20260610-apple-review-ui-v2';
    window.LCF_SERVER_NATIVE_APP = <%= nativeAppSurface ? 'true' : 'false' %>;
    window.LCF_LOOKS_NATIVE_WEBVIEW = function () {
      try {
        var userAgent = window.navigator.userAgent || '';
        var isIos = /\b(iPhone|iPad|iPod)\b/i.test(userAgent);
        var isAppleWebKit = /AppleWebKit/i.test(userAgent);
        var isStandaloneIosBrowser = /(Safari|CriOS|FxiOS|EdgiOS|OPiOS)/i.test(userAgent);
        var isIosWebView = isIos && isAppleWebKit && !isStandaloneIosBrowser;
        var isAndroid = /Android/i.test(userAgent);
        var isAndroidWebView = isAndroid && (/\bwv\b/i.test(userAgent) || (/Version\/\d/i.test(userAgent) && /Chrome\/\d/i.test(userAgent)));
        return isIosWebView || isAndroidWebView;
      } catch (error) {
        return false;
      }
    };
    window.LCF_DETECT_NATIVE_APP = function () {
      try {
        var cap = window.Capacitor;
        var userAgent = window.navigator.userAgent || '';
        if (window.LCF_SERVER_NATIVE_APP || /LeConseilFootApp|LCFNativeApp/i.test(userAgent) || window.LCF_LOOKS_NATIVE_WEBVIEW()) return true;
        if (!cap) return false;
        if (typeof cap.isNativePlatform === 'function' && cap.isNativePlatform()) return true;
        if (typeof cap.getPlatform === 'function') return ['ios', 'android'].indexOf(cap.getPlatform()) !== -1;
        return !!(cap.Plugins && (cap.Plugins.PushNotifications || cap.Plugins.StatusBar || cap.Plugins.AppLauncher));
      } catch (error) {
        return false;
      }
    };
    window.LCF_SYNC_SURFACE_CLASSES = function (allowWebMobile) {
      try {
        var root = document.documentElement;
        var standalone = (window.matchMedia && window.matchMedia('(display-mode: standalone)').matches) || window.navigator.standalone === true;
        if (window.LCF_DETECT_NATIVE_APP()) {
          root.classList.add('native-app');
          root.classList.remove('web-mobile-surface');
          window.LCF_IS_NATIVE_APP = true;
          return;
        }
        window.LCF_IS_NATIVE_APP = false;
        if (standalone) {
          root.classList.add('standalone-pwa');
          root.classList.remove('web-mobile-surface');
        } else if (allowWebMobile) {
          root.classList.add('web-mobile-surface');
        }
      } catch (error) {}
    };
    window.LCF_SYNC_SURFACE_CLASSES(false);
  </script>
  <style>
    .native-app .mobile-store-badges,.native-app .mobile-install-choice,.standalone-pwa .mobile-store-badges,.standalone-pwa .mobile-install-choice,html:not(.web-mobile-surface) .mobile-store-badges,html:not(.web-mobile-surface) .mobile-install-choice{display:none!important}
  </style>
  <link rel="stylesheet" href="/css/app.css">
  <script defer src="/js/app.js?v=20260610-apple-review-ui-v2"></script>
  <script defer src="/js/pwa.js?v=20260610-apple-review-ui-v2"></script>
  <script defer src="/js/capacitor-push.js?v=20260610-apple-review-ui-v2"></script>
  <script defer src="/js/analyses-live.js?v=20260610-apple-review-ui-v2"></script>
</head>
<%
  const lockScrollPaths = ['/', '/login', '/register', '/forgot-password', '/reset-password'];
  const shouldLockScroll = lockScrollPaths.includes(currentPath) || currentPath.startsWith('/reset-password/');
  const bodyClasses = [
    user ? 'member-shell' : 'guest-shell',
    shouldLockScroll ? 'lock-scroll-when-fit' : ''
  ].filter(Boolean).join(' ');
%>
<body class="<%= bodyClasses %>">
  <header class="topbar">
    <a class="brand" href="<%= user ? '/analyses' : '/' %>">
      <img src="<%= settings.logo_url || '/brand/logo-mark.png' %>" alt="">
      <span>Le Conseil Foot</span>
    </a>
    <% if (user) { %>
      <div class="top-actions">
        <% if (user.role === 'admin') { %>
          <a class="admin-access" href="/admin" aria-label="Administration">
            <svg viewBox="0 0 24 24" aria-hidden="true"><path d="M4 13h7V4H4v9Zm0 7h7v-5H4v5Zm9 0h7v-9h-7v9Zm0-16v5h7V4h-7Z"/></svg>
            <span>Admin</span>
          </a>
        <% } %>
        <a class="icon-link" href="/profil" aria-label="Profil"><span><%= user.name.slice(0,1).toUpperCase() %></span></a>
      </div>
    <% } else { %>
      <a class="header-login" href="/login">Connexion</a>
    <% } %>
  </header>

  <main class="page">
    <% if (flash.error && flash.error.length) { %><div class="flash error"><%= flash.error[0] %></div><% } %>
    <% if (flash.success && flash.success.length) { %><div class="flash success"><%= flash.success[0] %></div><% } %>
    <%- body %>
  </main>

  <% if (user) { %>
    <nav class="bottom-nav <%= (!appReviewMode && settings.show_telegram_button === 'true') ? 'has-telegram' : 'no-telegram' %>">
      <a class="<%= currentPath === '/analyses' ? 'active' : '' %>" href="/analyses">
        <svg viewBox="0 0 24 24" aria-hidden="true"><path d="M7 3h10a2 2 0 0 1 2 2v14l-3-2-3 2-3-2-3 2-2-1.35V5a2 2 0 0 1 2-2Zm1 5h8V6H8v2Zm0 4h8v-2H8v2Zm0 4h5v-2H8v2Z"/></svg>
        <span>Analyses</span>
      </a>
      <% if (!appReviewMode && settings.show_telegram_button === 'true') { %>
        <a class="telegram" href="<%= settings.telegram_button_url %>" target="_blank" rel="noopener" data-telegram-link aria-label="<%= settings.telegram_button_label || 'GROUPE TELEGRAM' %>">
          <svg viewBox="0 0 24 24" aria-hidden="true"><path d="M21.7 4.4 18.6 19c-.23 1.04-.84 1.29-1.7.8l-4.7-3.46-2.27 2.18c-.25.25-.46.46-.94.46l.34-4.78 8.7-7.86c.38-.34-.08-.53-.59-.2L6.7 12.9 2.08 11.45c-1-.31-1.02-1 .2-1.48L20.35 3c.84-.31 1.57.2 1.35 1.4Z"/></svg>
          <span>Telegram</span>
        </a>
      <% } %>
      <a class="<%= currentPath === '/historique' ? 'active' : '' %>" href="/historique">
        <svg viewBox="0 0 24 24" aria-hidden="true"><path d="M13 3a9 9 0 1 1-8.05 5H2l4-4 4 4H7.1A7 7 0 1 0 13 5v4l3 3-1.4 1.4L11 9.8V3h2Z"/></svg>
        <span>Historique</span>
      </a>
    </nav>
  <% } %>
</body>
</html>
