/*
 * Copyright 2023-2025 VMware, Inc. All rights reserved. VMware Confidential
 */

import { Pipe, PipeTransform } from "@angular/core";
import { ExtensionComponentRegistration } from "../../common/extensibility/extension-component.registry";
import { PluginUtilService } from "../../common/extensibility/plugin-util.service";

@Pipe({
    name: "extensionRouterLink",
})
export class ExtensionRouterLinkPipe implements PipeTransform {
    constructor(private pluginUtil: PluginUtilService) {}

    transform(extension: ExtensionComponentRegistration): string {
        const linkFirstSegment = this.pluginUtil.buildStartResourceSegment(extension.manifest.type);
        if (extension.vcdRoute) {
            // No need escape vcdRoute, because it is a valid angular route, which could contain a '/'
            return `${linkFirstSegment}/${extension.hashedVendor}/${extension.vcdRoute}`;
        }

        return `${linkFirstSegment}/${extension.manifest.urn}`;
    }
}
