import * as i0 from '@angular/core';
import { InjectionToken, input, booleanAttribute, inject, ElementRef, effect, ViewEncapsulation, ChangeDetectionStrategy, Component, NgModule } from '@angular/core';

/**
 * Injection token for providing a default header size to title components.
 *
 * **How it works:**
 * 1. A parent component (like dialog-header) provides this token with a value (e.g., 5)
 * 2. Child title components automatically receive that value through dependency injection
 * 3. The title uses this default only if no explicit `headerSize` input is provided
 *
 * **Example:**
 * ```typescript
 * // Parent provides the default
 * @Component({
 *   providers: [{ provide: DEFAULT_TITLE_SIZE, useValue: 5 }]
 * })
 * export class DialogHeaderComponent { }
 *
 * // Child receives the default automatically
 * <fd-dialog-header>
 *   <h1 fd-title>Title</h1>  <!-- Will be size 5 -->
 * </fd-dialog-header>
 * ```
 */
const DEFAULT_TITLE_SIZE = new InjectionToken('DEFAULT_TITLE_SIZE');
/**
 * Abstract token for providing access to the title component's element reference.
 * Used for dependency injection when components need to access the title element.
 */
class TitleToken {
}
/**
 * Title component for rendering semantic headings with Fundamental styles.
 *
 * Applied as an attribute directive to heading elements (h1-h6).
 * Automatically detects heading level from the tag name or can be explicitly set via `headerSize`.
 */
class TitleComponent extends TitleToken {
    /**
     * Returns the element reference for external access via TitleToken.
     */
    get elementRef() {
        return this._elementRef;
    }
    /**
     * @hidden
     * Effect that reactively updates the header size class when headerSize input changes.
     * Runs on initialization and whenever the headerSize signal updates.
     */
    constructor() {
        super();
        /** Whether this title should clamp at two lines of text. */
        this.twoLineClamp = input(false, { ...(ngDevMode ? { debugName: "twoLineClamp" } : {}), transform: booleanAttribute });
        /**
         * Explicit header size (1-6) for the title styling.
         * If not provided, uses the injected DEFAULT_TITLE_SIZE or automatically detected from the host element's tag name.
         * @default null
         */
        this.headerSize = input(null, ...(ngDevMode ? [{ debugName: "headerSize" }] : []));
        /**
         * Enables text wrapping. When `false`, text truncates with ellipsis.
         * @default false
         */
        this.wrap = input(false, ...(ngDevMode ? [{ debugName: "wrap" }] : []));
        /**
         * Default header size provided by parent component via DI.
         * Will be `null` if no parent provides DEFAULT_TITLE_SIZE.
         * @hidden
         */
        this._defaultHeaderSize = inject(DEFAULT_TITLE_SIZE, { optional: true });
        /**
         * Element reference to the host element.
         * @hidden
         */
        this._elementRef = inject((ElementRef));
        effect(() => {
            this._setHeaderSize();
        });
    }
    /**
     * Applies the appropriate header size class to the host element.
     * Priority: explicit headerSize > injected default > element tag name.
     * @hidden
     */
    _setHeaderSize() {
        let headerSize = this.headerSize() ?? this._defaultHeaderSize ?? null;
        // If no explicit size provided, try to extract from element tag name
        if (headerSize === null) {
            const tagName = this._elementRef.nativeElement.tagName;
            // Only extract from valid heading tags (H1-H6)
            if (/^H[1-6]$/i.test(tagName)) {
                headerSize = tagName.charAt(1);
            }
            else {
                // Default to h5 for non-heading elements (like div with role="heading")
                headerSize = 5;
            }
        }
        if (this._appliedHeaderSize !== undefined) {
            this._elementRef.nativeElement.classList.remove(`fd-title--h${this._appliedHeaderSize}`);
        }
        this._elementRef.nativeElement.classList.add(`fd-title--h${headerSize}`);
        this._appliedHeaderSize = Number(headerSize);
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.0", ngImport: i0, type: TitleComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
    static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.1.0", version: "21.1.0", type: TitleComponent, isStandalone: true, selector: "[fd-title], [fdTitle]", inputs: { twoLineClamp: { classPropertyName: "twoLineClamp", publicName: "twoLineClamp", isSignal: true, isRequired: false, transformFunction: null }, headerSize: { classPropertyName: "headerSize", publicName: "headerSize", isSignal: true, isRequired: false, transformFunction: null }, wrap: { classPropertyName: "wrap", publicName: "wrap", isSignal: true, isRequired: false, transformFunction: null } }, host: { properties: { "class.fd-title--wrap": "wrap()", "class.fd-title--two-line-clamp": "twoLineClamp()" }, classAttribute: "fd-title" }, providers: [{ provide: TitleToken, useExisting: TitleComponent }], exportAs: ["fd-title"], usesInheritance: true, ngImport: i0, template: '<ng-content></ng-content>', isInline: true, styles: [".fd-title{font-size:1rem;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;--fdTitle_Font_Size:1rem;--fdTitle_Color:var(--sapTextColor);--fdTitle_Font_Family:var(--sapFontHeaderFamily);border:0;-webkit-box-sizing:border-box;box-sizing:border-box;color:var(--sapTextColor);color:var(--fdTitle_Color);font-family:var(--sapFontFamily);font-family:var(--fdTitle_Font_Family);font-size:var(--sapFontSize);font-size:var(--fdTitle_Font_Size);font-weight:400;forced-color-adjust:none;line-height:normal;margin-block:0;margin-inline:0;padding-block:0;padding-inline:0}.fd-title:after,.fd-title:before{-webkit-box-sizing:inherit;box-sizing:inherit;font-size:inherit}.fd-title--h1{--fdTitle_Font_Size:var(--sapFontHeader1Size)}.fd-title--h2{--fdTitle_Font_Size:var(--sapFontHeader2Size)}.fd-title--h3{--fdTitle_Font_Size:var(--sapFontHeader3Size)}.fd-title--h4{--fdTitle_Font_Size:var(--sapFontHeader4Size)}.fd-title--h5{--fdTitle_Font_Size:var(--sapFontHeader5Size)}.fd-title--h6{--fdTitle_Font_Size:var(--sapFontHeader6Size)}.fd-title--wrap{overflow:auto;text-overflow:clip;white-space:normal}.fd-title--two-line-clamp{display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden;text-overflow:ellipsis;white-space:normal}\n/*! Bundled license information:\n\nfundamental-styles/dist/title.css:\n  (*!\n   * Fundamental Library Styles v0.41.7\n   * Copyright (c) 2026 SAP SE or an SAP affiliate company.\n   * Licensed under Apache License 2.0 (https://github.com/SAP/fundamental-styles/blob/main/LICENSE)\n   *)\n*/\n"], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.0", ngImport: i0, type: TitleComponent, decorators: [{
            type: Component,
            args: [{ selector: '[fd-title], [fdTitle]', exportAs: 'fd-title', template: '<ng-content></ng-content>', host: {
                        class: 'fd-title',
                        '[class.fd-title--wrap]': 'wrap()',
                        '[class.fd-title--two-line-clamp]': 'twoLineClamp()'
                    }, changeDetection: ChangeDetectionStrategy.OnPush, encapsulation: ViewEncapsulation.None, providers: [{ provide: TitleToken, useExisting: TitleComponent }], styles: [".fd-title{font-size:1rem;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;--fdTitle_Font_Size:1rem;--fdTitle_Color:var(--sapTextColor);--fdTitle_Font_Family:var(--sapFontHeaderFamily);border:0;-webkit-box-sizing:border-box;box-sizing:border-box;color:var(--sapTextColor);color:var(--fdTitle_Color);font-family:var(--sapFontFamily);font-family:var(--fdTitle_Font_Family);font-size:var(--sapFontSize);font-size:var(--fdTitle_Font_Size);font-weight:400;forced-color-adjust:none;line-height:normal;margin-block:0;margin-inline:0;padding-block:0;padding-inline:0}.fd-title:after,.fd-title:before{-webkit-box-sizing:inherit;box-sizing:inherit;font-size:inherit}.fd-title--h1{--fdTitle_Font_Size:var(--sapFontHeader1Size)}.fd-title--h2{--fdTitle_Font_Size:var(--sapFontHeader2Size)}.fd-title--h3{--fdTitle_Font_Size:var(--sapFontHeader3Size)}.fd-title--h4{--fdTitle_Font_Size:var(--sapFontHeader4Size)}.fd-title--h5{--fdTitle_Font_Size:var(--sapFontHeader5Size)}.fd-title--h6{--fdTitle_Font_Size:var(--sapFontHeader6Size)}.fd-title--wrap{overflow:auto;text-overflow:clip;white-space:normal}.fd-title--two-line-clamp{display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden;text-overflow:ellipsis;white-space:normal}\n/*! Bundled license information:\n\nfundamental-styles/dist/title.css:\n  (*!\n   * Fundamental Library Styles v0.41.7\n   * Copyright (c) 2026 SAP SE or an SAP affiliate company.\n   * Licensed under Apache License 2.0 (https://github.com/SAP/fundamental-styles/blob/main/LICENSE)\n   *)\n*/\n"] }]
        }], ctorParameters: () => [], propDecorators: { twoLineClamp: [{ type: i0.Input, args: [{ isSignal: true, alias: "twoLineClamp", required: false }] }], headerSize: [{ type: i0.Input, args: [{ isSignal: true, alias: "headerSize", required: false }] }], wrap: [{ type: i0.Input, args: [{ isSignal: true, alias: "wrap", required: false }] }] } });

/**
 * @deprecated Use the standalone `TitleComponent` directly instead. Import `TitleComponent` in your component's imports array.
 * This module will be removed in a future version.
 */
class TitleModule {
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.0", ngImport: i0, type: TitleModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
    static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "21.1.0", ngImport: i0, type: TitleModule, imports: [TitleComponent], exports: [TitleComponent] }); }
    static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "21.1.0", ngImport: i0, type: TitleModule }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.0", ngImport: i0, type: TitleModule, decorators: [{
            type: NgModule,
            args: [{
                    imports: [TitleComponent],
                    exports: [TitleComponent]
                }]
        }] });

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

export { DEFAULT_TITLE_SIZE, TitleComponent, TitleModule, TitleToken };
//# sourceMappingURL=fundamental-ngx-core-title.mjs.map
