File size: 9,414 Bytes
9e42d3b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
import { Link, useRouterState, useNavigate } from "@tanstack/react-router";
import { useEffect, useState, type ReactNode } from "react";

const navItems = [
  { href: "/dashboard", label: "TABLEAU DE BORD", icon: "dashboard" as const },
  { href: "/leads", label: "LISTE DES LEADS", icon: "leads" as const },
  { href: "/stands", label: "ANALYSE DES STANDS", icon: "stands" as const },
  { href: "/settings", label: "PARAMÈTRES DU MODÈLE", icon: "settings" as const },
];

function NavIcon({ type, active }: { type: string; active: boolean }) {
  const color = active ? "var(--primary)" : "var(--muted-foreground)";
  switch (type) {
    case "dashboard":
      return (
        <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke={color} strokeWidth="2">
          <rect x="3" y="3" width="7" height="7" rx="1" />
          <rect x="14" y="3" width="7" height="7" rx="1" />
          <rect x="3" y="14" width="7" height="7" rx="1" />
          <rect x="14" y="14" width="7" height="7" rx="1" />
        </svg>
      );
    case "leads":
      return (
        <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke={color} strokeWidth="2">
          <path d="M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2" />
          <circle cx="9" cy="7" r="4" />
          <path d="M23 21v-2a4 4 0 0 0-3-3.87" />
          <path d="M16 3.13a4 4 0 0 1 0 7.75" />
        </svg>
      );
    case "stands":
      return (
        <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke={color} strokeWidth="2">
          <path d="M3 3v18h18" />
          <path d="M18 17V9" />
          <path d="M13 17V5" />
          <path d="M8 17v-3" />
        </svg>
      );
    case "settings":
      return (
        <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke={color} strokeWidth="2">
          <path d="M12.22 2h-.44a2 2 0 0 0-2 2v.18a2 2 0 0 1-1 1.73l-.43.25a2 2 0 0 1-2 0l-.15-.08a2 2 0 0 0-2.73.73l-.22.38a2 2 0 0 0 .73 2.73l.15.1a2 2 0 0 1 1 1.72v.51a2 2 0 0 1-1 1.74l-.15.09a2 2 0 0 0-.73 2.73l.22.38a2 2 0 0 0 2.73.73l.15-.08a2 2 0 0 1 2 0l.43.25a2 2 0 0 1 1 1.73V20a2 2 0 0 0 2 2h.44a2 2 0 0 0 2-2v-.18a2 2 0 0 1 1-1.73l.43-.25a2 2 0 0 1 2 0l.15.08a2 2 0 0 0 2.73-.73l.22-.39a2 2 0 0 0-.73-2.73l-.15-.08a2 2 0 0 1-1-1.74v-.5a2 2 0 0 1 1-1.74l.15-.09a2 2 0 0 0 .73-2.73l-.22-.38a2 2 0 0 0-2.73-.73l-.15.08a2 2 0 0 1-2 0l-.43-.25a2 2 0 0 1-1-1.73V4a2 2 0 0 0-2-2z" />
          <circle cx="12" cy="12" r="3" />
        </svg>
      );
    default:
      return null;
  }
}

export function AdminLayout({
  title,
  subtitle,
  actions,
  children,
}: {
  title: string;
  subtitle?: string;
  actions?: ReactNode;
  children: ReactNode;
}) {
  const navigate = useNavigate();
  const pathname = useRouterState({ select: (s) => s.location.pathname });
  const [user, setUser] = useState<{ email: string; name: string }>({
    email: "admin@letudiant.local",
    name: "admin",
  });
  const [searchQuery, setSearchQuery] = useState("");

  useEffect(() => {
    const auth = typeof window !== "undefined" ? localStorage.getItem("letudiant_auth") : null;
    if (!auth) {
      return;
    }
    try {
      setUser(JSON.parse(auth));
    } catch {
      localStorage.removeItem("letudiant_auth");
    }
  }, [navigate]);

  const handleLogout = () => {
    localStorage.removeItem("letudiant_auth");
    navigate({ to: "/" });
  };

  if (!user) {
    return (
      <div className="min-h-screen flex items-center justify-center bg-background">
        <div className="animate-pulse text-muted-foreground">Chargement…</div>
      </div>
    );
  }

  return (
    <div className="min-h-screen flex bg-background">
      <aside
        className="w-[230px] flex flex-col fixed h-screen border-r"
        style={{ background: "var(--sidebar)", borderColor: "var(--outline-variant)" }}
      >
        <div className="p-6 pb-5">
          <img src="/letudiant-logo.png" alt="L'etudiant" className="h-14 w-auto object-contain" />
        </div>

        <nav className="flex-1 px-3 mt-4">
          {navItems.map((item) => {
            const isActive =
              pathname === item.href || (item.href === "/leads" && pathname.startsWith("/lead/"));
            return (
              <Link
                key={item.href}
                to={item.href}
                className="flex items-center gap-3 px-3 py-2.5 rounded-xl mb-1 transition-all"
                style={{
                  background: isActive ? "var(--surface-container)" : "transparent",
                  color: isActive ? "var(--primary)" : "var(--muted-foreground)",
                  fontWeight: isActive ? 600 : 500,
                }}
              >
                <NavIcon type={item.icon} active={isActive} />
                <span className="text-[11px] tracking-wide">{item.label}</span>
              </Link>
            );
          })}
        </nav>

        <div className="p-4">
          <div
            className="flex items-center gap-3 px-3 py-3 rounded-2xl"
            style={{ background: "var(--surface-container)" }}
          >
            <div
              className="w-10 h-10 rounded-full flex items-center justify-center text-sm font-medium text-white"
              style={{ background: "var(--gradient-primary)" }}
            >
              {user.name.slice(0, 2).toUpperCase()}
            </div>
            <div className="flex-1 min-w-0">
              <p className="text-sm font-medium truncate" style={{ color: "var(--foreground)" }}>
                {user.name.charAt(0).toUpperCase() + user.name.slice(1)}
              </p>
              <p className="text-[10px] tracking-wider" style={{ color: "var(--muted-foreground)" }}>
                ADMIN CONSOLE
              </p>
            </div>
          </div>
          <button
            onClick={handleLogout}
            className="w-full mt-3 py-2.5 rounded-xl text-sm font-medium text-white transition-all hover:opacity-90"
            style={{ background: "var(--gradient-primary)" }}
          >
            Déconnexion
          </button>
        </div>
      </aside>

      <main className="flex-1 ml-[230px]">
        <header
          className="sticky top-0 z-10 flex items-center justify-between px-10 py-5"
          style={{
            background: "color-mix(in oklab, var(--background) 85%, transparent)",
            backdropFilter: "blur(14px)",
          }}
        >
          <div className="flex-1 max-w-md">
            <div className="relative">
              <svg
                className="absolute left-4 top-1/2 -translate-y-1/2 w-4 h-4"
                style={{ color: "var(--muted-foreground)" }}
                fill="none"
                viewBox="0 0 24 24"
                stroke="currentColor"
              >
                <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z" />
              </svg>
              <input
                type="text"
                value={searchQuery}
                onChange={(e) => setSearchQuery(e.target.value)}
                placeholder="Search parameters…"
                className="w-full pl-11 pr-4 py-3 rounded-2xl text-sm transition-all focus:outline-none focus:ring-2"
                style={{
                  background: "var(--surface-container)",
                  border: "1px solid transparent",
                  color: "var(--foreground)",
                }}
              />
            </div>
          </div>

          <div className="flex items-center gap-5 ml-6">
            <button className="p-2 rounded-lg hover:bg-black/5 transition-colors relative">
              <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="var(--muted-foreground)" strokeWidth="2">
                <path d="M18 8A6 6 0 0 0 6 8c0 7-3 9-3 9h18s-3-2-3-9" />
                <path d="M13.73 21a2 2 0 0 1-3.46 0" />
              </svg>
            </button>
            <div className="flex items-center gap-3">
              <div className="text-right">
                <p className="text-sm font-semibold" style={{ color: "var(--foreground)" }}>
                  Alex Rivers
                </p>
                <p className="text-[11px]" style={{ color: "var(--muted-foreground)" }}>
                  Head of Growth
                </p>
              </div>
              <div
                className="w-10 h-10 rounded-full flex items-center justify-center text-sm font-semibold text-white"
                style={{ background: "var(--gradient-primary)" }}
              >
                AR
              </div>
            </div>
          </div>
        </header>

        <div className="px-10 pb-10">
          <div className="mb-8 flex items-start justify-between gap-6 flex-wrap">
            <div>
              <h2
                className="text-[40px] font-extrabold tracking-tight leading-none"
                style={{ color: "var(--foreground)", letterSpacing: "-0.03em" }}
              >
                {title}
              </h2>
              {subtitle && (
                <p className="text-sm mt-3 max-w-2xl" style={{ color: "var(--muted-foreground)" }}>
                  {subtitle}
                </p>
              )}
            </div>
            {actions && <div className="flex items-center gap-3">{actions}</div>}
          </div>
          {children}
        </div>
      </main>
    </div>
  );
}