import Link from "next/link";
import { useRouter } from "next/router";
import {
Listbox,
ListboxButton,
ListboxOption,
ListboxOptions,
} from "@headlessui/react";
import { t } from "@lingui/core/macro";
import { env } from "next-runtime-env";
import { useEffect, useState } from "react";
import {
HiChevronDown,
HiOutlineBanknotes,
HiOutlineCodeBracketSquare,
HiOutlineRectangleGroup,
HiOutlineUser,
} from "react-icons/hi2";
interface SettingsLayoutProps {
children: React.ReactNode;
currentTab: string;
}
export function SettingsLayout({ children, currentTab }: SettingsLayoutProps) {
const router = useRouter();
const [selectedTabIndex, setSelectedTabIndex] = useState(0);
const settingsTabs = [
{
key: "account",
icon: ,
label: t`Account`,
condition: true,
},
{
key: "workspace",
icon: ,
label: t`Workspace`,
condition: true,
},
{
key: "billing",
label: t`Billing`,
icon: ,
condition: env("NEXT_PUBLIC_KAN_ENV") === "cloud",
},
{
key: "api",
icon: ,
label: t`API`,
condition: true,
},
{
key: "integrations",
icon: ,
label: t`Integrations`,
condition: true,
},
];
const availableTabs = settingsTabs.filter((tab) => tab.condition);
// Update selected tab when currentTab prop changes
useEffect(() => {
const tabIndex = availableTabs.findIndex((tab) => tab.key === currentTab);
if (tabIndex !== -1) {
setSelectedTabIndex(tabIndex);
}
}, [currentTab, availableTabs]);
const isTabActive = (tabKey: string) => {
return currentTab === tabKey;
};
return (
{t`Settings`}
{/* Mobile dropdown */}
{
const tabKey = availableTabs[index]?.key;
if (tabKey) {
void router.push(`/settings/${tabKey}`);
}
}}
>
{availableTabs[selectedTabIndex]?.label || "Select a tab"}
{availableTabs.map((tab) => (
{tab.label}
))}
{children}
);
}