import { cn } from "@/src/utils/tailwind"; import { ArrowUpRight } from "lucide-react"; import Link from "next/link"; import { type ReactNode } from "react"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "@/src/components/ui/select"; import { useRouter } from "next/router"; type SettingsProps = { pages: Array< { title: string; slug: string; show?: boolean | (() => boolean); } & ({ content: ReactNode } | { href: string }) >; activeSlug?: string; }; export const PagedSettingsContainer = ({ pages, activeSlug, }: SettingsProps) => { const router = useRouter(); const availablePages = pages.filter((page) => "show" in page ? typeof page.show === "function" ? page.show() : page.show : true, ); const currentPage = availablePages.find((page) => page.slug === activeSlug) ?? availablePages[0]; // Fallback to first page if not found const onChange = (newSlug: string) => { const pathSegments = router.asPath.split("/"); if (pathSegments[pathSegments.length - 1] !== "settings") pathSegments.pop(); if (newSlug !== "index") pathSegments.push(newSlug); router.push(pathSegments.join("/")); }; return (
{currentPage && "content" in currentPage ? currentPage.content : null}
); };