import type { ReactNode } from 'react'
import { Fragment } from 'react'

import styled from 'styled-components/macro'

import { TooltipBlockWrapper } from 'features/UserFavorites/TooltipBlock/styled'
import { T9n } from 'features/T9n'

export const TooltipWrapper = styled(TooltipBlockWrapper)`
  position: absolute;
  top: calc(100% + 0.38rem);
  left: 50%;
  transform: translateX(-50%);
  padding: 0.38rem 0.567rem;
  font-weight: normal;
  font-size: 0.65rem;
  line-height: 0.85rem;
  text-align: center;
  display: none;

  &::before {
    left: 50%;
    transform: translateX(-50%);
  }
`

type Props = {
  children?: ReactNode,
  lexic: string,
}

export const Tooltip = ({
  children,
  lexic,
}: Props) => (
  <Fragment>
    <TooltipWrapper top={0}>
      <T9n t={lexic} />
    </TooltipWrapper>
    {children}
  </Fragment>
)
