import React, { useEffect, useState } from 'react'
import { Redirect, useRouteMatch } from 'react-router-dom'
import { connect } from 'react-redux';
import WrapperPanelComponent from "../../utility/hoc/wrapper-panel/wrapper-panel.component"
import { TermsAndConditionContentComponent } from './terms_and_conditions.component'
import WithSpinner from '../../utility/hoc/spinner/with-spinner.component'
import ToastComponent from '../../utility/toast/toast.component'

import { getTermsAndConditionsContent } from '../../../redux/user/selectors'

const TermsAndConditionWrapperComponent = ({
    content,    
}) => {
    const [showContent, setShowContent] = useState(true)
    let { path } = useRouteMatch()
    const spliitedPath = path.split('/')

    // console.log(path, spliitedPath)
    useEffect(() =>{
        return () =>{
            
        }
    },[])

    
    if (!showContent)
        return <Redirect to={`/${spliitedPath[1]}/graph_list`} />


    const onTermsConditionComponentHide = () => {
        setShowContent(false)
        
    }

    return (  
        <WrapperPanelComponent>
            <div className="body">
                <div className="containers">
                    <TermsAndConditionContentComponent readOnly={true} 
                    show={showContent} 
                    onHide={onTermsConditionComponentHide}
                    content={content}
                    />                    
                </div>                          
            </div>
        </WrapperPanelComponent>
    )
}

const mapStateToProps = (state) => ({
  content: getTermsAndConditionsContent(state)  
})

const mapDispatchToProps = dispatch => ({
    
})

export default connect(mapStateToProps, mapDispatchToProps)(TermsAndConditionWrapperComponent)
    

