import { CardAttributeContent } from '@/components/card/components/card-content/CardAttributeContent';
import { CardContent } from '@/components/card/components/card-content/CardContent';
import { CardDescription } from '@/components/card/components/card-description/CardDescription';
import { CardFooter } from '@/components/card/components/card-footer/CardFooter';
import { CardFooterWithLike } from '@/components/card/components/card-footer/CardFooterWithLike';
import { CardFooterWithRange } from '@/components/card/components/card-footer/CardFooterWithRange';
import { CardLike } from '@/components/card/components/card-like/CardLike';
import { CardTitle } from '@/components/card/components/card-title/CardTitle';
import { CardContext } from '@/components/card/context/CardContext';
import { classNames } from '@/utils/classNames';

type TCardProps = {
  children: React.ReactNode;
  theme: 'light' | 'dark';
  className?: string;
  isLink?: boolean;
};

function Card({ children, theme, className = '', isLink = false }: TCardProps): React.ReactElement {
  let colorScheme,
    hoverStyles = '';

  if (theme === 'light') {
    colorScheme = 'text-gray-ui before:bg-gray-ui-100';
  } else {
    colorScheme = 'text-gray-ui-100 before:bg-gray-ui';
  }

  if (isLink) {
    if (theme === 'light') {
      hoverStyles = 'hover:before:bg-yellow-ui-500';
    } else {
      hoverStyles = 'hover:before:bg-yellow-ui-500';
    }
  }

  return (
    <CardContext.Provider
      value={{
        theme,
        isLink,
      }}
    >
      <div
        className={classNames(
          'relative flex flex-col h-min border border-gray-ui/ba border-solid rounded-lg before:w-full before:h-full before:absolute before:-z-10 before:transition-all',
          colorScheme,
          hoverStyles,
          className,
        )}
      >
        {children}
      </div>
    </CardContext.Provider>
  );
}

Card.Content = CardContent;
Card.AttributeContent = CardAttributeContent;
Card.Footer = CardFooter;
Card.FooterWithLike = CardFooterWithLike;
Card.FooterWithRange = CardFooterWithRange;
Card.Title = CardTitle;
Card.Description = CardDescription;
Card.Like = CardLike;

export { Card, TCardProps };
