File size: 7,345 Bytes
b688fe8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8a3fe26
a2ea1c4
5614636
 
8a3fe26
b688fe8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0e5aad3
 
82daa40
0e5aad3
b688fe8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8a3fe26
b688fe8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8a3fe26
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
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";
import AnnouncementBar from "@/components/AnnouncementBar";

/* The rail, per ContiAI App.dc.html.
 *
 * It is a dark navy panel rather than a light one, which is the single change
 * that gives the product its shape: the page floats as one bright field beside
 * a fixed dark edge, and the active item - brand fill on navy - is legible at
 * a glance.
 *
 * The page is RTL, so the first element in a flex row lands on the RIGHT. The
 * rail is therefore first in the DOM; putting the main region first pushed the
 * navigation to the left, which is wrong for Arabic.
 */

interface NavItem {
  to: string;
  label: string;
  icon: IconName;
  end?: boolean;
}

const NAV: NavItem[] = [
  { to: "/", label: t.nav.home, icon: "home", end: true },
  { to: "/create", label: t.nav.create, icon: "sparkle" },
  { to: "/library", label: t.nav.library, icon: "book" },
  { to: "/usage", label: t.nav.usage, icon: "clock" },
];

/** The founder's bag designer - shown to the owner account only. */
const DESIGN: NavItem = { to: "/design", label: "تصميم الحقائب والعروض", icon: "layers" };
/** «استوديو التصميم» - social designs and infographics, the owner account only. */
const STUDIO: NavItem = { to: "/studio", label: "استوديو التصميم", icon: "infographic" };

const FOOT: NavItem[] = [
  { to: "/profile", label: "الملف الشخصي", icon: "user" },
  { to: "/settings", label: t.nav.settings, icon: "cog" },
];

/** A rail row. Everything it wears is a rail token - none of the page's text
 *  or surface roles read correctly against navy. */
function Item({ item }: { item: NavItem }) {
  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 AppShell() {
  const { user, isAdmin, canDesign, signOut } = useAuth();
  // the designers and the studio: whoever the founder opened them to
  const designs = canDesign("bag") || canDesign("slides");
  const nav = [...NAV, ...(designs ? [DESIGN] : []), ...(canDesign("studio") ? [STUDIO] : [])];
  const location = useLocation();
  const account = user?.full_name || user?.email?.split("@")[0] || "";
  const initial = (account || "؟").trim().charAt(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)" }}
      >
        {/* The mark, oversized and nearly invisible in the corner. It reads as
            texture rather than as a second logo. */}
        <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="/"
          className="relative flex items-center gap-3 px-2 pb-[18px] 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>

        <p
          className="relative px-2.5 pb-2 text-micro font-semibold tracking-[0.08em]"
          style={{ color: "var(--rail-label)" }}
        >
          {t.nav.section}
        </p>

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

        <div className="relative mt-auto flex flex-col gap-1">
          {FOOT.map((i) => (
            <Item key={i.to} item={i} />
          ))}

          <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"
            >
              {initial}
            </span>
            <div className="min-w-0 flex-1">
              {/* An account name is very often an email or a Latin name, and it
                  sits in an RTL column - isolate it or the domain migrates to
                  the wrong end of the truncation. */}
              <p className="truncate text-caption font-semibold text-white">
                <Ltr>{account}</Ltr>
              </p>
              <p className="text-micro" style={{ color: "var(--rail-role)" }}>
                {isAdmin ? t.nav.roleAdmin : t.nav.roleUser}
              </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>

      {/* key on the path so each screen fades in on navigation */}
      <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-[34px]"
      >
        <AnnouncementBar />
        <Outlet />
      </main>

      {/* On small screens the rail becomes a bottom bar, and it keeps the rail's
          own colours so the product still reads as itself. */}
      <nav
        className="fixed inset-x-0 bottom-0 z-20 flex justify-around py-1.5 lg:hidden"
        style={{ background: "var(--rail)" }}
      >
        {nav.map((i) => (
          <NavLink
            key={i.to}
            to={i.to}
            end={i.end}
            className={({ isActive }) =>
              [
                "flex min-h-11 min-w-11 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={i.icon} size={19} />
            {i.label}
          </NavLink>
        ))}
      </nav>
    </div>
  );
}