import { useState } from 'react'

import styled from 'styled-components/macro'

type LogoImgProps = {
  isLogoError: boolean,
}
export const LogoImg = styled.img<LogoImgProps>`
  height: 25px;
  width: 25px;
  margin-right: 15px;
  display: ${({ isLogoError }) => (isLogoError ? 'none' : '')};
  filter: grayscale(1);

  :hover {
    filter: none;
  }
`

type Props = {
  src: string,
}

export const TeamLogoImg = ({
  src,
}: Props) => {
  const [isLogoError, setIsImgError] = useState(false)

  const onError = () => setIsImgError(true)

  return (
    <LogoImg
      src={src}
      onError={onError}
      isLogoError={isLogoError}
    />
  )
}
