/*
 * ******************************************************************
 * Copyright (c) 2025 Broadcom. All Rights Reserved.
 * Broadcom Confidential. The term "Broadcom" refers to Broadcom Inc.
 * and/or its subsidiaries.
 * ******************************************************************
 */

import { Component } from '@angular/core';
import { ExtensionPointService, GeneralExtensibilityService, TextBasedExtensionNavRegistration } from '@vcf/ng-hyper-plugin-framework';
import { filter, switchMap } from "rxjs";

@Component({
  selector: 'app-all-in-one',
  templateUrl: './all-in-one.component.html',
  styleUrl: './all-in-one.component.scss',
  host: {
    "[class.extension-host]": "true",
  },
})
export class AllInOneComponent {
  verticalNavCollapsed: boolean = false;
  navItems: any[] = [
    {
      title: "navigation:primary",
      iconShape: "applications",
      children: [],
    },
    {
      title: "navigation:services:overview",
      iconShape: "applications",
      children: [],
    },
    {
      title: "navigation:services:vcf",
      iconShape: "applications",
      children: [],
    },
    {
      title: "vm-action",
      iconShape: "applications",
      children: [
        {
          nameKey: "VM Actions",
          routerLink: "vm-actions",
        }
      ],
    },
  ];

  constructor(
    private extensionPointService: ExtensionPointService,
    private generalExtensibilityService: GeneralExtensibilityService,
  ) {
    this.extensionPointService.getPrimaryNavigationMenuItems().subscribe((menuItems: TextBasedExtensionNavRegistration[]) => {
      this.navItems[0].children = menuItems.map((menu) => {
        return {
          nameKey: menu.nameText,
          routerLink: `plugins/${menu.path}`,
        };
      });
    });


    this.generalExtensibilityService.allExtensionsLoaded
      .pipe(
        filter(Boolean),
        switchMap(() => {
          return this.extensionPointService.getServicesOverviewMenuItems();
        }),
      ).subscribe((menuItems: TextBasedExtensionNavRegistration[]) => {

        this.navItems[1].children = menuItems.map((menu) => {
          return {
            nameKey: menu.nameText,
            routerLink: `plugins/${menu.path}`,
          };
        });
      });

    this.generalExtensibilityService.allExtensionsLoaded
      .pipe(
        filter(Boolean),
        switchMap(() => {
          return this.extensionPointService.getVCFServicesMenuItems();
        }),
      ).subscribe((menuItems: TextBasedExtensionNavRegistration[]) => {
        this.navItems[2].children = menuItems.map((menu) => {
          return {
            nameKey: menu.nameText,
            routerLink: `vcf-services/${menu.path}`,
          };
        });
      });
  }
}
