2025-09-16 21:05:04 +03:00

190 lines
6.6 KiB
TypeScript

import { ReactNode } from 'react';
import { motion } from 'framer-motion';
import {
Home,
TrendingUp,
Trophy,
User,
Bot,
Menu,
X
} from 'lucide-react';
import { useState } from 'react';
import Link from 'next/link';
import { useRouter } from 'next/router';
import { useWalletStore } from '../store/wallet';
import { useLiffStore } from '../store/liff';
interface LayoutProps {
children: ReactNode;
}
export default function Layout({ children }: LayoutProps) {
const [isMobileMenuOpen, setIsMobileMenuOpen] = useState(false);
const router = useRouter();
const { isConnected, address, connectWallet, disconnectWallet } = useWalletStore();
const { profile } = useLiffStore();
const navigation = [
{ name: 'Home', href: '/', icon: Home },
{ name: 'Strategies', href: '/strategies', icon: TrendingUp },
{ name: 'Missions', href: '/missions', icon: Trophy },
{ name: 'Portfolio', href: '/portfolio', icon: User },
];
const isActive = (href: string) => router.pathname === href;
const truncateAddress = (addr: string) => {
return `${addr.slice(0, 6)}...${addr.slice(-4)}`;
};
return (
<div className="min-h-screen bg-gray-50">
{/* Top Navigation */}
<header className="bg-white shadow-sm border-b sticky top-0 z-50">
<div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
<div className="flex justify-between items-center h-16">
{/* Logo */}
<Link href="/" className="flex items-center space-x-2">
<Bot className="h-8 w-8 text-primary-500" />
<span className="font-bold text-xl text-gray-900">KAIA YIELD AI</span>
</Link>
{/* Desktop Navigation */}
<nav className="hidden md:flex space-x-8">
{navigation.map((item) => {
const Icon = item.icon;
return (
<Link
key={item.name}
href={item.href}
className={`flex items-center space-x-2 px-3 py-2 rounded-md text-sm font-medium transition-colors ${
isActive(item.href)
? 'text-primary-600 bg-primary-50'
: 'text-gray-700 hover:text-primary-600 hover:bg-gray-50'
}`}
>
<Icon className="h-4 w-4" />
<span>{item.name}</span>
</Link>
);
})}
</nav>
{/* Wallet Connection */}
<div className="flex items-center space-x-4">
{isConnected ? (
<div className="flex items-center space-x-2">
{profile && (
<div className="hidden sm:flex items-center space-x-2">
<img
src={profile.pictureUrl}
alt={profile.displayName}
className="h-8 w-8 rounded-full"
/>
<span className="text-sm font-medium text-gray-700">
{profile.displayName}
</span>
</div>
)}
<div className="bg-primary-50 px-3 py-1 rounded-lg">
<span className="text-xs font-medium text-primary-700">
{truncateAddress(address!)}
</span>
</div>
<button
onClick={disconnectWallet}
className="text-xs text-gray-500 hover:text-gray-700"
>
Disconnect
</button>
</div>
) : (
<motion.button
whileHover={{ scale: 1.05 }}
whileTap={{ scale: 0.95 }}
onClick={connectWallet}
className="bg-primary-600 text-white px-4 py-2 rounded-lg text-sm font-medium hover:bg-primary-700 transition-colors"
>
Connect Wallet
</motion.button>
)}
{/* Mobile menu button */}
<button
onClick={() => setIsMobileMenuOpen(!isMobileMenuOpen)}
className="md:hidden p-2 rounded-md text-gray-700 hover:bg-gray-100"
>
{isMobileMenuOpen ? (
<X className="h-6 w-6" />
) : (
<Menu className="h-6 w-6" />
)}
</button>
</div>
</div>
</div>
{/* Mobile Navigation */}
{isMobileMenuOpen && (
<motion.div
initial={{ opacity: 0, y: -10 }}
animate={{ opacity: 1, y: 0 }}
exit={{ opacity: 0, y: -10 }}
className="md:hidden bg-white border-t"
>
<div className="px-2 pt-2 pb-3 space-y-1">
{navigation.map((item) => {
const Icon = item.icon;
return (
<Link
key={item.name}
href={item.href}
onClick={() => setIsMobileMenuOpen(false)}
className={`flex items-center space-x-3 px-3 py-2 rounded-md text-base font-medium ${
isActive(item.href)
? 'text-primary-600 bg-primary-50'
: 'text-gray-700 hover:text-primary-600 hover:bg-gray-50'
}`}
>
<Icon className="h-5 w-5" />
<span>{item.name}</span>
</Link>
);
})}
</div>
</motion.div>
)}
</header>
{/* Main Content */}
<main className="max-w-7xl mx-auto pb-20 md:pb-6">
{children}
</main>
{/* Bottom Navigation (Mobile) */}
<div className="md:hidden fixed bottom-0 left-0 right-0 bg-white border-t shadow-lg">
<div className="grid grid-cols-4 py-2">
{navigation.map((item) => {
const Icon = item.icon;
return (
<Link
key={item.name}
href={item.href}
className={`flex flex-col items-center py-2 px-1 ${
isActive(item.href)
? 'text-primary-600'
: 'text-gray-500 hover:text-primary-600'
}`}
>
<Icon className="h-6 w-6 mb-1" />
<span className="text-xs font-medium">{item.name}</span>
</Link>
);
})}
</div>
</div>
</div>
);
}