import React, { Component } from 'react'
import { Snackbar } from '@material-ui/core';
import Card from '@material-ui/core/Card';
import CardActionArea from '@material-ui/core/CardActionArea';
import CardActions from '@material-ui/core/CardActions';
import CardContent from '@material-ui/core/CardContent';
import Typography from '@material-ui/core/Typography';
import { withStyles } from '@material-ui/core/styles';
import IconButton from '@material-ui/core/IconButton';
import CloseIcon from '@material-ui/icons/Close';
import cookie from 'react-cookies'

const styles = theme => ({
    cardSnack: {
        maxWidth: '100%'
    }
});
class CookiesRGPD extends Component {
    state = {
        openSnack: false
    }
    handleClose = () => {
        this.setState({ openSnack: false });
        cookie.save('RGPD', true, {
            path: '/'
        });
    }

    componentDidMount() {
        if (typeof window !== 'undefined') {
            // don't show if we are in App
            if (window.navigator.standalone ||
                window.matchMedia('(display-mode: standalone)').matches) {
                this.setState({ openSnack: false })
            } else {

                this.setState({ openSnack: !cookie.load('RGPD') })
            }
        }
    }
    render() {
        const { classes } = this.props;
        return (
            <Snackbar
                anchorOrigin={{
                    vertical: 'bottom',
                    horizontal: 'left',
                }}
                autoHideDuration={null}
                open={this.state.openSnack}
                onClose={this.handleClose}
            >
                <Card className={classes.cardSnack}>
                    <CardActionArea>
                        <CardContent>
                            <Typography gutterBottom variant="h5" component="h2">
                                Utilisation des cookies
                        </Typography>
                            <Typography component="p">
                                En poursuivant votre navigation, vous acceptez l'utilisation de cookies ou technologies similaires, y compris de partenaires tiers pour la diffusion de publicité ciblée et de contenus pertinents au regard de vos centres d'intérêts. En savoir plus.
                                Afin de continuer à améliorer la protection de vos données personnelles, nous avons mis à jour notre politique de confidentialité.
                         </Typography>
                        </CardContent>
                    </CardActionArea>
                    <CardActions>
                        <IconButton
                            key="close"
                            aria-label="Close"
                            color="inherit"
                            className={classes.close}
                            onClick={this.handleClose}
                        >
                            <CloseIcon />
                        </IconButton>
                    </CardActions>
                </Card>
            </Snackbar>
        )
    }
}

export default withStyles(styles)(CookiesRGPD)