import React, { useContext } from 'react';
import { ProductContext } from './ProductCard';
import styles from '../styles/styles.module.css';

export interface Props extends React.HTMLAttributes<HTMLSpanElement> {
  title?: string;
}

export const ProductTitle = ({
  title = '',
  className,
  ...restProps
}: Props) => {
  const { product } = useContext(ProductContext);

  const titleToUse = title || product.title;

  return (
    <span
      className={`${styles.productDescription} ${className}`}
      {...restProps}
    >
      {titleToUse}
    </span>
  );
};

export default ProductTitle;
