import * as i0 from '@angular/core';
import { input, ChangeDetectionStrategy, Component, inject, ApplicationRef, EnvironmentInjector, DOCUMENT, createComponent, Injectable, ElementRef, Directive } from '@angular/core';
import { t, SiTranslatePipe } from '@siemens/element-translate-ng/translate';

/**
 * Copyright (c) Siemens 2016 - 2026
 * SPDX-License-Identifier: MIT
 */
class SiSkipLinksComponent {
    /** @defaultValue [] */
    skipLinks = input([], ...(ngDevMode ? [{ debugName: "skipLinks" }] : []));
    jumpToLabel = t(() => $localize `:@@SI_SKIP_LINKS.JUMP_TO:Jump to {{link}}`);
    static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.0.8", ngImport: i0, type: SiSkipLinksComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
    static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.0.8", type: SiSkipLinksComponent, isStandalone: true, selector: "si-skip-links", inputs: { skipLinks: { classPropertyName: "skipLinks", publicName: "skipLinks", isSignal: true, isRequired: false, transformFunction: null } }, ngImport: i0, template: "@for (link of skipLinks(); track link) {\n  <div class=\"skip-link-wrapper\">\n    <button\n      type=\"button\"\n      role=\"link\"\n      class=\"skip-link btn btn-secondary\"\n      (click)=\"link.jumpToThisTarget()\"\n    >\n      <span class=\"text-nowrap\">\n        {{ jumpToLabel | translate: { link: link.name() | translate } }}\n      </span>\n    </button>\n  </div>\n}\n", styles: [".skip-link-wrapper:focus-within{position:absolute;z-index:1060;inset-block-start:8px;inset-inline-start:50%;transform:translate(-50%)}.skip-link-wrapper:not(:focus-within){inline-size:1px;block-size:1px;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap;border:0}.skip-link{background:var(--element-base-0);border-color:var(--element-base-1)}\n"], dependencies: [{ kind: "pipe", type: SiTranslatePipe, name: "translate" }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.8", ngImport: i0, type: SiSkipLinksComponent, decorators: [{
            type: Component,
            args: [{ selector: 'si-skip-links', imports: [SiTranslatePipe], changeDetection: ChangeDetectionStrategy.OnPush, template: "@for (link of skipLinks(); track link) {\n  <div class=\"skip-link-wrapper\">\n    <button\n      type=\"button\"\n      role=\"link\"\n      class=\"skip-link btn btn-secondary\"\n      (click)=\"link.jumpToThisTarget()\"\n    >\n      <span class=\"text-nowrap\">\n        {{ jumpToLabel | translate: { link: link.name() | translate } }}\n      </span>\n    </button>\n  </div>\n}\n", styles: [".skip-link-wrapper:focus-within{position:absolute;z-index:1060;inset-block-start:8px;inset-inline-start:50%;transform:translate(-50%)}.skip-link-wrapper:not(:focus-within){inline-size:1px;block-size:1px;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap;border:0}.skip-link{background:var(--element-base-0);border-color:var(--element-base-1)}\n"] }]
        }], propDecorators: { skipLinks: [{ type: i0.Input, args: [{ isSignal: true, alias: "skipLinks", required: false }] }] } });

/**
 * Copyright (c) Siemens 2016 - 2026
 * SPDX-License-Identifier: MIT
 */
class SkipLinkService {
    skipLinksComponentRef;
    appRef = inject(ApplicationRef);
    environmentInjector = inject(EnvironmentInjector);
    document = inject(DOCUMENT);
    registeredTargets = [];
    registerLink(skipLink) {
        if (!this.skipLinksComponentRef) {
            this.createSkipLinksComponent();
        }
        this.registeredTargets.push(skipLink);
        this.skipLinksComponentRef.setInput('skipLinks', this.registeredTargets);
        this.skipLinksComponentRef.changeDetectorRef.markForCheck();
    }
    unregisterLink(skipLink) {
        this.registeredTargets.splice(this.registeredTargets.indexOf(skipLink), 1);
        if (this.registeredTargets.length && this.skipLinksComponentRef) {
            this.skipLinksComponentRef.setInput('skipLinks', this.registeredTargets);
            this.skipLinksComponentRef.changeDetectorRef.markForCheck();
        }
        else {
            this.skipLinksComponentRef?.destroy();
            this.skipLinksComponentRef = undefined;
        }
    }
    createSkipLinksComponent() {
        this.skipLinksComponentRef = createComponent(SiSkipLinksComponent, {
            environmentInjector: this.environmentInjector
        });
        this.appRef.attachView(this.skipLinksComponentRef.hostView);
        this.document.body.insertBefore(this.skipLinksComponentRef.location.nativeElement, this.document.body.children.item(0));
    }
    static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.0.8", ngImport: i0, type: SkipLinkService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
    static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.0.8", ngImport: i0, type: SkipLinkService, providedIn: 'root' });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.8", ngImport: i0, type: SkipLinkService, decorators: [{
            type: Injectable,
            args: [{
                    providedIn: 'root'
                }]
        }] });

/**
 * Copyright (c) Siemens 2016 - 2026
 * SPDX-License-Identifier: MIT
 */
/**
 * Directive to mark an element as a target for a skip link.
 * If this directive is applied to a none interactive element, a tabindex of -1 must be added manually.
 */
class SiSkipLinkTargetDirective {
    /**
     * The name of the skip link target which will be shown in the skip link.
     */
    name = input.required({ ...(ngDevMode ? { debugName: "name" } : {}), alias: 'siSkipLinkTarget' });
    skipLinkService = inject(SkipLinkService);
    elementRef = inject(ElementRef);
    ngOnInit() {
        this.skipLinkService.registerLink(this);
    }
    ngOnDestroy() {
        this.skipLinkService.unregisterLink(this);
    }
    /**
     * Call this methode to "activate" a skip link target. It will focus this element and scroll it into the view.
     */
    jumpToThisTarget() {
        this.elementRef.nativeElement.scrollIntoView({ block: 'nearest', inline: 'nearest' });
        this.elementRef.nativeElement.focus();
    }
    static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.0.8", ngImport: i0, type: SiSkipLinkTargetDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive });
    static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.0.8", type: SiSkipLinkTargetDirective, isStandalone: true, selector: "[siSkipLinkTarget]", inputs: { name: { classPropertyName: "name", publicName: "siSkipLinkTarget", isSignal: true, isRequired: true, transformFunction: null } }, ngImport: i0 });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.8", ngImport: i0, type: SiSkipLinkTargetDirective, decorators: [{
            type: Directive,
            args: [{
                    selector: '[siSkipLinkTarget]'
                }]
        }], propDecorators: { name: [{ type: i0.Input, args: [{ isSignal: true, alias: "siSkipLinkTarget", required: true }] }] } });

/**
 * Copyright (c) Siemens 2016 - 2026
 * SPDX-License-Identifier: MIT
 */

/**
 * Generated bundle index. Do not edit.
 */

export { SiSkipLinkTargetDirective };
//# sourceMappingURL=siemens-element-ng-skip-links.mjs.map
