"use client"

import { usePermissionStore } from "@/components/label/store/auth"
import AppLayout from "@/components/layout/AppLayout"
import { PathnameRecorder } from "@/components/layout/PathnameRecorder"
import { componentList, showList } from "@/components/layout/common"
import { useMemo } from "react"

// async function getMenu() {
//   return [...componentList, ...showList]
// }

export default function Layout({ children }: { children: React.ReactNode }) {
  const detailInfo = usePermissionStore((s) => s.detailInfo)

  const menu = useMemo(() => {
    if (detailInfo?.roles?.length) {
      return [...componentList, ...showList]
    } else {
      return [...componentList, ...showList].filter(
        (item) => item.title !== "管理中心"
      )
    }
  }, [detailInfo?.roles?.length])

  return (
    <AppLayout menu={menu}>
      {children}
      <PathnameRecorder menu={menu} />
    </AppLayout>
  )
}
