import { isUndefined } from 'lodash'
import Link from 'next/link'
import { ReactNode } from 'react'
import { useFlag } from 'hooks/ui/useFlag'
import { ArrowUpRight, LogOut } from 'lucide-react'
import { Badge, cn, Menu } from 'ui'
import { LayoutHeader } from '../ProjectLayout/LayoutHeader'
import type { SidebarLink, SidebarSection } from './AccountLayout.types'
interface WithSidebarProps {
title: string
breadcrumbs: any[]
sections: SidebarSection[]
header?: ReactNode
subitems?: any[]
subitemsParentKey?: number
hideSidebar?: boolean
customSidebarContent?: ReactNode
children: ReactNode
}
const WithSidebar = ({
title,
header,
breadcrumbs = [],
children,
sections,
subitems,
subitemsParentKey,
hideSidebar = false,
customSidebarContent,
}: WithSidebarProps) => {
const noContent = !sections && !customSidebarContent
const navLayoutV2 = useFlag('navigationLayoutV2')
return (
{!hideSidebar && !noContent && (
)}
{!navLayoutV2 &&
}
{children}
)
}
export default WithSidebar
interface SectionWithHeadersProps {
section: SidebarSection
subitems?: any[]
subitemsParentKey?: number
}
const SectionWithHeaders = ({ section, subitems, subitemsParentKey }: SectionWithHeadersProps) => (
{section.heading &&
}
{section.versionLabel && (
{section.versionLabel}
)}
{
}
)
interface SidebarItemProps {
links: SidebarLink[]
subitems?: any[]
subitemsParentKey?: number
}
const SidebarItem = ({ links, subitems, subitemsParentKey }: SidebarItemProps) => {
return (
{links.map((link, i: number) => {
// disable active state for link with subitems
const isActive = link.isActive && !subitems
let render: any = (
)
if (subitems && link.subitemsKey === subitemsParentKey) {
const subItemsRender = subitems.map((y: any, i: number) => (
))
render = [render, ...subItemsRender]
}
return render
})}
)
}
interface SidebarLinkProps extends SidebarLink {
id: string
isSubitem?: boolean
}
const SidebarLinkItem = ({
id,
label,
href,
isActive,
isSubitem,
isExternal,
onClick,
icon,
}: SidebarLinkProps) => {
if (isUndefined(href)) {
let icon
if (isExternal) {
icon =
}
if (label === 'Log out') {
icon =
}
return (
{})}
icon={icon}
>
{isSubitem ? {label}
: label}
)
}
return (
{isExternal && (
)}
{isSubitem ? {label}
: label}
{icon}
)
}