import { Link, useLocation } from "react-router-dom";
import { createPageUrl } from "@/utils";
import {
LayoutDashboard, Users, Map, TreePine,
CloudOff, Menu, X, ChevronRight, Shield, Wifi, WifiOff, RefreshCw
} from "lucide-react";
import { useState, useEffect } from "react";
import { Button } from "@/components/ui/button";
import { cn } from "@/lib/utils";
import { getPendingSyncCount, isOnline } from "@/components/common/OfflineStorage";
function SyncIndicator() {
const [online, setOnline] = useState(isOnline());
const [pendingCount, setPendingCount] = useState(getPendingSyncCount());
useEffect(() => {
// const handleOnline = () => setOnline(true);
// const handleOffline = () => setOnline(false);
const handleOnline = () => navigator.onLine;
const handleOffline = () => !navigator.onLine;
window.addEventListener('online', handleOnline);
window.addEventListener('offline', handleOffline);
const interval = setInterval(() => {
setPendingCount(getPendingSyncCount());
}, 2000);
return () => {
window.removeEventListener('online', handleOnline);
window.removeEventListener('offline', handleOffline);
clearInterval(interval);
};
}, []);
return (
{online ? (
) : (
)}
{online ? "Online" : "Offline"}
{pendingCount > 0 ? `${pendingCount} data menunggu sync` : "Data tersinkronisasi"}
);
}
const navigation = [
{ name: "Dashboard", page: "Dashboard", icon: LayoutDashboard },
{ name: "Petani", page: "Farmers", icon: Users },
{ name: "Lahan", page: "Lands", icon: Map },
{ name: "Tanaman", page: "Plants", icon: TreePine },
{ name: "Produktivitas", page: "ProductivityMonitoring", icon: LayoutDashboard },
{ name: "Validator", page: "Validators", icon: Shield },
{ name: "Offtaker", page: "Offtakers", icon: Users },
{ name: "Portal Petani", page: "FarmerPortal", icon: Users },
{ name: "Portal Validator", page: "ValidatorPortal", icon: Shield },
{ name: "Portal Offtaker", page: "OfftakerPortal", icon: Users },
];
export default function Layout({ children, currentPageName }) {
const [sidebarOpen, setSidebarOpen] = useState(false);
const location = useLocation();
const isActivePage = (pageName) => {
return currentPageName === pageName || location.pathname.includes(pageName.toLowerCase());
};
return (
{/* Mobile Header */}
{/* Mobile Sidebar Overlay */}
{sidebarOpen && (
setSidebarOpen(false)}
/>
)}
{/* Sidebar */}
{/* Main Content */}
{children}
);
}