import * as i0 from '@angular/core';
import { input, booleanAttribute, computed, output, inject, ElementRef, Injector, signal, runInInjectionContext, effect, ChangeDetectionStrategy, Component } from '@angular/core';
import '@ui5/webcomponents/dist/SegmentedButton.js';

class SegmentedButton {
    constructor() {
        /**
         * Defines the accessible ARIA name of the component.
         */
        this.accessibleName = input(...(ngDevMode ? [undefined, { debugName: "accessibleName" }] : []));
        /**
         * Defines the IDs of the HTML Elements that label the component.
         */
        this.accessibleNameRef = input(...(ngDevMode ? [undefined, { debugName: "accessibleNameRef" }] : []));
        /**
         * Defines the accessible description of the component.
         */
        this.accessibleDescription = input(...(ngDevMode ? [undefined, { debugName: "accessibleDescription" }] : []));
        /**
         * Defines the IDs of the HTML Elements that describe the component.
         */
        this.accessibleDescriptionRef = input(...(ngDevMode ? [undefined, { debugName: "accessibleDescriptionRef" }] : []));
        /**
         * Defines the component selection mode.
         */
        this.selectionMode = input("Single", ...(ngDevMode ? [{ debugName: "selectionMode" }] : []));
        /**
         * Determines whether the segmented button items should be sized to fit their content.
      
      If set to `true`, each item will be sized to fit its content, with any extra space distributed after the last item.
      If set to `false` (the default), all items will be equally sized to fill the available space.
         */
        this.itemsFitContent = input(false, ...(ngDevMode ? [{ debugName: "itemsFitContent", transform: booleanAttribute }] : [{ transform: booleanAttribute }])); // className is now passed
        /**
         * Returns an array of the currently selected items.
         * @readonly This property is managed by the web component and updates reactively.
         * Based on schema: readonly field that updates via selection-change event parameters.
         */
        this.selectedItems = computed(() => this._selectedItemsSignal(), ...(ngDevMode ? [{ debugName: "selectedItems" }] : []));
        /**
         * Fired when the selected item changes.
         */
        this.ui5SelectionChange = output();
        /**
         * Available slots for content projection in this component.
         *
         * Slots allow you to insert custom content into predefined areas of the web component.
         * Use the `slot` attribute on child elements to target specific slots.
         *
         * - **(default)**: Defines the items of `ui5-segmented-button`.
      
      **Note:** Multiple items are allowed.
      
      **Note:** Use the `ui5-segmented-button-item` for the intended design.
         *
         * @example
         * ```html
         * <ui5-segmented-button>
         *   <div slot="header">Custom header content</div>
         *   <p>Default slot content</p>
         * </ui5-segmented-button>
         * ```
         *
         * @readonly
         * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Web_components/Using_templates_and_slots | MDN Web Components Slots}
         */
        this.slots = [
            {
                "name": "default",
                "description": "Defines the items of `ui5-segmented-button`.\n\n**Note:** Multiple items are allowed.\n\n**Note:** Use the `ui5-segmented-button-item` for the intended design."
            }
        ];
        this.elementRef = inject(ElementRef);
        this.injector = inject(Injector);
        // Internal signal to track selectedItems from selection-change events
        this._selectedItemsSignal = signal([], ...(ngDevMode ? [{ debugName: "_selectedItemsSignal" }] : []));
    }
    get element() {
        return this.elementRef.nativeElement;
    }
    ngAfterViewInit() {
        const wcElement = this.element;
        const inputsToSync = [
            'accessibleName',
            'accessibleNameRef',
            'accessibleDescription',
            'accessibleDescriptionRef',
            'selectionMode',
            'itemsFitContent',
        ];
        // Synchronize inputs (properties)
        for (const inputName of inputsToSync) {
            // Find the corresponding camelCase signal property on the Angular component
            const signalName = inputName.replace(/-./g, (x) => x[1].toUpperCase());
            // Use the Injector to run the effect in the correct context
            if (this[signalName] && typeof this[signalName] === 'function') {
                runInInjectionContext(this.injector, () => {
                    effect(() => {
                        // Read the signal value
                        const value = this[signalName]();
                        if (wcElement) {
                            // Write the value to the Web Component's property
                            wcElement[inputName] = value;
                        }
                    });
                });
            }
        }
        const outputsToSync = [
            'ui5SelectionChange',
        ];
        // Synchronize outputs (events)
        for (const outputName of outputsToSync) {
            // Map Angular output name to UI5 web component event name
            const eventName = outputName.replace('ui5', '').replace(/([A-Z])/g, '-$1').toLowerCase().substring(1);
            // Ensure the output property exists and has an emit function before adding listener
            if (this[outputName] && typeof this[outputName].emit === 'function' && wcElement.addEventListener) {
                // Cast the listener to the correct type to satisfy TypeScript
                wcElement.addEventListener(eventName, (e) => {
                    // Update selectedItems signal when selection-change event fires
                    if (eventName === 'selection-change') {
                        const customEvent = e;
                        // Use selectedItems from event detail, fallback to web component property
                        const selectedItemsValue = customEvent.detail?.selectedItems || wcElement.selectedItems || [];
                        this._selectedItemsSignal.set(selectedItemsValue);
                    }
                    this[outputName].emit(e);
                });
            }
        }
        // Initialize selectedItems signal with current state using delayed initialization
        // to handle web component timing properly
        const initializeSelectedItems = () => {
            const currentValue = wcElement.selectedItems || [];
            if (JSON.stringify(currentValue) !== JSON.stringify(this._selectedItemsSignal())) {
                this._selectedItemsSignal.set(currentValue);
            }
        };
        // Try immediate initialization
        initializeSelectedItems();
        // Fallback delayed initialization if web component needs more time
        // Use requestAnimationFrame for zoneless compatibility
        requestAnimationFrame(() => initializeSelectedItems());
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.1.4", ngImport: i0, type: SegmentedButton, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
    static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.1.0", version: "20.1.4", type: SegmentedButton, isStandalone: true, selector: "ui5-segmented-button, [ui5-segmented-button]", inputs: { accessibleName: { classPropertyName: "accessibleName", publicName: "accessibleName", isSignal: true, isRequired: false, transformFunction: null }, accessibleNameRef: { classPropertyName: "accessibleNameRef", publicName: "accessibleNameRef", isSignal: true, isRequired: false, transformFunction: null }, accessibleDescription: { classPropertyName: "accessibleDescription", publicName: "accessibleDescription", isSignal: true, isRequired: false, transformFunction: null }, accessibleDescriptionRef: { classPropertyName: "accessibleDescriptionRef", publicName: "accessibleDescriptionRef", isSignal: true, isRequired: false, transformFunction: null }, selectionMode: { classPropertyName: "selectionMode", publicName: "selectionMode", isSignal: true, isRequired: false, transformFunction: null }, itemsFitContent: { classPropertyName: "itemsFitContent", publicName: "itemsFitContent", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { ui5SelectionChange: "ui5SelectionChange" }, exportAs: ["ui5SegmentedButton"], ngImport: i0, template: '<ng-content></ng-content>', isInline: true, changeDetection: i0.ChangeDetectionStrategy.OnPush }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.1.4", ngImport: i0, type: SegmentedButton, decorators: [{
            type: Component,
            args: [{
                    standalone: true,
                    selector: 'ui5-segmented-button, [ui5-segmented-button]',
                    template: '<ng-content></ng-content>',
                    exportAs: 'ui5SegmentedButton',
                    changeDetection: ChangeDetectionStrategy.OnPush,
                }]
        }] });

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

export { SegmentedButton };
//# sourceMappingURL=fundamental-ngx-ui5-webcomponents-segmented-button.mjs.map
