import React from 'react';
import { Page } from '../Page';
import { Dashboard } from './Dashboard';
import { useUserProfileQuery } from '../../gql/queries/profile';
import { Loader } from '../Loader';

export function HomePage() {
  const { data, loading } = useUserProfileQuery();

  if (loading) {
    return (
      <Loader />
    );
  }

  const { userProfile } = (data || {});

  return (
    <Page title={userProfile ? 'Tableau de bord' : 'Accueil'}>
      <div className="container is-fluid">
        <section className="section">
          {
            userProfile ?
            <Dashboard /> :
            <div className="columns">
              <div className="column is-4 is-offset-4">
                <div className="box">
                  <p>Veuillez vous authentifier.</p>
                </div>
              </div>
            </div> 
          }
        </section>
      </div>
    </Page>
  );
}