import { h } from 'preact'
import { bool, string } from 'prop-types'
import Helmet from 'react-helmet'

const siteTitle = 'Underscore Streams'

function SEO({ description, title, metaImg: imgSrc, noindex }) {
  return (
    <Helmet
      htmlAttributes={{
        lang: 'en',
      }}
      title={title}
      titleTemplate={`%s \\ ${siteTitle}`}
      meta={[
        {
          name: 'description',
          content: description,
        },
        {
          property: 'og:title',
          content: title ? `${title} \\\\ ${siteTitle}` : siteTitle,
        },
        {
          property: 'og:url',
          content: 'https://looseantenna.fm',
        },
        {
          property: 'og:description',
          content: description,
        },
        {
          property: 'og:image',
          content: imgSrc,
        },
        {
          property: 'og:type',
          content: 'website',
        },
        {
          name: 'twitter:card',
          content: 'summary',
        },
        {
          name: 'twitter:title',
          content: title,
        },
        {
          name: 'twitter:image',
          content: `${imgSrc}`,
        },
        {
          name: 'twitter:description',
          content: description,
        },
        {
          name: 'apple-mobile-web-app-capable',
          content: 'yes',
        },
        (noindex ? {
          name: 'robots',
          content: 'noindex',
        } : {}),
      ].concat()}
    />
  )
}

SEO.defaultProps = {
  meta: [],
  description: '',
}

SEO.propTypes = {
  description: string,
  metaImg: string,
  title: string.isRequired,
  noindex: bool,
}

export default SEO
