import {NgModule, isDevMode} from '@angular/core'
import {BrowserModule} from '@angular/platform-browser'
import {RouteReuseStrategy} from '@angular/router'

import {IonicModule, IonicRouteStrategy} from '@ionic/angular'

import {AppComponent} from './app.component'
import {AppRoutingModule} from './app-routing.module'
import {getApp, initializeApp, provideFirebaseApp} from '@angular/fire/app'
import {environment} from '../environments/environment'
import {getAuth, provideAuth} from '@angular/fire/auth'
import {
    initializeFirestore,
    persistentLocalCache,
    persistentMultipleTabManager,
    provideFirestore,
} from '@angular/fire/firestore'
import {MenuChannelGroupComponent} from './menu-channel-group/menu-channel-group.component'
import {ServiceWorkerModule} from '@angular/service-worker'

@NgModule({
    declarations: [AppComponent, MenuChannelGroupComponent],
    imports: [BrowserModule, IonicModule.forRoot(), AppRoutingModule,
        // Firebase main import.
        provideFirebaseApp(() => initializeApp(environment.firebaseConfig)),
        // Firebase authentication import.
        provideAuth(() => getAuth()),
        // Firebase Firestore (database) import.
        provideFirestore(() => initializeFirestore(getApp(), {
            localCache: persistentLocalCache({tabManager: persistentMultipleTabManager()})
        })),
        ServiceWorkerModule.register('ngsw-worker.js', {
            enabled: !isDevMode(),
            // Register the ServiceWorker as soon as the application is stable
            // or after 30 seconds (whichever comes first).
            registrationStrategy: 'registerWhenStable:30000'
        }),
    ],
    providers: [{provide: RouteReuseStrategy, useClass: IonicRouteStrategy}],
    bootstrap: [AppComponent],
})
export class AppModule {
}
