import {Component, isDevMode} from '@angular/core';
import {select, Store} from "@ngrx/store";
import {fromApplication, fromAuthorize, selectIsLoggedIn} from "./shared/state/store";
import {environment} from "../environments/environment";
// @ts-ignore
import packageJson from '../../../../package.json';
import {tap} from "rxjs";

@Component({
    selector: 'app-root',
    templateUrl: './app.component.html',
    styleUrls: ['./app.component.scss']
})
export class AppComponent {
    appName = environment.appName;
    version = packageJson.version;

    navigationItems = [
        {title: 'Authorize', link: '/authorize'},
        {title: 'Stats', link: '/sync'},
        {title: 'Edit Lists', link: '/lists'},
        {title: 'List view', link: '/followings/list'},
        {title: 'Matrix View', link: '/followings/matrix'},
        {title: 'Table View', link: '/followings/table'},
    ];

    constructor(private store: Store) {
        this.store.dispatch(fromAuthorize.loadLocalStorage());
        this.store.pipe(
            select(selectIsLoggedIn),
        ).subscribe((loggedIn) => {
            if (loggedIn && !isDevMode()) {
                this.store.dispatch(fromApplication.loadLists());
                this.store.dispatch(fromApplication.loadFollowings());
            }
        });
    }
}
