import { useQuery } from "react-query"
import PageContentSkeleton from "~/common/components/skeleton/PageContentSkeleton"
import { PageContentProps } from "~/common/types/pageContent"
import { getPageContent } from "~/services/pageContent"

type Props = {
  path: string
}

const PageContent = ({ path }: Props) => {
  const { data, isLoading } = useQuery<PageContentProps>(`page-content:${path}`, async () => await getPageContent({ path }))

  if (isLoading) {
    return <PageContentSkeleton />
  }

  return (
    <div dangerouslySetInnerHTML={{ __html: data?.content || '' }}></div>
  )
}

export default PageContent