import { Component } from "@angular/core";
import { Router } from '@angular/router';
import { IconNamesEnum } from "ngx-bootstrap-icons";
import { AuthService } from "../auth/auth.service";


interface MenuItem {
    title: string,
    link: string,
    icon: IconNamesEnum
}


@Component({
    selector: "sidenav",
    templateUrl: "./sidenav.component.html",
    styleUrls: ["./sidenav.component.css"]
})
export class SidenavComponent {
    Menu: MenuItem[] = [
        {
            title: $localize`Dashboard`,
            link: "/dashboard",
            icon: IconNamesEnum.HouseFill
        },
        {
            title: $localize`Entities`,
            link: "/entities",
            icon: IconNamesEnum.PeopleFill
        },
        {
            title: $localize`Provision&nbsp;Templates`,
            link: "/templates/provisions",
            icon: IconNamesEnum.BlockquoteLeft
        },
        {
            title: $localize`Contracts&nbsp;Templates`,
            link: "/templates/contracts",
            icon: IconNamesEnum.FileCodeFill
        },
        {
            title: $localize`Contracts&nbsp;Drafts`,
            link: "/contract-drafts",
            icon: IconNamesEnum.PencilSquare
        },
        {
            title: $localize`Contracts`,
            link: "/contracts",
            icon: IconNamesEnum.FileEarmarkTextFill
        },
    ]

    isAuthenticated: boolean = false

    constructor(
        private router: Router,
        private authService: AuthService,) {

        this.isAuthenticated = this.authService.is_authenticated;
        this.authService.onIsAuthenticated$.subscribe((isAuthenticated: boolean) => {
            this.isAuthenticated = isAuthenticated;
        })
    }

    is_current_page(menu_item: MenuItem) {
        return this.router.url.startsWith(menu_item.link);
    }
}
