import { Component, inject, OnInit } from '@angular/core';
import { DashboardStatsService } from '@services/dossier-templates/dashboard-stats.service';
import { UserPreferenceService } from '@users/user-preference.service';
import { trackByFactory } from '@iqser/common-ui/lib/utils';
import { User } from '@red/domain';
import { getCurrentUser } from '@iqser/common-ui/lib/users';
import { TranslateModule } from '@ngx-translate/core';
import { TemplateStatsComponent } from '../components/template-stats/template-stats.component';
import { AsyncPipe, NgForOf } from '@angular/common';
import { SnakeCasePipe } from '@common-ui/pipes/snake-case.pipe';

@Component({
    templateUrl: './dashboard-screen.component.html',
    styleUrls: ['./dashboard-screen.component.scss'],
    standalone: true,
    imports: [TranslateModule, TemplateStatsComponent, NgForOf, AsyncPipe, SnakeCasePipe],
})
export class DashboardScreenComponent implements OnInit {
    readonly currentUser = getCurrentUser<User>();
    readonly stats$ = inject(DashboardStatsService).all$;
    readonly trackBy = trackByFactory();

    constructor(private readonly _userPreferenceService: UserPreferenceService) {}

    async ngOnInit(): Promise<void> {
        await this._userPreferenceService.saveLastDossierTemplate(null);
    }
}
