import Link from "next/link";
import { ReactNode } from "react";
import styles from "./Title.module.css";

type TitleProps = {
  children: ReactNode;
  className?: string;
  color?: string;
  align?: string;
  size?: "sm";
  href?: string;
};

const Title = (props: TitleProps) => {
  const {
    className = "",
    children,
    color = "white",
    align = "center",
    size,
    href,
    ...rest
  } = props;
  const classNames = [
    styles.title,
    styles[color],
    styles[align],
    size && styles[size],
    className,
  ].filter(Boolean);

  const content = (
    <div className={classNames.join(" ")} {...rest}>
      {children}
    </div>
  );

  if (href) {
    return (
      <Link href={href} className={styles.link}>
        {content}
      </Link>
    );
  }

  return content;
};

export default Title;
