%PDF- %PDF-
| Direktori : /home2/rezakur1/muakita.rezakurnia.com/Mua-Kita-Web/src/components/ |
| Current File : //home2/rezakur1/muakita.rezakurnia.com/Mua-Kita-Web/src/components/BottomNav.tsx |
import React, { useState } from 'react';
import {
LayoutDashboard, Building2, Package, CreditCard,
CalendarDays, Sparkles, DollarSign, Menu, X, ChevronRight,
Shield, Briefcase, Plus, Search
} from 'lucide-react';
import { Role, MenuItem } from '../types';
interface BottomNavProps {
role: Role;
setRole: (role: Role) => void;
activeTab: string;
setActiveTab: (tab: string) => void;
menus: MenuItem[];
onOpenAddModal: () => void;
triggerToast: (msg: string) => void;
}
export const BottomNav: React.FC<BottomNavProps> = ({
role,
setRole,
activeTab,
setActiveTab,
menus,
onOpenAddModal,
triggerToast
}) => {
const [showMoreMenu, setShowMoreMenu] = useState(false);
const [mobileSearch, setMobileSearch] = useState('');
// Define top 4 primary actions for each role
const primaryMenuItems = role === 'superadmin' ? [
{ id: 'dashboard', label: 'Beranda', icon: LayoutDashboard },
{ id: 'tenant', label: 'Tenant', icon: Building2 },
{ id: 'paket', label: 'Paket', icon: Package },
{ id: 'pembayaran', label: 'Pembayaran', icon: CreditCard },
] : [
{ id: 'dashboard', label: 'Beranda', icon: LayoutDashboard },
{ id: 'reservasi', label: 'Reservasi', icon: CalendarDays },
{ id: 'layanan', label: 'Layanan', icon: Sparkles },
{ id: 'keuangan', label: 'Keuangan', icon: DollarSign },
];
// Filter extra menus for the 'Lainnya' modal sheet
const filteredMenus = menus.filter(m =>
m.label.toLowerCase().includes(mobileSearch.toLowerCase())
);
return (
<>
{/* FIXED BOTTOM NAVIGATION BAR (VISIBLE ON MOBILE ONLY: sm:hidden) */}
<div className="fixed bottom-0 left-0 right-0 z-40 bg-white/95 backdrop-blur-md border-t border-slate-200/90 shadow-lg sm:hidden px-2 py-1.5 flex items-center justify-around">
{primaryMenuItems.map(item => {
const Icon = item.icon;
const isActive = activeTab === item.id;
return (
<button
key={item.id}
onClick={() => {
setActiveTab(item.id);
setShowMoreMenu(false);
}}
className={`flex flex-col items-center justify-center py-1 px-2.5 rounded-xl transition-all cursor-pointer ${
isActive
? 'text-[#EC167F] font-bold'
: 'text-slate-500 hover:text-slate-800'
}`}
>
<div className={`p-1 rounded-xl transition-transform ${isActive ? 'scale-110 bg-pink-50' : ''}`}>
<Icon className="w-5 h-5" />
</div>
<span className="text-[10px] mt-0.5 font-semibold tracking-tight">{item.label}</span>
</button>
);
})}
{/* Floating Quick Add Center Button or Menu button */}
<button
onClick={() => setShowMoreMenu(true)}
className={`flex flex-col items-center justify-center py-1 px-2.5 rounded-xl transition-all cursor-pointer ${
showMoreMenu
? 'text-[#EC167F] font-bold'
: 'text-slate-500 hover:text-slate-800'
}`}
>
<div className={`p-1 rounded-xl transition-transform ${showMoreMenu ? 'scale-110 bg-pink-50' : ''}`}>
<Menu className="w-5 h-5" />
</div>
<span className="text-[10px] mt-0.5 font-semibold tracking-tight">Lainnya</span>
</button>
</div>
{/* MOBILE SHEET / FULL MENU OVERLAY */}
{showMoreMenu && (
<div className="fixed inset-0 z-50 bg-slate-900/60 backdrop-blur-xs flex flex-col justify-end sm:hidden animate-in fade-in duration-200">
<div className="bg-white rounded-t-3xl max-h-[85vh] flex flex-col shadow-2xl border-t border-slate-100 overflow-hidden animate-in slide-in-from-bottom duration-300">
{/* Sheet Handle and Header */}
<div className="p-3.5 border-b border-slate-100 flex items-center justify-between shrink-0 bg-slate-50/50">
<div className="flex items-center gap-2">
<div className="w-2.5 h-2.5 rounded-full bg-[#EC167F]"></div>
<div>
<h3 className="text-xs font-extrabold text-slate-900">
Menu MuaKita ({role === 'superadmin' ? 'Super Admin' : 'Bisnis Owner'})
</h3>
<p className="text-[10px] text-slate-500">Semua fitur & navigasi platform</p>
</div>
</div>
<button
onClick={() => setShowMoreMenu(false)}
className="p-1.5 text-slate-400 hover:text-slate-700 hover:bg-slate-200/60 rounded-full transition-colors cursor-pointer"
>
<X className="w-5 h-5" />
</button>
</div>
{/* Quick Role Switcher Bar inside Sheet */}
<div className="p-3 bg-pink-50/60 border-b border-pink-100 flex items-center justify-between text-xs shrink-0">
<span className="font-bold text-slate-700 text-[11px]">Ganti Mode Role:</span>
<div className="flex gap-1.5">
<button
onClick={() => {
setRole('superadmin');
setActiveTab('dashboard');
triggerToast("Switch ke role: Super Admin");
}}
className={`px-2.5 py-1 rounded-lg text-[10px] font-bold flex items-center gap-1 cursor-pointer transition-all ${
role === 'superadmin' ? 'bg-[#EC167F] text-white shadow-2xs' : 'bg-white text-slate-600 border border-slate-200'
}`}
>
<Shield className="w-3 h-3" /> Superadmin
</button>
<button
onClick={() => {
setRole('owner');
setActiveTab('dashboard');
triggerToast("Switch ke role: Bisnis Owner");
}}
className={`px-2.5 py-1 rounded-lg text-[10px] font-bold flex items-center gap-1 cursor-pointer transition-all ${
role === 'owner' ? 'bg-[#EC167F] text-white shadow-2xs' : 'bg-white text-slate-600 border border-slate-200'
}`}
>
<Briefcase className="w-3 h-3" /> Bisnis Owner
</button>
</div>
</div>
{/* Action Bar Button inside sheet */}
<div className="p-3 border-b border-slate-100 shrink-0 flex items-center gap-2">
<button
onClick={() => {
setShowMoreMenu(false);
onOpenAddModal();
}}
className="w-full py-2 bg-[#EC167F] hover:bg-[#D41270] text-white rounded-xl text-xs font-bold flex items-center justify-center gap-1.5 shadow-xs cursor-pointer"
>
<Plus className="w-4 h-4" />
<span>{role === 'superadmin' ? 'Buat Tenant Baru' : 'Buat Reservasi Baru'}</span>
</button>
</div>
{/* Search Input for Menu */}
<div className="px-3 pt-2 pb-1 shrink-0">
<div className="relative">
<input
type="text"
placeholder="Cari menu navigasi..."
value={mobileSearch}
onChange={(e) => setMobileSearch(e.target.value)}
className="w-full pl-8 pr-3 py-1.5 bg-slate-100 border border-slate-200/80 rounded-xl text-xs focus:bg-white focus:outline-none focus:ring-2 focus:ring-pink-500/20"
/>
<Search className="w-3.5 h-3.5 text-slate-400 absolute left-2.5 top-2.5" />
</div>
</div>
{/* Scrollable Menu Items Grid */}
<div className="p-3 overflow-y-auto flex-1 grid grid-cols-2 gap-2 custom-scrollbar">
{filteredMenus.map(item => {
const Icon = item.icon;
const isActive = activeTab === item.id;
return (
<button
key={item.id}
onClick={() => {
setActiveTab(item.id);
setShowMoreMenu(false);
}}
className={`flex items-center gap-2.5 p-2.5 rounded-xl border text-left text-xs font-bold transition-all cursor-pointer ${
isActive
? 'bg-pink-50 border-pink-200 text-[#EC167F] shadow-2xs'
: 'bg-slate-50/80 border-slate-200/60 text-slate-700 hover:bg-slate-100'
}`}
>
<div className={`p-1.5 rounded-lg shrink-0 ${isActive ? 'bg-[#EC167F] text-white' : 'bg-white text-slate-600 border border-slate-200'}`}>
<Icon className="w-4 h-4" />
</div>
<span className="truncate flex-1 text-[11px]">{item.label}</span>
{item.badge && (
<span className="text-[8px] font-extrabold px-1 py-0.2 rounded bg-purple-100 text-purple-700">
{item.badge}
</span>
)}
</button>
);
})}
</div>
{/* Sheet Footer */}
<div className="p-3 bg-slate-50 border-t border-slate-100 text-center shrink-0">
<p className="text-[10px] text-slate-400 font-medium">MuaKita App Version 1.0 • Mobile View</p>
</div>
</div>
</div>
)}
</>
);
};