import { useState } from 'react' import { AdminLayout, Card, CardContent, CardHeader, DescriptionItem, DescriptionList, LocaleProvider, SegmentedControl, TenantSwitcher, toast, zhTW, type AdminNavGroup, type TenantItem, } from '../../index' type Role = 'platformAdmin' | 'member' /** * The app layer owns permissions — the layout only receives a check * function. Here a role → permission map stands in for your auth store. */ const ROLE_PERMISSIONS: Record = { platformAdmin: ['platform:access', 'billing:view'], member: [], } /** * Navigation is plain data: group-level `visibleWhen` hides whole * sections, item-level `permissions` hides single entries. Adding a page * for a new role is a data change, not a layout change. */ const NAVIGATION: AdminNavGroup[] = [ { label: '總覽', items: [{ path: '/dashboard', label: '儀表板' }], }, { label: '平台管理', visibleWhen: (ctx) => ctx.hasPermission?.(['platform:access']) ?? false, items: [ { path: '/tenants', label: '租戶' }, { path: '/platform-users', label: '平台使用者' }, ], }, { label: '營運', items: [ { path: '/orders', label: '訂單' }, { path: '/billing', label: '帳務', permissions: ['billing:view'] }, ], }, { label: '設定', items: [{ path: '/settings', label: '設定' }], }, ] const TENANTS: TenantItem[] = [ { id: 't1', name: '宏達物流', slug: 'hongda', planLabel: 'Enterprise', status: '啟用', statusVariant: 'success', }, { id: 't2', name: '晨星文創', slug: 'morningstar', planLabel: 'Pro' }, { id: 't3', name: '青田餐飲', slug: 'aozora', planLabel: 'Starter', status: '試用', statusVariant: 'warning', }, ] /** * Recipe: a multi-tenant admin shell. * * Composition: LocaleProvider (zhTW, once at the root — every built-in * string and aria-label localizes from here) → AdminLayout (brand + * permission-aware navigation + user) → TenantSwitcher in the navbar, * controlled via `value`/`onChange`. Routing is simulated with useState; * in a real SPA keep `onNavigate` for imperative moves and also pass * `renderLink` so nav items render as your router's `` elements. * The role toggle in the content area stands in for your auth layer. */ export function TenantAdminShell() { const [role, setRole] = useState('platformAdmin') const [tenant, setTenant] = useState(TENANTS[0]) const [path, setPath] = useState('/dashboard') const hasPermission = (permissions: string[]) => permissions.some((p) => ROLE_PERMISSIONS[role].includes(p)) return ( toast.success('已登出')} navbarLeft={} >
) }