import { Icon } from 'features/Icon'

import { add } from 'date-fns'
import { isIOS } from 'config'

import {
  ScBannerWrap,
  ScIconLogo,
  ScTitleWrap,
  ScTitle,
  ScNameOfCompany,
  ScDescribe,
  ScBtnDownload,
  ScIconWrap,
} from './styled'

type SmartBannerProps = {
  setIsOpenDownload: (open: boolean) => void,
}

export const SmartBanner = ({ setIsOpenDownload }: SmartBannerProps) => (
  <ScBannerWrap>
    <ScIconWrap>
      <Icon
        refIcon='Close'
        onClick={() => {
          localStorage.setItem(
            'dateLastOpenSmartBanner',
            JSON.stringify(add(new Date(), { days: 1 })),
          )
          setIsOpenDownload(false)
        }}
      />
    </ScIconWrap>
    <ScIconLogo src='/images/icon-insportstv-smart-banner.svg' />
    <ScTitleWrap>
      <ScTitle>official inSports App</ScTitle>
      <ScNameOfCompany>inSports limited</ScNameOfCompany>
      <ScDescribe>inSports – the Home of Sports Streaming</ScDescribe>
    </ScTitleWrap>
    <a
      href={isIOS
        ? 'https://apps.apple.com/es/app/insports-tv/id1643858776'
        : 'https://play.google.com/store/apps/details?id=instat.ott'}
      target='_blank'
      rel='noreferrer'
      onClick={() => {
        localStorage.setItem(
          'dateLastOpenSmartBanner',
          JSON.stringify(add(new Date(), { days: 1 })),
        )
        setIsOpenDownload(false)
      }}
    >
      <ScBtnDownload>Download</ScBtnDownload>
    </a>
  </ScBannerWrap>
)
