import React from 'react';
import ReactMarkdown from 'react-markdown';
import remarkGfm from 'remark-gfm';

// Definir los componentes con tipos más específicos
const HeadingOne: React.FC<{ children?: React.ReactNode }> = ({ children }) => (
  <h1 className="tw-text-2xl md:tw-text-[32px] md:tw-leading-[32px] tw-text-secondary-dark tw-uppercase tw-font-semibold mb-4">
    {children}
  </h1>
);
const HeadingTwo: React.FC<{ children?: React.ReactNode }> = ({ children }) => (
  <h2 className="tw-text-2xl md:tw-text-[32px] md:tw-leading-[32px] tw-text-secondary-dark tw-uppercase tw-font-semibold mb-4">
    {children}
  </h2>
);
const HeadingThree: React.FC<{ children?: React.ReactNode }> = ({ children }) => (
  <h3 className="tw-text-2xl md:tw-text-[32px] md:tw-leading-[32px] tw-text-secondary-dark tw-uppercase tw-font-semibold mb-4">
    {children}
  </h3>
);
const HeadingFour: React.FC<{ children?: React.ReactNode }> = ({ children }) => (
  <h4 className="tw-text-2xl md:tw-text-[32px] md:tw-leading-[32px] tw-text-secondary-dark tw-uppercase tw-font-semibold mb-4">
    {children}
  </h4>
);
const HeadingFive: React.FC<{ children?: React.ReactNode }> = ({ children }) => (
  <h5 className="tw-text-2xl md:tw-text-[32px] md:tw-leading-[32px] tw-text-secondary-dark tw-uppercase tw-font-semibold mb-4">
    {children}
  </h5>
);
const HeadingSix: React.FC<{ children?: React.ReactNode }> = ({ children }) => (
  <h5 className="tw-text-2xl md:tw-text-[32px] md:tw-leading-[32px] tw-text-secondary-dark tw-uppercase tw-font-semibold mb-4">
    {children}
  </h5>
);

const List: React.FC<{ children?: React.ReactNode }> = ({ children }) => (
  <ul className="tw-list-disc tw-pl-8 tw-mb-4">{children}</ul>
);

const ListItem: React.FC<{ children?: React.ReactNode }> = ({ children }) => (
  <li className="base-text !tw-font-ibm !tw-text-secondary-dark">{children}</li>
);

const Link: React.FC<{ href?: string; children?: React.ReactNode }> = ({ href, children }) => (
  <a href={href} className="tw-font-inter tw-font-normal tw-text-base tw-text-main-dark tw-underline">
    {children}
  </a>
);

const Paragraph: React.FC<{ children?: React.ReactNode }> = ({ children }) => (
  <p className="base-text !tw-font-ibm !tw-text-secondary-dark mb-4">{children}</p>
);

const MarkdownComponents: any = {
  h1: HeadingOne,
  h2: HeadingTwo,
  h3: HeadingThree,
  h4: HeadingFour,
  h5: HeadingFive,
  h6: HeadingSix,
  a: Link,
  p: Paragraph,
  ul: List,
  li: ListItem
};

const CustomMarkdown: React.FC<{ content: string; className?: string }> = ({ content, className }) => {
  return (
    <ReactMarkdown className={className} remarkPlugins={[remarkGfm]} components={MarkdownComponents}>
      {content}
    </ReactMarkdown>
  );
};

export default CustomMarkdown;
