File size: 8,411 Bytes
b688fe8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
243
244
245
import { NavLink, Outlet, useLocation } from "react-router-dom";
import { useAuth } from "@/features/auth/AuthProvider";
import { Icon, type IconName } from "@/components/Icon";
import { Ltr } from "@/components/ui";
import { t } from "@/strings/ar";

/**
 * The administration space, per ContiAI Admin.dc.html.
 *
 * Same rail as the product - dark navy, 258px, the mark as a watermark - so
 * the two spaces are recognisably one system. What distinguishes them is the
 * navigation itself, which is the honest signal: seven administrative
 * destinations rather than four working ones.
 *
 * There is deliberately no banner across the top. The rail already says where
 * you are on every screen, and a fixed bar repeating it cost 46px of vertical
 * space on every page to tell an administrator something they knew.
 */

const NAV: { to: string; label: string; icon: IconName; end?: boolean }[] = [
  { to: "/admin", label: t.admin.overview, icon: "grid", end: true },
  { to: "/admin/users", label: t.admin.users, icon: "user" },
  { to: "/admin/usage", label: "الاستهلاك التفصيلي", icon: "bars" },
  { to: "/admin/runs", label: t.admin.runs, icon: "playRing" },
  { to: "/admin/task-types", label: t.admin.taskTypes, icon: "book" },
  { to: "/admin/announcements", label: t.admin.announcements, icon: "bell" },
  { to: "/admin/audit", label: t.admin.audit, icon: "shield" },
];

function Item({ item }: { item: (typeof NAV)[number] }) {
  return (
    <NavLink
      to={item.to}
      end={item.end}
      className={({ isActive }) =>
        [
          "flex min-h-11 items-center gap-3 rounded-md px-3 py-2.5",
          "text-item transition-colors duration-200",
          isActive
            ? "bg-[var(--color-brand-700)] font-bold text-white"
            : "font-medium text-[var(--rail-item)] hover:bg-white/[0.07]",
        ].join(" ")
      }
    >
      {({ isActive }) => (
        <>
          <span
            className="grid size-5 shrink-0 place-items-center"
            style={{ color: isActive ? "#fff" : "var(--rail-icon)" }}
          >
            <Icon name={item.icon} size={19} />
          </span>
          <span>{item.label}</span>
        </>
      )}
    </NavLink>
  );
}

export default function AdminShell() {
  const { user, signOut } = useAuth();
  const location = useLocation();
  const account = user?.full_name || user?.email?.split("@")[0] || "";

  return (
    <div className="flex min-h-screen bg-[var(--surface-subtle)]">
      {/* rail first == right side in RTL */}
      <aside
        className="sticky top-0 hidden h-screen w-[258px] shrink-0 flex-col overflow-hidden
                   px-4 pb-4 pt-5 lg:flex"
        style={{ background: "var(--rail)" }}
      >
        <img
          src="/logo/mark-white.png"
          alt=""
          aria-hidden
          className="pointer-events-none absolute -bottom-8 -left-10 size-[220px] object-contain
                     opacity-[0.07]"
        />

        <NavLink
          to="/admin"
          className="relative flex items-center gap-3 px-2 pb-5 pt-1.5
                     transition-opacity hover:opacity-80"
        >
          <img src="/logo/mark-white.png" alt="" className="size-[34px] object-contain" />
          <img src="/logo/lockup-white.png" alt="كونتي AI" className="h-5 object-contain" />
        </NavLink>

        <nav className="relative flex flex-col gap-1">
          {NAV.map((item) => (
            <Item key={item.to} item={item} />
          ))}
        </nav>

        <div className="relative mt-auto flex flex-col gap-1">
          {/* The way back to the product. It belongs with the account controls
              rather than in a banner: leaving is something you do once, at the
              end, not something the screen should announce continuously. */}
          <NavLink
            to="/"
            className="flex min-h-11 items-center gap-3 rounded-md px-3 py-2.5 text-item
                       font-medium text-[var(--rail-item)] transition-colors
                       hover:bg-white/[0.07]"
          >
            <span
              className="grid size-5 shrink-0 place-items-center"
              style={{ color: "var(--rail-icon)" }}
            >
              <Icon name="exit" size={19} />
            </span>
            {t.admin.exit}
          </NavLink>

          <div
            className="mt-2 flex items-center gap-3 rounded-[var(--radius-btn)] border px-3 py-2.5"
            style={{ background: "var(--rail-card)", borderColor: "var(--rail-card-bd)" }}
          >
            <span
              className="grid size-[34px] shrink-0 place-items-center rounded-full
                         bg-[var(--color-brand-500)] text-item font-bold text-white"
            >
              {(account || "؟").trim().charAt(0)}
            </span>
            <div className="min-w-0 flex-1">
              <p className="truncate text-caption font-semibold text-white">
                <Ltr>{account}</Ltr>
              </p>
              <p className="text-micro" style={{ color: "var(--rail-role)" }}>
                {t.nav.roleAdmin}
              </p>
            </div>
            <button
              onClick={signOut}
              title={t.nav.signOut}
              aria-label={t.nav.signOut}
              className="tap shrink-0 rounded-md transition-colors hover:text-white"
              style={{ color: "var(--rail-label)" }}
            >
              <Icon name="exit" size={17} />
            </button>
          </div>
        </div>
      </aside>

      <main
        key={location.pathname}
        className="min-w-0 flex-1 animate-[fade_.22s_ease-out] px-6 pb-24 pt-8
                   lg:px-10 lg:pb-[60px] lg:pt-[30px]"
      >
        <Outlet />
      </main>

      <nav
        className="fixed inset-x-0 bottom-0 z-20 flex justify-around overflow-x-auto py-1.5 lg:hidden"
        style={{ background: "var(--rail)" }}
      >
        {NAV.map((item) => (
          <NavLink
            key={item.to}
            to={item.to}
            end={item.end}
            className={({ isActive }) =>
              [
                "flex min-h-11 min-w-11 shrink-0 flex-col items-center justify-center gap-0.5 px-3",
                "text-micro font-semibold transition-colors",
                isActive ? "text-white" : "text-[var(--rail-item)]",
              ].join(" ")
            }
          >
            <Icon name={item.icon} size={19} />
            {item.label}
          </NavLink>
        ))}
      </nav>
    </div>
  );
}

/** Shared page header for admin screens.
 *
 *  The admin file sets its title at 34/800 rather than the product's 40 - an
 *  administrative page carries more per screen and the smaller title leaves
 *  the room for it. */
export function AdminHeader({
  title,
  subtitle,
  action,
}: {
  title: string;
  subtitle?: string;
  action?: React.ReactNode;
}) {
  return (
    <header className="mb-[22px] flex flex-wrap items-start justify-between gap-5">
      <div className="min-w-0">
        <h1 className="text-h1 text-[var(--text-strong)]">
          {title}
        </h1>
        {subtitle && (
          <p className="mt-1.5 max-w-2xl text-item text-[var(--text-muted)]">{subtitle}</p>
        )}
      </div>
      {action}
    </header>
  );
}

/** The week/month/quarter/year switch. Full-height pills, per the admin file. */
export function RangeSwitch({
  value,
  onChange,
  options = [
    { days: 7, label: "أسبوع" },
    { days: 30, label: "شهر" },
    { days: 90, label: "٣ أشهر" },
    { days: 365, label: "سنة" },
  ],
}: {
  value: number;
  onChange: (days: number) => void;
  options?: { days: number; label: string }[];
}) {
  return (
    <div className="flex shrink-0 items-center gap-1.5">
      {options.map((o) => (
        <button
          key={o.days}
          type="button"
          onClick={() => onChange(o.days)}
          className={[
            "min-h-11 rounded-md border px-4 py-2 text-caption transition-all",
            value === o.days
              ? "border-[var(--color-brand-700)] bg-[var(--color-brand-700)] font-bold text-white"
              : "border-[var(--border-subtle)] bg-[var(--surface)] font-medium " +
                "text-[var(--text-muted)] hover:border-[var(--brand)]",
          ].join(" ")}
        >
          {o.label}
        </button>
      ))}
    </div>
  );
}