import React from 'react'
import type { BodyProps } from '../../Body'
import { ComponentsContext } from '../../RichText'
import { LiveBlogWrapper } from '../../LiveBlogWrapper'

//TODO: CI-1975 remove "any" types

type LiveBlogBodyProps = BodyProps & {
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
  xInteractionSerialiser?: any
}

const LiveBlogBody: React.FC<LiveBlogBodyProps> = ({
  content,
  richTextComponents,
  xInteractionSerialiser,
  showShareButtons,
  showShareLinkButton,
  postTrackerConfig,
  ads,
}) => {
  if (content.__typename !== 'LiveBlogPackage') return null

  // eslint-disable-next-line @typescript-eslint/no-explicit-any
  const posts = content.liveBlogPosts || []

  return (
    <ComponentsContext.Provider value={richTextComponents}>
      <LiveBlogWrapper
        articleUrl={`https://www.ft.com/content/${content.id}`}
        id="live-blog-wrapper"
        posts={posts}
        serialiser={xInteractionSerialiser}
        showShareButtons={showShareButtons ?? true}
        showShareLinkButton={showShareLinkButton ?? false}
        postTrackerConfig={postTrackerConfig}
        ads={ads}
      />
    </ComponentsContext.Provider>
  )
}

export default LiveBlogBody
