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/Select.js';
import * as i1 from '@fundamental-ngx/ui5-webcomponents/utils';
import { GenericControlValueAccessor } from '@fundamental-ngx/ui5-webcomponents/utils';

class Select {
    constructor() {
        /**
         * Defines whether the component is in disabled state.
      
      **Note:** A disabled component is noninteractive.
         */
        this.disabled = input(false, ...(ngDevMode ? [{ debugName: "disabled", transform: booleanAttribute }] : [{ transform: booleanAttribute }]));
        /**
         * Determines the name by which the component will be identified upon submission in an HTML form.
      
      **Note:** This property is only applicable within the context of an HTML Form element.
         */
        this.name = input(...(ngDevMode ? [undefined, { debugName: "name" }] : []));
        /**
         * Defines the value state of the component.
         */
        this.valueState = input("None", ...(ngDevMode ? [{ debugName: "valueState" }] : []));
        /**
         * Defines whether the component is required.
         */
        this.required = input(false, ...(ngDevMode ? [{ debugName: "required", transform: booleanAttribute }] : [{ transform: booleanAttribute }]));
        /**
         * Defines whether the component is read-only.
      
      **Note:** A read-only component is not editable,
      but still provides visual feedback upon user interaction.
         */
        this.readonly = input(false, ...(ngDevMode ? [{ debugName: "readonly", transform: booleanAttribute }] : [{ transform: booleanAttribute }]));
        /**
         * Defines the accessible ARIA name of the component.
         */
        this.accessibleName = input(...(ngDevMode ? [undefined, { debugName: "accessibleName" }] : []));
        /**
         * Receives id(or many ids) of the elements that label the select.
         */
        this.accessibleNameRef = input(...(ngDevMode ? [undefined, { debugName: "accessibleNameRef" }] : []));
        /**
         * Defines the accessible description of the component.
         */
        this.accessibleDescription = input(...(ngDevMode ? [undefined, { debugName: "accessibleDescription" }] : []));
        /**
         * Receives id(or many ids) of the elements that describe the select.
         */
        this.accessibleDescriptionRef = input(...(ngDevMode ? [undefined, { debugName: "accessibleDescriptionRef" }] : []));
        /**
         * Defines the tooltip of the select.
         */
        this.tooltip = input(...(ngDevMode ? [undefined, { debugName: "tooltip" }] : []));
        /**
         * Defines the separator type for the two columns layout when Select is in read-only mode.
         */
        this.textSeparator = input("Dash", ...(ngDevMode ? [{ debugName: "textSeparator" }] : []));
        /**
         * Defines the value of the component:
      
      - when get - returns the value of the component or the value/text content of the selected option.
      - when set - selects the option with matching `value` property or text content.
      
      **Note:** Use either the Select's value or the Options' selected property.
      Mixed usage could result in unexpected behavior.
      
      **Note:** If the given value does not match any existing option,
      no option will be selected and the Select component will be displayed as empty.
         */
        this.value = input("", ...(ngDevMode ? [{ debugName: "value" }] : [])); // className is now passed
        /**
         * Currently selected `ui5-option` element.
         * @readonly This property is managed by the web component and updates reactively.
         * Based on schema: readonly field that updates via change event parameters.
         */
        this.selectedOption = computed(() => this._selectedOptionSignal(), ...(ngDevMode ? [{ debugName: "selectedOption" }] : []));
        /**
         * Fired when the selected option changes.
         */
        this.ui5Change = output();
        /**
         * Fired when the user navigates through the options, but the selection is not finalized,
      or when pressing the ESC key to revert the current selection.
         */
        this.ui5LiveChange = output();
        /**
         * Fired after the component's dropdown menu opens.
         */
        this.ui5Open = output();
        /**
         * Fired after the component's dropdown menu closes.
         */
        this.ui5Close = 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 component options.
      
      **Note:** Only one selected option is allowed.
      If more than one option is defined as selected, the last one would be considered as the selected one.
      
      **Note:** Use the `ui5-option` component to define the desired options.
         * - **valueStateMessage**: Defines the value state message that will be displayed as pop up under the component.
      
      **Note:** If not specified, a default text (in the respective language) will be displayed.
      
      **Note:** The `valueStateMessage` would be displayed,
      when the component is in `Information`, `Critical` or `Negative` value state.
      
      **Note:** If the component has `suggestionItems`,
      the `valueStateMessage` would be displayed as part of the same popover, if used on desktop, or dialog - on phone.
         * - **label**: Defines the HTML element that will be displayed in the component input part,
      representing the selected option.
      
      **Note:** If not specified and `ui5-option-custom` is used,
      either the option's `display-text` or its textContent will be displayed.
      
      **Note:** If not specified and `ui5-option` is used,
      the option's textContent will be displayed.
         *
         * @example
         * ```html
         * <ui5-select>
         *   <div slot="header">Custom header content</div>
         *   <p>Default slot content</p>
         * </ui5-select>
         * ```
         *
         * @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 component options.\n\n**Note:** Only one selected option is allowed.\nIf more than one option is defined as selected, the last one would be considered as the selected one.\n\n**Note:** Use the `ui5-option` component to define the desired options."
            },
            {
                "name": "valueStateMessage",
                "description": "Defines the value state message that will be displayed as pop up under the component.\n\n**Note:** If not specified, a default text (in the respective language) will be displayed.\n\n**Note:** The `valueStateMessage` would be displayed,\nwhen the component is in `Information`, `Critical` or `Negative` value state.\n\n**Note:** If the component has `suggestionItems`,\nthe `valueStateMessage` would be displayed as part of the same popover, if used on desktop, or dialog - on phone."
            },
            {
                "name": "label",
                "description": "Defines the HTML element that will be displayed in the component input part,\nrepresenting the selected option.\n\n**Note:** If not specified and `ui5-option-custom` is used,\neither the option's `display-text` or its textContent will be displayed.\n\n**Note:** If not specified and `ui5-option` is used,\nthe option's textContent will be displayed.",
                "since": "1.17.0"
            }
        ];
        this.elementRef = inject(ElementRef);
        this.injector = inject(Injector);
        // Internal signal to track selectedOption from change events
        this._selectedOptionSignal = signal(undefined, ...(ngDevMode ? [{ debugName: "_selectedOptionSignal" }] : []));
    }
    get element() {
        return this.elementRef.nativeElement;
    }
    ngAfterViewInit() {
        const wcElement = this.element;
        const inputsToSync = [
            'disabled',
            'name',
            'valueState',
            'required',
            'readonly',
            'accessibleName',
            'accessibleNameRef',
            'accessibleDescription',
            'accessibleDescriptionRef',
            'tooltip',
            'textSeparator',
            'value',
        ];
        // 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 = [
            'ui5Change',
            'ui5LiveChange',
            'ui5Open',
            'ui5Close',
        ];
        // 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 selectedOption signal when change event fires
                    if (eventName === 'change') {
                        const customEvent = e;
                        // Use selectedOption from event detail, fallback to web component property
                        const selectedOptionValue = customEvent.detail?.selectedOption || wcElement.selectedOption || undefined;
                        this._selectedOptionSignal.set(selectedOptionValue);
                    }
                    // Update selectedOption signal when live-change event fires
                    if (eventName === 'live-change') {
                        const customEvent = e;
                        // Use selectedOption from event detail, fallback to web component property
                        const selectedOptionValue = customEvent.detail?.selectedOption || wcElement.selectedOption || undefined;
                        this._selectedOptionSignal.set(selectedOptionValue);
                    }
                    this[outputName].emit(e);
                });
            }
        }
        // Initialize selectedOption signal with current state using delayed initialization
        // to handle web component timing properly
        const initializeSelectedOption = () => {
            const currentValue = wcElement.selectedOption || undefined;
            if (JSON.stringify(currentValue) !== JSON.stringify(this._selectedOptionSignal())) {
                this._selectedOptionSignal.set(currentValue);
            }
        };
        // Try immediate initialization
        initializeSelectedOption();
        // Fallback delayed initialization if web component needs more time
        // Use requestAnimationFrame for zoneless compatibility
        requestAnimationFrame(() => initializeSelectedOption());
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.1.4", ngImport: i0, type: Select, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
    static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.1.0", version: "20.1.4", type: Select, isStandalone: true, selector: "ui5-select, [ui5-select]", inputs: { disabled: { classPropertyName: "disabled", publicName: "disabled", isSignal: true, isRequired: false, transformFunction: null }, name: { classPropertyName: "name", publicName: "name", isSignal: true, isRequired: false, transformFunction: null }, valueState: { classPropertyName: "valueState", publicName: "valueState", isSignal: true, isRequired: false, transformFunction: null }, required: { classPropertyName: "required", publicName: "required", isSignal: true, isRequired: false, transformFunction: null }, readonly: { classPropertyName: "readonly", publicName: "readonly", isSignal: true, isRequired: false, transformFunction: null }, 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 }, tooltip: { classPropertyName: "tooltip", publicName: "tooltip", isSignal: true, isRequired: false, transformFunction: null }, textSeparator: { classPropertyName: "textSeparator", publicName: "textSeparator", isSignal: true, isRequired: false, transformFunction: null }, value: { classPropertyName: "value", publicName: "value", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { ui5Change: "ui5Change", ui5LiveChange: "ui5LiveChange", ui5Open: "ui5Open", ui5Close: "ui5Close" }, exportAs: ["ui5Select"], hostDirectives: [{ directive: i1.GenericControlValueAccessor }], 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: Select, decorators: [{
            type: Component,
            args: [{
                    standalone: true,
                    selector: 'ui5-select, [ui5-select]',
                    template: '<ng-content></ng-content>',
                    exportAs: 'ui5Select',
                    hostDirectives: [GenericControlValueAccessor],
                    changeDetection: ChangeDetectionStrategy.OnPush,
                }]
        }] });

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

export { Select };
//# sourceMappingURL=fundamental-ngx-ui5-webcomponents-select.mjs.map
