Files
SweetHome/app/components/BottomNav.js

107 lines
3.5 KiB
JavaScript
Raw Normal View History

2026-06-04 22:54:34 +03:00
"use client";
import Link from "next/link";
import { usePathname } from "next/navigation";
2026-08-10 22:27:28 +03:00
import { Home, Building2, Building, CalendarCheck, CalendarDays, ClipboardList, CreditCard, BookOpenCheck } from "lucide-react";
2026-06-04 22:54:34 +03:00
import React, { useEffect, useState } from "react";
import { useTranslation } from "react-i18next";
import { label } from "framer-motion/client";
2026-06-04 22:54:34 +03:00
export default function BottomNav({ isOwner, isOwnerOrAgent }) {
const { t } = useTranslation();
const pathname = usePathname();
2026-06-04 22:54:34 +03:00
const [isMounted, setIsMounted] = useState(false);
const bookingsHref = isOwner ? "/owner/reservations" : "/reservations";
useEffect(() => {
setIsMounted(true);
}, []);
const items = [
{ href: "/", label: t("home"), icon: Home },
2026-08-10 22:27:28 +03:00
{ href: "/properties", label: t("ourProperties"), icon: Building2 },
...(isOwnerOrAgent
? [
2026-08-10 22:27:28 +03:00
{ href: "/owner/properties", label: t("myProperties"), icon: Building },
{ href: "/owner/bookings", label: t("Myseizedproperties"), icon: CalendarCheck },
{ href: "/reservations", label: t("Mybookings"), icon: CalendarDays },
]
: [{ href: "/booked-properties", label: t("Mybookings"), icon: CalendarDays }]),
{ href: bookingsHref, label: t("Orders"), icon: ClipboardList },
{ href: "/payments", label: t("payments"), icon: CreditCard },
2026-08-10 22:27:28 +03:00
...(isOwnerOrAgent ? [{ href: "/owner/account-book", label: t("accountBook"), icon: BookOpenCheck }] : []),
2026-06-04 22:54:34 +03:00
];
const isActive = (href) => {
if (href === "/") return pathname === "/";
return pathname.startsWith(href);
};
2026-06-04 22:54:34 +03:00
return (
2026-08-10 22:27:28 +03:00
<div className="fixed bottom-0 left-0 right-0 z-50 flex justify-center px-5 pb-4 pt-4 pointer-events-none">
2026-08-08 14:22:34 +03:00
<nav
className="
w-fit max-w-full
rounded-3xl
bg-gray-50
2026-08-10 22:27:28 +03:00
px-5 py-3 sm:px-4
2026-08-08 14:22:34 +03:00
shadow-[0_4px_24px_rgba(251,146,60,0.25)]
pointer-events-auto
"
>
<div className="flex items-center justify-center gap-0.5 sm:gap-1 overflow-hidden ">
{items.map((it) => {
const Icon = it.icon;
const active = isActive(it.href);
2026-08-08 14:22:34 +03:00
return (
<Link
key={it.href}
href={it.href}
style={{ padding: "3px", width: "115px" }}
2026-08-08 14:22:34 +03:00
className={`
flex
flex-col
items-center
justify-center
rounded-xl
transition-all
duration-200
ease-out
${active ? "bg-white shadow-sm text-amber-600" : "text-gray-700 hover:bg-white/80 hover:text-amber-600 hover:shadow-md"}
`}
>
<div className="relative">
2026-08-08 14:22:34 +03:00
<Icon className="h-5 w-5 sm:h-6 sm:w-6" />
{it.badge > 0 && (
2026-08-08 14:22:34 +03:00
<div
className="
absolute -right-2 -top-2
flex h-6 w-7 sm:h-5 sm:w-5
items-center justify-center
rounded-full
bg-red-500
text-[9px] sm:text-xs
font-bold
text-white
"
>
{it.badge > 9 ? "9+" : it.badge}
</div>
)}
</div>
2026-08-08 14:22:34 +03:00
<div className="mt-0.5 text-[10px] sm:mt-1 text-center sm:text-xs">{it.label}</div>
</Link>
);
})}
</div>
</nav>
</div>
2026-06-04 22:54:34 +03:00
);
}