/**
 * Copyright (c) Facebook, Inc. and its affiliates.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 * 
 * Modified by David Garcia for Finboot.
 *
 * Modfications: 
 * - Show descriptions on Blog List Page.
 */

import clsx from 'clsx';
import React from 'react';

import type {Props} from '@theme/BlogPostItem/Content';
// @ts-ignore the api exists on the package but is not exposed
import { useBlogPost } from '@docusaurus/theme-common/internal';
import { blogPostContainerID } from '@docusaurus/utils-common';
import MDXContent from '@theme/MDXContent';

export default function BlogPostItemContent({
  children,
  className,
}: Props): JSX.Element {
  const {isBlogPostPage, metadata} = useBlogPost();

  let description, content;
  if(isBlogPostPage) {
    content = ( <div
      // This ID is used for the feed generation to locate the main content
      id={isBlogPostPage ? blogPostContainerID : undefined}
      className={clsx('markdown', className)}
      itemProp="articleBody">
      <MDXContent>{children}</MDXContent>
    </div>);
  } else {
    description =  (<p>{metadata.frontMatter.description}</p>);
  }

  return (
    <>
      {description}
      {content}
    </>
  );
}
