import * as i0 from '@angular/core';
import { EventEmitter, booleanAttribute, forwardRef, ContentChildren, Output, Input, HostBinding, ChangeDetectionStrategy, Component, NgModule } from '@angular/core';
import { EuiButtonComponent } from '@eui/components/eui-button';

/**
 * @description
 * Component for grouping multiple buttons together with optional checkbox or radio button behavior.
 */
class EuiButtonGroupComponent {
    constructor() {
        /**
         * Whether the buttons should behave like checkboxes (multiple selection)
         * @default false
         */
        this.isCheckboxButtons = false;
        /**
         * Whether the buttons should behave like radio buttons (single selection)
         * @default false
         */
        this.isRadioButtons = false;
        /**
         * Event emitted when any button in the group is clicked
         * Emits the clicked EuiButtonComponent instance
         */
        this.buttonClick = new EventEmitter();
    }
    /** CSS classes applied to the host element */
    get cssClasses() {
        return 'eui-button-group';
    }
    /**
     * Initializes button click subscriptions after content is initialized
     */
    ngAfterContentInit() {
        this.buttons.map((b) => {
            b.buttonClick.subscribe(() => {
                this.handleInnerButtonClick(b);
            });
        });
    }
    /**
     * Handles button click events based on group configuration
     * - For checkbox buttons: Toggles the clicked button's checked state
     * - For radio buttons: Sets the clicked button as checked and unchecks others
     * - Emits the buttonClick event with the clicked button instance
     *
     * @param button - The EuiButtonComponent that was clicked
     * @internal
     */
    handleInnerButtonClick(button) {
        try {
            if (button.isChecked && this.isCheckboxButtons) {
                button.isChecked = false;
            }
            else {
                if (this.isRadioButtons) {
                    this.buttons.find((b) => b.id === button.id).isChecked = true;
                    this.buttons.forEach((b) => {
                        if (b.id !== button.id) {
                            b.isChecked = false;
                        }
                    });
                }
                else if (this.isCheckboxButtons) {
                    this.buttons.find((b) => b.id === button.id).isChecked = true;
                }
            }
            this.buttonClick.emit(button);
        }
        catch (e) {
            console.log(e);
        }
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.17", ngImport: i0, type: EuiButtonGroupComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
    static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "16.1.0", version: "19.2.17", type: EuiButtonGroupComponent, isStandalone: true, selector: "eui-button-group", inputs: { isCheckboxButtons: ["isCheckboxButtons", "isCheckboxButtons", booleanAttribute], isRadioButtons: ["isRadioButtons", "isRadioButtons", booleanAttribute] }, outputs: { buttonClick: "buttonClick" }, host: { properties: { "class": "this.cssClasses" } }, queries: [{ propertyName: "buttons", predicate: i0.forwardRef(() => EuiButtonComponent) }], ngImport: i0, template: '<ng-content/>', isInline: true, styles: [".eui-19 :host.eui-button-group{position:relative;display:inline-flex;flex-wrap:wrap;vertical-align:middle;width:100%}.eui-19 :host.eui-button-group ::ng-deep .eui-button:focus-visible:not([readonly]){outline:2px solid var(--eui-c-focus-visible)!important;outline-offset:-2px!important;transition:none}.eui-19 :host.eui-button-group ::ng-deep>.eui-button:not(:first-child),.eui-19 :host.eui-button-group ::ng-deep>.eui-button-group:not(:first-child){margin-left:-1px}.eui-19 :host.eui-button-group ::ng-deep>.eui-button:not(:last-child),.eui-19 :host.eui-button-group ::ng-deep>.eui-button-group:not(:last-child)>.eui-button{border-bottom-right-radius:0;border-top-right-radius:0}.eui-19 :host.eui-button-group ::ng-deep>.eui-button:not(:first-child),.eui-19 :host.eui-button-group ::ng-deep>.eui-button-group:not(:first-child)>.eui-button{border-bottom-left-radius:0;border-top-left-radius:0}\n"], changeDetection: i0.ChangeDetectionStrategy.OnPush }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.17", ngImport: i0, type: EuiButtonGroupComponent, decorators: [{
            type: Component,
            args: [{ selector: 'eui-button-group', template: '<ng-content/>', changeDetection: ChangeDetectionStrategy.OnPush, styles: [".eui-19 :host.eui-button-group{position:relative;display:inline-flex;flex-wrap:wrap;vertical-align:middle;width:100%}.eui-19 :host.eui-button-group ::ng-deep .eui-button:focus-visible:not([readonly]){outline:2px solid var(--eui-c-focus-visible)!important;outline-offset:-2px!important;transition:none}.eui-19 :host.eui-button-group ::ng-deep>.eui-button:not(:first-child),.eui-19 :host.eui-button-group ::ng-deep>.eui-button-group:not(:first-child){margin-left:-1px}.eui-19 :host.eui-button-group ::ng-deep>.eui-button:not(:last-child),.eui-19 :host.eui-button-group ::ng-deep>.eui-button-group:not(:last-child)>.eui-button{border-bottom-right-radius:0;border-top-right-radius:0}.eui-19 :host.eui-button-group ::ng-deep>.eui-button:not(:first-child),.eui-19 :host.eui-button-group ::ng-deep>.eui-button-group:not(:first-child)>.eui-button{border-bottom-left-radius:0;border-top-left-radius:0}\n"] }]
        }], propDecorators: { cssClasses: [{
                type: HostBinding,
                args: ['class']
            }], isCheckboxButtons: [{
                type: Input,
                args: [{ transform: booleanAttribute }]
            }], isRadioButtons: [{
                type: Input,
                args: [{ transform: booleanAttribute }]
            }], buttonClick: [{
                type: Output
            }], buttons: [{
                type: ContentChildren,
                args: [forwardRef(() => EuiButtonComponent)]
            }] } });
/**
 * @deprecated Import the standalone {@link EUI_BUTTON_GROUP} instead.
 * This module is maintained for backward compatibility.
 *
 */
class EuiButtonGroupModule {
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.17", ngImport: i0, type: EuiButtonGroupModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
    static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "19.2.17", ngImport: i0, type: EuiButtonGroupModule, imports: [EuiButtonGroupComponent], exports: [EuiButtonGroupComponent] }); }
    static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "19.2.17", ngImport: i0, type: EuiButtonGroupModule }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.17", ngImport: i0, type: EuiButtonGroupModule, decorators: [{
            type: NgModule,
            args: [{
                    imports: [EuiButtonGroupComponent],
                    exports: [EuiButtonGroupComponent],
                }]
        }] });

const EUI_BUTTON_GROUP = [
    EuiButtonGroupComponent,
];
// export { EuiButtonGroupComponent as EuiButtonGroup } from './eui-button-group.component';

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

export { EUI_BUTTON_GROUP, EuiButtonGroupComponent, EuiButtonGroupModule };
//# sourceMappingURL=eui-components-eui-button-group.mjs.map
