import * as React from 'react';
import PropsTypes from './types';
import Helmet from 'react-helmet';

const defaultTitle = 'App';
const defaultDescription = '';

export default class Page extends React.Component<PropsTypes, {}> {


    getMetaTags({title, description}) {
        const theTitle = title ? title.substring(0, 60) : defaultTitle;
        const theDescription = description ? description.substring(0, 155) : defaultDescription;

        const metaTags = [
            {itemprop: 'name', content: theTitle},
            {itemprop: 'description', content: theDescription},
            {name: 'description', content: theDescription},
        ];

        return metaTags;
    }


    render() {

        const { children, ...rest } = this.props;

        return <>
            <Helmet
                htmlAttributes={{
                    lang: 'en',
                }}
                title={
                    rest.title ? rest.title : defaultTitle
                }
                link={[ ]}
                meta={this.getMetaTags(rest)}
            />
            {children}
        </>
    }
}
