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

import styled from 'styled-components/macro'

import { devices } from 'config'

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

export const TooltipWrapper = styled(TooltipBlockWrapper)`
  position: absolute;
  top: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  padding: 8px 12px;
  font-weight: normal;
  font-size: 14px;
  line-height: 18px;
  text-align: center;
  display: none;

  @media ${devices.tablet} {
    top: calc(100% + 16px);
  }

  &::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>
)
