177 lines
7.7 KiB
TypeScript
177 lines
7.7 KiB
TypeScript
import React from 'react';
|
|
import {
|
|
Sparkles, ChevronLeft, ChevronRight, LogOut,
|
|
List, BookOpen, Tag, Ticket, Users, CheckCircle,
|
|
Receipt, Shield, Database, FileText
|
|
} from 'lucide-react';
|
|
import type { LoggedInUser, AdminTabType } from '../../types';
|
|
|
|
interface TabItem {
|
|
key: AdminTabType;
|
|
label: string;
|
|
icon: React.ReactNode;
|
|
count?: number;
|
|
}
|
|
|
|
interface AdminSidebarProps {
|
|
loggedInUser: LoggedInUser | null;
|
|
activeTab: AdminTabType;
|
|
onSelectTab: (tab: AdminTabType) => void;
|
|
counts: {
|
|
modules: number;
|
|
plans: number;
|
|
coupons: number;
|
|
customers: number;
|
|
subscriptions: number;
|
|
payments: number;
|
|
admins: number;
|
|
};
|
|
isCollapsed: boolean;
|
|
onToggleCollapse: () => void;
|
|
onLogout: () => void;
|
|
}
|
|
|
|
export const AdminSidebar: React.FC<AdminSidebarProps> = ({
|
|
loggedInUser,
|
|
activeTab,
|
|
onSelectTab,
|
|
counts,
|
|
isCollapsed,
|
|
onToggleCollapse,
|
|
onLogout,
|
|
}) => {
|
|
const tabs: TabItem[] = [
|
|
{ key: 'overview', label: 'Overview & Logs', icon: <List className="h-4 w-4 shrink-0" /> },
|
|
{ key: 'modules', label: 'Modules', count: counts.modules, icon: <BookOpen className="h-4 w-4 shrink-0" /> },
|
|
{ key: 'plans', label: 'Plans & Pricing', count: counts.plans, icon: <Tag className="h-4 w-4 shrink-0" /> },
|
|
{ key: 'coupons', label: 'Coupons', count: counts.coupons, icon: <Ticket className="h-4 w-4 shrink-0" /> },
|
|
{ key: 'customers', label: 'Customers', count: counts.customers, icon: <Users className="h-4 w-4 shrink-0" /> },
|
|
{ key: 'users_subscriptions', label: 'Subscriptions', count: counts.subscriptions, icon: <CheckCircle className="h-4 w-4 shrink-0" /> },
|
|
{ key: 'payments', label: 'Payments', count: counts.payments, icon: <Receipt className="h-4 w-4 shrink-0" /> },
|
|
{ key: 'admins', label: 'Manage Admins', count: counts.admins, icon: <Shield className="h-4 w-4 shrink-0" /> },
|
|
{ key: 'database', label: 'DB & Backups', icon: <Database className="h-4 w-4 shrink-0" /> },
|
|
{ key: 'reports', label: 'Reports & Exports', icon: <FileText className="h-4 w-4 shrink-0" /> },
|
|
];
|
|
|
|
return (
|
|
<aside
|
|
className={`bg-[#0A0A0E] border-b md:border-b-0 md:border-r border-slate-800/80 flex flex-col justify-between py-4 transition-all duration-300 ease-in-out flex-shrink-0 text-slate-300 shadow-2xl select-none relative z-30 ${
|
|
isCollapsed ? 'w-full md:w-[68px] px-2' : 'w-full md:w-60 px-3'
|
|
}`}
|
|
>
|
|
<div className="space-y-4">
|
|
{/* Brand & Collapse Header */}
|
|
<div className={`flex items-center ${isCollapsed ? 'justify-center' : 'justify-between'} gap-2 px-1`}>
|
|
<div className="flex items-center gap-2.5 min-w-0">
|
|
<div className="h-8 w-8 rounded-xl bg-gradient-to-tr from-indigo-500 to-cyan-400 flex items-center justify-center shadow-md shadow-indigo-500/20 shrink-0">
|
|
<Sparkles className="h-4 w-4 text-white" />
|
|
</div>
|
|
{!isCollapsed && (
|
|
<div className="min-w-0">
|
|
<h1 className="text-sm font-black tracking-tight text-white truncate">
|
|
ACUPEDIA
|
|
</h1>
|
|
<p className="text-[8px] text-slate-400 font-bold tracking-widest uppercase">ADMIN CONSOLE</p>
|
|
</div>
|
|
)}
|
|
</div>
|
|
|
|
<button
|
|
type="button"
|
|
onClick={onToggleCollapse}
|
|
className="hidden md:flex h-7 w-7 rounded-lg bg-slate-800/80 hover:bg-slate-700 text-slate-400 hover:text-white items-center justify-center transition-colors cursor-pointer border border-slate-700/60"
|
|
title={isCollapsed ? 'Expand sidebar' : 'Collapse sidebar'}
|
|
>
|
|
{isCollapsed ? <ChevronRight className="h-3.5 w-3.5" /> : <ChevronLeft className="h-3.5 w-3.5" />}
|
|
</button>
|
|
</div>
|
|
|
|
{/* Navigation Tabs */}
|
|
<nav className="space-y-1">
|
|
{tabs.map((tab) => {
|
|
const isActive = activeTab === tab.key;
|
|
return (
|
|
<button
|
|
key={tab.key}
|
|
type="button"
|
|
onClick={() => onSelectTab(tab.key)}
|
|
className={`w-full flex items-center gap-3 px-3 py-2.5 rounded-xl text-xs font-bold transition-all cursor-pointer relative group ${
|
|
isActive
|
|
? 'bg-indigo-600 text-white shadow-lg shadow-indigo-600/30'
|
|
: 'text-slate-400 hover:text-slate-100 hover:bg-slate-800/60'
|
|
} ${isCollapsed ? 'justify-center px-0' : ''}`}
|
|
title={isCollapsed ? `${tab.label} ${tab.count !== undefined ? `(${tab.count})` : ''}` : undefined}
|
|
>
|
|
{tab.icon}
|
|
{!isCollapsed && (
|
|
<>
|
|
<span className="truncate flex-1 text-left">{tab.label}</span>
|
|
{tab.count !== undefined && (
|
|
<span
|
|
className={`text-[10px] font-black px-1.5 py-0.5 rounded-full ${
|
|
isActive
|
|
? 'bg-white/20 text-white'
|
|
: 'bg-slate-800 text-slate-400 group-hover:text-slate-200'
|
|
}`}
|
|
>
|
|
{tab.count}
|
|
</span>
|
|
)}
|
|
</>
|
|
)}
|
|
{/* Collapsed active dot */}
|
|
{isCollapsed && isActive && (
|
|
<span className="absolute right-1.5 top-1/2 -translate-y-1/2 w-1.5 h-1.5 bg-white rounded-full shadow-xs" />
|
|
)}
|
|
</button>
|
|
);
|
|
})}
|
|
</nav>
|
|
</div>
|
|
|
|
{/* User Footer */}
|
|
<div className="pt-3 border-t border-slate-800/80 mt-4">
|
|
{!isCollapsed ? (
|
|
<div className="space-y-2.5 px-1">
|
|
<div className="flex items-center gap-2.5">
|
|
<div className="h-8 w-8 rounded-xl bg-gradient-to-tr from-indigo-950 to-indigo-900 border border-indigo-500/30 flex items-center justify-center text-indigo-400 font-black text-xs shrink-0 shadow-inner">
|
|
{loggedInUser?.display_name ? loggedInUser.display_name[0].toUpperCase() : 'A'}
|
|
</div>
|
|
<div className="min-w-0 flex-1">
|
|
<p className="text-xs font-bold text-white truncate">
|
|
{loggedInUser?.display_name || 'Admin'}
|
|
</p>
|
|
<p className="text-[10px] text-slate-400 truncate">{loggedInUser?.email}</p>
|
|
</div>
|
|
</div>
|
|
<button
|
|
type="button"
|
|
onClick={onLogout}
|
|
className="w-full flex items-center justify-center gap-2 py-2 rounded-xl text-xs font-bold bg-slate-800 hover:bg-slate-700 text-slate-300 hover:text-white transition-colors cursor-pointer border border-slate-700/60"
|
|
>
|
|
<LogOut className="h-3.5 w-3.5" /> Log Out
|
|
</button>
|
|
</div>
|
|
) : (
|
|
<div className="flex flex-col items-center gap-2">
|
|
<div
|
|
className="h-8 w-8 rounded-xl bg-indigo-950/60 border border-indigo-500/30 flex items-center justify-center text-indigo-400 font-bold text-xs shrink-0"
|
|
title={`${loggedInUser?.display_name || 'Admin'} (${loggedInUser?.email})`}
|
|
>
|
|
{loggedInUser?.display_name ? loggedInUser.display_name[0].toUpperCase() : 'A'}
|
|
</div>
|
|
<button
|
|
type="button"
|
|
onClick={onLogout}
|
|
className="h-8 w-8 flex items-center justify-center rounded-xl bg-slate-800 hover:bg-slate-700 text-slate-400 hover:text-white transition-colors cursor-pointer border border-slate-700/60"
|
|
title="Log Out"
|
|
>
|
|
<LogOut className="h-3.5 w-3.5" />
|
|
</button>
|
|
</div>
|
|
)}
|
|
</div>
|
|
</aside>
|
|
);
|
|
};
|