import React from 'react'
import styled from 'styled-components'

export type TooltipProps = {
  /**
   * icon to represent the tooltip
   */
  icon: React.ReactNode;
  /**
   * text to display on hover
   */
  info: string;
  /**
   * additional css that you might want to use to style the tooltip
   */
  css?: string;
};

export const Tooltip = ({ icon,info,css }: TooltipProps):JSX.Element  => {
  return (
    <IconContainer css={css}>
      <TooltipContainer className="tooltip">
        {info}
      </TooltipContainer>
      {icon}
    </IconContainer>
  )
}

const IconContainer = styled.div<{css?:string}>`
  height: 24px;
  width: 24px;
  position: relative;
  cursor: pointer;
  
  &:hover {
    .tooltip {
      display: block
      }
    }

  ${(p) => p.css}  
`

const TooltipContainer = styled.div`
  padding: 10px;
  position: absolute;
  width: auto;
  white-space: nowrap;
  word-wrap: no-wrap;
  box-shadow: 1px 1px 20px #aaa;
  border-radius: 5px;
  background-color: #fff;
  top: 30px;
  left: 50%;
  transform: translate(-50%);
  transform-style: preserve-3d;
  z-index: 200;
  font-size: 0.9rem;
  display: none;
`