import { serverClient } from "@/lib/trpc/server"

import BreadcrumbsComp from "@/components/TempDesignSystem/Breadcrumbs"
import { generateBreadcrumbsSchema } from "@/utils/jsonSchemas"

export default async function Breadcrumbs() {
  const breadcrumbs = await serverClient().contentstack.breadcrumbs.get()

  if (!breadcrumbs?.length) {
    return null
  }
  const jsonSchema = generateBreadcrumbsSchema(breadcrumbs)

  return (
    <>
      <script
        type={jsonSchema.type}
        dangerouslySetInnerHTML={{
          __html: JSON.stringify(jsonSchema.jsonLd),
        }}
      />
      <BreadcrumbsComp breadcrumbs={breadcrumbs} />
    </>
  )
}
