import {NgModule} from '@angular/core';
import {RouterModule, Routes} from '@angular/router';
import {OpenaireErrorPageComponent} from './error/errorPage.component';
import {PageURLResolverComponent} from "./openaireLibrary/utils/pageURLResolver.component";
import {IsCommunity} from "./openaireLibrary/connect/communityGuard/isCommunity.guard";

const routes: Routes = [
  // ORCID Pages
  {path: 'orcid', loadChildren: () => import('./orcid/orcid.module').then(m => m.LibOrcidModule)},
  {path: 'my-orcid-links', loadChildren: () => import('./orcid/my-orcid-links/myOrcidLinks.module').then(m => m.LibMyOrcidLinksModule)},

  /** Other Pages */
  {
    path: '',
    loadChildren: () => import('./communitywrapper/communityWrapper.module').then(m => m.CommunityWrapperModule)
  },
  {path: 'about', redirectTo: 'about/learn-how', pathMatch: 'full'},
  {path: 'about/learn-how', loadChildren: () => import('./learn-how/learn-how.module').then(m => m.LearnHowModule)},
  {path: 'about/faq', loadChildren: () => import('./learn-how/faqs/faqs.module').then(m => m.FaqsModule)},
  {path: 'get-started', loadChildren: () => import('./get-started/get-started.module').then(m => m.GetStartedModule)},
  {path: 'contact-us', loadChildren: () => import('./contact/contact.module').then(m => m.ContactModule)},
  {path: 'invite', loadChildren: () => import('./utils/subscribe/invite/invite.module').then(m => m.InviteModule)},
  {
    path: 'content',
    loadChildren: () => import('./content/contentPage.module').then(m => m.ContentPageModule),
    canActivate: [IsCommunity]
  },
  {path: 'sdgs', loadChildren: () => import('./sdg/sdg.module').then(m => m.LibSdgModule)},
  {
    path: 'fields-of-science',
    loadChildren: () => import('./fos/fos.module').then(m => m.LibFosModule),
    data: {extraOffset: 100}
  },
  {
    path: 'organizations',
    loadChildren: () => import('./htmlPages/organizations/organizationsPage.module').then(m => m.OrganizationsPageModule),
    canActivate: [IsCommunity]
  },
  {
    path: 'publications',
    loadChildren: () => import('./htmlPages/publications/publications-page.module').then(m => m.PublicationsPageModule),
    canActivate: [IsCommunity]
  },
  {
    path: 'projects',
    loadChildren: () => import('./htmlPages/projects/projectsPage.module').then(m => m.ProjectsPageModule),
    canActivate: [IsCommunity]
  },
  {
    path: 'national-bulletins',
    loadChildren: () => import('./htmlPages/nationalBulletins/nationalBulletinsPage.module').then(m => m.NaionalBulletinPageModule),
    canActivate: [IsCommunity]
  },
  // {
  //   path: 'featured',
  //   children: [
  //     {
  //       path: '',
  //       loadChildren: () => import('./htmlPages/featured/featuredPage.module').then(m => m.FeaturedPageModule),
  //       canActivateChild: [IsCommunity],
  //     },
  //     {
  //       path: '**',
  //       loadChildren: () => import('./htmlPages/featured/featuredPage.module').then(m => m.FeaturedPageModule),
  //       canActivateChild: [IsCommunity],
  //     },
  //   ]
  // },
  {
    path: 'curators',
    loadChildren: () => import('./curators/curators.module').then(m => m.CuratorsModule),
    canActivate: [IsCommunity]
  },
  {
    path: 'subjects',
    loadChildren: () => import('./subjects/subjects.module').then(m => m.SubjectsModule),
    canActivate: [IsCommunity]
  },
  {
    path: 'myCommunities',
    loadChildren: () => import('./my-communities/my-communities.module').then(m => m.MyCommunitiesModule)
  },
  {
    path: 'develop',
    loadChildren: () => import('./develop/develop.module').then(m => m.DevelopModule), canActivate: [IsCommunity]
  },
  /** Testing Page for help contents */
  {path: 'helper-test', loadChildren: () => import('./helper-test/helper-test.module').then(m => m.HelperTestModule)},
  /**  Landing Pages */
  {
    path: 'search/result',
    loadChildren: () => import('./landingPages/result/libResult.module').then(m => m.LibResultModule),
    canActivate: [IsCommunity]
  },
  {
    path: 'search/publication',
    loadChildren: () => import('./landingPages/publication/libPublication.module').then(m => m.LibPublicationModule),
    canActivate: [IsCommunity]
  },
  {
    path: 'search/dataset',
    loadChildren: () => import('./landingPages/dataset/libDataset.module').then(m => m.LibDatasetModule),
    canActivate: [IsCommunity]
  },
  {
    path: 'search/software',
    loadChildren: () => import('./landingPages/software/libSoftware.module').then(m => m.LibSoftwareModule),
    canActivate: [IsCommunity]
  },
  {path: 'search/other', loadChildren: () => import('./landingPages/orp/libOrp.module').then(m => m.LibOrpModule), canActivate: [IsCommunity]},
  {
    path: 'search/project',
    loadChildren: () => import('./landingPages/project/libProject.module').then(m => m.LibProjectModule),
    canActivate: [IsCommunity]
  },
  {
    path: 'search/dataprovider',
    loadChildren: () => import('././landingPages/dataProvider/libDataProvider.module').then(m => m.LibDataProviderModule),
    canActivate: [IsCommunity]
  },
  {
    path: 'search/organization',
    loadChildren: () => import('./landingPages/organization/libOrganization.module').then(m => m.LibOrganizationModule),
    canActivate: [IsCommunity]
  },
  {
    path: 'project-report',
    loadChildren: () => import('./landingPages/htmlProjectReport/libHtmlProjectReport.module').then(m => m.LibHtmlProjectReportModule)
  },
  /**  Search Pages */
  {path: 'search/find', redirectTo: 'search/find/research-outcomes', pathMatch: 'full'},
  
  {
    path: 'search/find/communities',
    loadChildren: () => import('./searchPages/communities/searchCommunities.module').then(m => m.SearchCommunitiesModule)
  },
  {
    path: 'search/find/research-outcomes',
    loadChildren: () => import('./searchPages/simple/searchResearchResults.module').then(m => m.OpenaireSearchResearchResultsModule),
    canActivate: [IsCommunity]
  },
  {path: 'search/find/publications', component: PageURLResolverComponent, canActivate: [IsCommunity]},
  {path: 'search/find/datasets', component: PageURLResolverComponent, canActivate: [IsCommunity]},
  {path: 'search/find/software', component: PageURLResolverComponent, canActivate: [IsCommunity]},
  {path: 'search/find/other', component: PageURLResolverComponent, canActivate: [IsCommunity]},
  {
    path: 'search/find/projects',
    loadChildren: () => import('./searchPages/simple/searchProjects.module').then(m => m.LibSearchProjectsModule),
    canActivate: [IsCommunity]
  },
  {
    path: 'search/find/dataproviders',
    loadChildren: () => import('./searchPages/simple/searchDataProviders.module').then(m => m.LibSearchDataProvidersModule),
    canActivate: [IsCommunity]
  },
  /**  Advanced Search Pages */
  {
    path: 'search/advanced/research-outcomes',
    loadChildren: () => import('./searchPages/advanced/searchResearchResults.module').then(m => m.OpenaireAdvancedSearchResearchResultsModule),
    canActivate: [IsCommunity]
  },
  {path: 'search/advanced/publications', component: PageURLResolverComponent, canActivate: [IsCommunity]},
  {path: 'search/advanced/datasets', component: PageURLResolverComponent, canActivate: [IsCommunity]},
  {path: 'search/advanced/software', component: PageURLResolverComponent, canActivate: [IsCommunity]},
  {path: 'search/advanced/other', component: PageURLResolverComponent, canActivate: [IsCommunity]},
  {
    path: 'search/advanced/organizations',
    loadChildren: () => import('./searchPages/advanced/advancedSearchOrganizations.module').then(m => m.LibAdvancedSearchOrganizationsModule),
    canActivate: [IsCommunity]
  },
  {
    path: 'search/advanced/dataproviders',
    loadChildren: () => import('./searchPages/advanced/advancedSearchDataProviders.module').then(m => m.LibAdvancedSearchDataProvidersModule),
    canActivate: [IsCommunity]
  },
  {
    path: 'search/advanced/projects',
    loadChildren: () => import('./searchPages/advanced/advancedSearchProjects.module').then(m => m.LibAdvancedSearchProjectsModule),
    canActivate: [IsCommunity]
  },
  /** Deposit Pages */
  { path: 'participate/deposit-datasets',
    redirectTo: 'participate/deposit/learn-how',
    pathMatch: 'full' },
  { path: 'participate/deposit-datasets-result',
    redirectTo: 'participate/deposit/learn-how',
    pathMatch: 'full' },
  { path: 'participate/deposit-subject-result',
    redirectTo: 'participate/deposit/learn-how',
    pathMatch: 'full' },
  { path: 'participate/deposit-publications',
    redirectTo: 'participate/deposit/learn-how',
    pathMatch: 'full' },
  { path: 'participate/deposit-publications-result',
    redirectTo: 'participate/deposit/learn-how',
    pathMatch: 'full' },
  { path: 'participate/share-zenodo',
    redirectTo: '/participate/deposit/zenodo',
    pathMatch: 'full' },
  {
    path: 'participate/deposit/learn-how',
    loadChildren: () => import('./deposit/deposit.module').then(m => m.LibDepositModule),
    canActivate: [IsCommunity]
  },
  {
    path: 'participate/deposit/search',
    loadChildren: () => import('./deposit/searchDataprovidersToDeposit.module').then(m => m.LibSearchDataprovidersToDepositModule),
    canActivate: [IsCommunity]
  },
  {
    path: 'participate/deposit/zenodo',
    loadChildren: () => import('./deposit/zenodo/shareInZenodo.module').then(m => m.ShareInZenodoModule),
    canActivate: [IsCommunity]
  },
  /**  Linking Pages */
  {path: 'myclaims', loadChildren: () => import('./claims/myClaims/myClaims.module').then(m => m.LibMyClaimsModule), canActivate: [IsCommunity]},
  {
    path: 'participate/claim',
    loadChildren: () => import('./claims/linking/linkingGeneric.module').then(m => m.LibLinkingGenericModule),
    canActivate: [IsCommunity]
  },
  {
    path: 'participate/direct-claim',
    loadChildren: () => import('./claims/directLinking/directLinking.module').then(m => m.LibDirectLinkingModule),
    canActivate: [IsCommunity]
  },
  {
    path: 'preview',
    loadChildren: () => import('./demo/demo.module').then(m => m.DemoModule),
    canActivate: [IsCommunity]
  },
  /**  help pages - do not exist in Admin portal/api/db */
  {path: 'reload', loadChildren: () => import('./reload/libReload.module').then(m => m.LibReloadModule)},
  {path: 'user-info', loadChildren: () => import('./login/libUser.module').then(m => m.LibUserModule)},
  {path: 'error', component: OpenaireErrorPageComponent},
  {path: 'theme', loadChildren: () => import('./openaireLibrary/utils/theme/theme.module').then(m => m.ThemeModule)},
  {path: '**', pathMatch: 'full', component: OpenaireErrorPageComponent}
];

@NgModule({
  imports: [RouterModule.forRoot(routes, {
    onSameUrlNavigation: "reload"
  })],
  exports: [RouterModule]
})
export class AppRoutingModule {
}
