import { useApp } from "@/pages/app/AppContext";
import type { ScreenId } from "@/pages/app/types";
import { cn } from "@/pages/app/components/ui";

interface TabDef {
  id: ScreenId;
  label: string;
  icon: string;
  activeIcon: string;
}

const TABS: TabDef[] = [
  { id: "invHome", label: "الرئيسية", icon: "ri-home-5-line", activeIcon: "ri-home-5-fill" },
  { id: "invBusinesses", label: "المنشآت", icon: "ri-store-2-line", activeIcon: "ri-store-2-fill" },
  { id: "invFollowing", label: "المتابعة", icon: "ri-bookmark-3-line", activeIcon: "ri-bookmark-3-fill" },
  { id: "invChats", label: "المحادثات", icon: "ri-chat-3-line", activeIcon: "ri-chat-3-fill" },
  { id: "invProfile", label: "حسابي", icon: "ri-user-3-line", activeIcon: "ri-user-3-fill" },
];

export default function InvTabBar() {
  const { screen, jump } = useApp();

  return (
    <div className="shrink-0 bg-background-100 border-t border-background-200">
      <div className="flex items-stretch pt-2 pb-5">
        {TABS.map((tab) => {
          const active = screen === tab.id;
          return (
            <button
              key={tab.id}
              type="button"
              onClick={() => jump(tab.id)}
              className="flex-1 flex flex-col items-center gap-1 cursor-pointer"
            >
              <div
                className={cn(
                  "w-9 h-9 rounded-full flex items-center justify-center transition-colors",
                  active ? "bg-primary-500" : "bg-transparent",
                )}
              >
                <i
                  className={cn(
                    active ? tab.activeIcon : tab.icon,
                    "text-[20px] leading-none",
                    active ? "text-background-50" : "text-foreground-500",
                  )}
                />
              </div>
              <span
                className={cn(
                  "text-[10.5px] font-medium leading-none",
                  active ? "text-foreground-950" : "text-foreground-500",
                )}
              >
                {tab.label}
              </span>
            </button>
          );
        })}
      </div>
    </div>
  );
}