import React, { useState, useEffect } from "react";
import { BrowserRouter, Switch, Route } from "react-router-dom"
import './App.css';
import NotFound from './pages/NotFound'
import Contact from './pages/Contact'
import Connexion from './pages/Connexion'
import Login from './pages/Login';

import Recherche_new_v2 from "./pages/recherche_new_v2";
import Recherche_new_v3 from "./pages/recherche_new_v3";
import Recherche_new_v4 from "./pages/recherche_new_v4";

import Mon_Catalogue_Public from "./pages/mon_catalogue_public";
import Mon_Intranet_Public from "./pages/mon_intranet_public";

import TestUrl from "./pages/testurl";
import Account from "./pages/account";

import DisplayDetailClass_new_v2 from "./pages/displaydetailclass_new_v2";
import DisplayDetailClass_new_v3 from "./pages/displaydetailclass_new_v3";

import Display_Partner_Catalog_DetailClass_new_v2 from "./pages/display_partner_catalog_detailclass_new_v2"

import DisplayDetailArticle from "./pages/displaydetailarticle";
import AddArticleAvis from "./pages/addarticleavis";
import Acceuil from "./pages/acceuil";
import Partner from "./pages/partner";
import CreateAccount from "./pages/createaccount";
import PartnerLogin from "./pages/partnerlogin";
import PartnerLogin0 from "./pages/partnerlogin0";
import PartnerLogin1 from "./pages/partnerlogin1";

import RechecheArticles from "./pages/recherchearticles";
import AddArticle from "./pages/addarticle";
import ResetUserPwd from "./pages/resetuserpwd";
import DeleteUserAccount from "./pages/deleteuseraccount";

import ContactezNous from "./pages/contactez_nous";
import CoupDeCoeur from "./pages/coupdecoeur";
import AccountUserActivated from "./pages/accountuseractivated";
import ProduitsService from "./pages/produitservice";

import Recherche_new from "./pages/recherche_new";
import Recherche_old from "./pages/recherche";
import UserSignFirst from "./pages/usersigninfirst";
import GestionAdministrative from "./components/GestionAdministrative";
import Emargement from "./pages/emargementOk";
import Formation_Cartouche_Com from "./pages/recherche_cartouche_com";
import SeDesabonner from './pages/sedesabonner';
import OrderConfirmation_3DS from "./pages/orderconfirmation_3DS";
import Training_Inactive_Or_Not_Found from "./pages/Traning_Inactif_Or_Not_Exist";
import TestUrl_New from "./pages/testurl_new";
import QuiSommesNous_v3 from "./pages/quisommesnous_v3";
import Fonctionnalites from "./pages/fonctionnalite";
import Test_Drag_Drop from "./pages/test_drag_drop";
import Test_Drag_Drop2 from "./pages/test_dnd";
import ESign from "./pages/eSigne";
import ESignDiplayDignedDocument from "./pages/edigndiplaydigneddocument";
import SurveyDocument from "./pages/surveydocument";
import UpdateAttendeeList from "./pages/updateattendeelist";
import Emarge_QR_Code from "./pages/emarge_qr_code";
import AutomaticQuotation from "./pages/automaticquotation";
import MySyIA from "./pages/iamysy";
import Maintenance from "./pages/maintenance_page";
import Subdomain_Recherche_new_v2 from "./pages/subdomain_recherche_new_v2";


// New Design 2025
import New_Sign_In_2025 from "./pages/new_p_sign_in_2025";
import New_Sign_Up_2025 from "./pages/new_p_sign_up_2025";
import New_Tarif_2025 from "./pages/new_p_tarif_2025";
import New_Contact_2025 from "./pages/new_p_contact_2025";
import New_Article_Detail_2025 from "./pages/new_p_article_detail_2025";
import New_Formation_Detail_2025 from "./pages/new_p_detail_formation_2025";
import New_Marktplace_2025 from "./pages/new_p_marketplace_2025";
import New_Fonctionnalite_2025 from "./pages/new_p_fonctionnalite_2025";

import New_A_Propos_2025 from "./pages/new_p_a_propos_2025";
import New_Home_Page_2025 from "./pages/new_p_home_page_2025";


import New_Test_Header_Footer_2025 from "./pages/new_p_test_header_footer_2025";


function App() {

  const [screenSizeh, getDimension] = useState({
    dynamicWidth: window.innerHeight
  });


  const getSubdomain = url => {
    let domain = url;
    if (url.includes("://")) {
      domain = url.split('://')[1];
    }
    const subdomain = domain.split('.')[0];
    return subdomain;
  };


  useEffect(() => {

    let myurl = window.location.host;
    let myurl_pathname = window.location.pathname;



    var domain = myurl;
    if (domain.includes('://')) {
      domain = myurl.split('://')[1];
    }

    var tab_split = domain.split('.');

    const subdomain = domain.split('.')[0];

    var tab_reserved_subdomain = ['/dev', '/demo', 'demo', 'dev'];

    if (tab_split.length > 1 && myurl_pathname && !tab_reserved_subdomain.includes(subdomain)) {

      var tab_myurl_pathname = myurl_pathname.split('/');

      var tab_action = ['/moncatalog', '/Display-Partner-Catalog-Detail-formation', 'Display-Partner-Catalog-Detail-formation', 'moncatalog'];



      if (tab_myurl_pathname.length > 0 && !tab_action.includes(tab_myurl_pathname[1]) && !tab_reserved_subdomain.includes(subdomain)) {

        var new_url = window.location.protocol + "//" + domain.split('.')[0] + "." + domain.split('.')[1] + "/moncatalog";
      }


    }


  }, []);


  return (
    <div>
      <div className="App">
        {/*API DEV = {process.env.REACT_APP_API_URL_DEV} <br/>
    API REC = {process.env.REACT_APP_API_URL_REC}<br/>
    API URL = {process.env.REACT_APP_API_URL}<br/>
  */}


        <div className="main_haut">
          <BrowserRouter>
            <scrollToTop />
            <Switch>



              <Route path="/v3" exact component={Recherche_new_v3} />
              <Route path="/v4" exact component={Recherche_new_v4} />


              <Route path="/subdomain" exact component={Subdomain_Recherche_new_v2} />

              <Route path="/moncatalog" exact component={Mon_Catalogue_Public} />
              <Route path="/intranet" exact component={Mon_Intranet_Public} />


              <Route path="/acceuil" exact component={Acceuil} />

              <Route path="/maintenance" exact component={Maintenance} />


              <Route path="/markeplace" exact component={Contact} />

              <Route path="/create_account" exact component={CreateAccount} />
              <Route path="/user-connexion" exact component={Connexion} />


              <Route path="/testurl/:course/:tab" exact component={TestUrl} />
              <Route path="/testurl_new/:courseid/:tabid" exact component={TestUrl_New} />

              <Route path="/ajout-article" exact component={AddArticleAvis} />


              <Route path="/Display-Partner-Catalog-Detail-formation/:classId" exact component={Display_Partner_Catalog_DetailClass_new_v2} />
              <Route path="/Display-Partner-Catalog-Detail-formation/:classId/:action" exact component={Display_Partner_Catalog_DetailClass_new_v2} />





              <Route path="/mysy-account-activated/" exact component={AccountUserActivated} />
              {/* <Route path="/Produits-Services/" exact component={ProduitsService} />*/}
              <Route path="/tarifs_produits_services/" exact component={ProduitsService} />
              <Route path="/Recherche_new/" exact component={Recherche_new} />
              <Route path="/GestionAdministrative/:internal_url" exact component={GestionAdministrative} />
              <Route path="/Recherche_new/:type/:categorie" exact component={Recherche_new} />
              <Route path="/Recherche_old/" exact component={Recherche_old} />
              <Route path="/Connexion-utilisateur-0/" exact component={UserSignFirst} />
              <Route path="/Emargement/" exact component={Emargement} />
              <Route path="/CartoucheComMySy/" exact component={Formation_Cartouche_Com} />
              <Route path="/Test_DragDrop/" exact component={Test_Drag_Drop} />
              <Route path="/Test_DragDrop2/" exact component={Test_Drag_Drop2} />
              <Route path="/Recherche_new_v2/" exact component={Recherche_new_v2} />
              <Route path="/Recherche_new_v2/:type/:categorie" exact component={Recherche_new_v2} />
              <Route path="/unsubscribe/" exact component={SeDesabonner} />
              <Route path="/OrderConfirmation_3DS/:orderid/:packs" exact component={OrderConfirmation_3DS} />
              <Route path="/page-inconnue/" exact component={NotFound} />
              <Route path="/formation-inconnue/" exact component={Training_Inactive_Or_Not_Found} />

              <Route path="/qr_emargement/:session_id/:partner_owner_recid/:my_safe_token" exact component={Emarge_QR_Code} />

              <Route path="/E_Signature/:document_id" exact component={ESign} />
              <Route path="/E_Document/:document_id/:partner_owner_recid/:secret_key_signature" exact component={ESignDiplayDignedDocument} />

              <Route path="/Survey/:survey_id/" exact component={SurveyDocument} />
              <Route path="/UpadateAttendeeList/:client_id/:session_id/:partner_owner_recid/" exact component={UpdateAttendeeList} />

              <Route path="/automatic-quotation/:partner_owner_recid/:objid/" exact component={AutomaticQuotation} />

              <Route path="/intelligence-artificielle-mysy-training/" exact component={MySyIA} />

              {/**** New design 2025 */}
              <Route path="/signin/" exact component={New_Sign_In_2025} />
              <Route path="/signup/" exact component={New_Sign_Up_2025} />
              <Route path="/tarif/" exact component={New_Tarif_2025} />
              <Route path="/contact/" exact component={New_Contact_2025} />

              {/*  
            
            09/03/25 : un redirection a été faite dans cloudflaire pour les lignes ci-dessous
            
              <Route path="/ContactezNous" exact component={New_Contact_2025} />

              */}



              <Route path="/display-detail-article/:articleId" exact component={New_Article_Detail_2025} />
              <Route path="/Display-Detail-Article/:articleId" exact component={New_Article_Detail_2025} />

              <Route path="/detaile-formation/:classId" exact component={New_Formation_Detail_2025} />
              {/* ex :  http://localhost:3009/detaile-formation/habilitation-electrique-882*/}

              <Route path="/marketplace/" exact component={New_Marktplace_2025} />
              <Route path="/fonctionnalites/" exact component={New_Fonctionnalite_2025} />

              <Route path="/apropos/" exact component={New_A_Propos_2025} />
              {/*  
            
            09/03/25 : un redirection a été faite dans cloudflaire pour les lignes ci-dessous
            <Route path="/QuiSommesNous" exact component={New_A_Propos_2025} />
              <Route path="/QuiSommesNous_v3" exact component={New_A_Propos_2025} />
              <Route path="/qui-sommes-nous" exact component={New_A_Propos_2025} />

              */}

              <Route path="/" exact component={New_Home_Page_2025} />



              {/* Debut Migration */}
              <Route path="/Partner/:action/:orderid/:packs" exact component={Partner} />
              <Route path="/Partner/:action/:orderid" exact component={Partner} />
              <Route path="/Partner/:action" exact component={Partner} />
              <Route path="/Partner" exact component={Partner} />
              <Route path="/recherche-formation" exact component={New_Marktplace_2025} />
              <Route path="/recherche-formation/ref/:NewSearchText" exact component={New_Marktplace_2025} />
              <Route path="/mysy-training-login/:obj/:objid" exact component={New_Sign_In_2025} />
              <Route path="/Connexion" exact component={New_Sign_In_2025} />
              <Route path="/Recherche-Article-formation" exact component={RechecheArticles} />

              <Route path="/Display-Detail-formation_v3/:classId" exact component={New_Formation_Detail_2025} />
              <Route path="/Display-Detail-formation/:classId" exact component={New_Formation_Detail_2025} />
              <Route path="/Display-Detail-formation/:classId/:action" exact component={New_Formation_Detail_2025} />
              <Route path="/Display-Detail-formation_old/:classId/:action" exact component={New_Formation_Detail_2025} />

              <Route path="/PartnerLogin" exact component={PartnerLogin} />
              <Route path="/PartnerLogin0" exact component={PartnerLogin0} />
              <Route path="/PartnerLogin1" exact component={PartnerLogin1} />

              <Route path="/mysy-user-account" exact component={Account} />
              <Route path="/Ajout-Article-formation" exact component={AddArticle} />
              <Route path="/ResetUserPwd/:token/:accounttype" exact component={ResetUserPwd} />


              <Route path="/DeleteUserAccount/:token" exact component={DeleteUserAccount} />



              {/* Fin Migration */}



              <Route path="/new_header_footer/" exact component={New_Test_Header_Footer_2025} />

              <Route component={NotFound} />
            </Switch>
          </BrowserRouter>
        </div>

      </div>


    </div>

  );
}


export default App;
