import { ActionDropdownTriggerDirective } from '@agorapulse/ui-components';
import * as i1 from '@agorapulse/ui-components/directives';
import { BaseButtonDirective } from '@agorapulse/ui-components/directives';
import { UI_COMPONENTS_SYMBOLS } from '@agorapulse/ui-components/providers';
import { SymbolRegistry, SymbolComponent, apChevronDown } from '@agorapulse/ui-symbol';
import * as i0 from '@angular/core';
import { inject, input, booleanAttribute, output, viewChild, contentChild, effect, HostListener, ViewEncapsulation, ChangeDetectionStrategy, Component } from '@angular/core';
import * as i2 from '@angular/material/menu';
import { MatMenuModule } from '@angular/material/menu';

let id = 1;
class SplitButtonComponent {
    symbolRegistry = inject(SymbolRegistry);
    baseButtonDirective = inject(BaseButtonDirective, { self: true });
    disabled = input(false, { ...(ngDevMode ? { debugName: "disabled" } : /* istanbul ignore next */ {}), transform: booleanAttribute });
    config = input({ style: 'primary', color: 'orange' }, ...(ngDevMode ? [{ debugName: "config" }] : /* istanbul ignore next */ []));
    actionDropdownTrigger = input(...(ngDevMode ? [undefined, { debugName: "actionDropdownTrigger" }] : /* istanbul ignore next */ []));
    /** @deprecated use actionDropdownTrigger instead */
    menuTrigger = input(null, ...(ngDevMode ? [{ debugName: "menuTrigger" }] : /* istanbul ignore next */ []));
    splitDisabled = input(false, ...(ngDevMode ? [{ debugName: "splitDisabled" }] : /* istanbul ignore next */ []));
    symbolPosition = input('right', ...(ngDevMode ? [{ debugName: "symbolPosition" }] : /* istanbul ignore next */ []));
    splitButtonDataTest = input(undefined, ...(ngDevMode ? [{ debugName: "splitButtonDataTest" }] : /* istanbul ignore next */ []));
    symbolId = input(...(ngDevMode ? [undefined, { debugName: "symbolId" }] : /* istanbul ignore next */ []));
    name = input(...(ngDevMode ? [undefined, { debugName: "name" }] : /* istanbul ignore next */ []));
    menuOpened = output();
    menuClosed = output();
    mainButtonClick = output();
    // eslint-disable-next-line @angular-eslint/no-output-native
    focus = output();
    // eslint-disable-next-line @angular-eslint/no-output-native
    blur = output();
    buttonElement = viewChild.required('button');
    splitButtonElement = viewChild.required('splitButton');
    symbolComponent = contentChild(SymbolComponent, ...(ngDevMode ? [{ debugName: "symbolComponent" }] : /* istanbul ignore next */ []));
    id;
    menuOpen = false;
    constructor() {
        this.symbolRegistry.registerSymbols([apChevronDown]);
        this.symbolRegistry.withSymbols(...(inject(UI_COMPONENTS_SYMBOLS, { optional: true })?.flat() ?? []));
        effect(() => {
            const symbolComp = this.symbolComponent();
            if (symbolComp) {
                symbolComp.size.set('sm');
            }
        });
    }
    ngAfterViewInit() {
        this.id = this.baseButtonDirective.hostId ?? `ap-split-button-${id++}`;
    }
    onSplitButtonClickHandle($event) {
        $event.stopImmediatePropagation();
    }
    handleMenuOpened() {
        this.menuOpened.emit();
        this.menuOpen = true;
        this.buttonElement().nativeElement.blur();
        this.splitButtonElement().nativeElement.blur();
    }
    handleMenuClosed() {
        this.menuClosed.emit();
        this.menuOpen = false;
        this.buttonElement().nativeElement.blur();
        this.splitButtonElement().nativeElement.blur();
    }
    focused = false;
    onClickHandle($event) {
        if (this.disabled()) {
            return;
        }
        $event.stopImmediatePropagation();
        this.mainButtonClick.emit($event);
        this.buttonElement().nativeElement.blur();
        this.blur.emit($event);
    }
    onSpaceKeyUp(event) {
        if (this.focused) {
            event.preventDefault();
            this.buttonElement().nativeElement.click();
        }
    }
    static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.16", ngImport: i0, type: SplitButtonComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
    static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.2.16", type: SplitButtonComponent, isStandalone: true, selector: "ap-split-button", inputs: { disabled: { classPropertyName: "disabled", publicName: "disabled", isSignal: true, isRequired: false, transformFunction: null }, config: { classPropertyName: "config", publicName: "config", isSignal: true, isRequired: false, transformFunction: null }, actionDropdownTrigger: { classPropertyName: "actionDropdownTrigger", publicName: "actionDropdownTrigger", isSignal: true, isRequired: false, transformFunction: null }, menuTrigger: { classPropertyName: "menuTrigger", publicName: "menuTrigger", isSignal: true, isRequired: false, transformFunction: null }, splitDisabled: { classPropertyName: "splitDisabled", publicName: "splitDisabled", isSignal: true, isRequired: false, transformFunction: null }, symbolPosition: { classPropertyName: "symbolPosition", publicName: "symbolPosition", isSignal: true, isRequired: false, transformFunction: null }, splitButtonDataTest: { classPropertyName: "splitButtonDataTest", publicName: "splitButtonDataTest", isSignal: true, isRequired: false, transformFunction: null }, symbolId: { classPropertyName: "symbolId", publicName: "symbolId", isSignal: true, isRequired: false, transformFunction: null }, name: { classPropertyName: "name", publicName: "name", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { menuOpened: "menuOpened", menuClosed: "menuClosed", mainButtonClick: "mainButtonClick", focus: "focus", blur: "blur" }, host: { listeners: { "window:keyup.space": "onSpaceKeyUp($event)" }, properties: { "attr.disabled": "(disabled() && splitDisabled())  || null" } }, queries: [{ propertyName: "symbolComponent", first: true, predicate: SymbolComponent, descendants: true, isSignal: true }], viewQueries: [{ propertyName: "buttonElement", first: true, predicate: ["button"], descendants: true, isSignal: true }, { propertyName: "splitButtonElement", first: true, predicate: ["splitButton"], descendants: true, isSignal: true }], hostDirectives: [{ directive: i1.BaseButtonDirective }], ngImport: i0, template: "<button\n    #button\n    type=\"button\"\n    [class.primary]=\"config().style === 'primary'\"\n    [class.orange]=\"config().color === 'orange'\"\n    [class.blue]=\"config().color === 'blue'\"\n    [class.inverse]=\"symbolPosition() === 'left'\"\n    [disabled]=\"disabled()\"\n    [name]=\"name()\"\n    [id]=\"id\"\n    [attr.data-test]=\"baseButtonDirective.hostDataTest ?? name()\"\n    (click)=\"onClickHandle($event)\"\n    (focus)=\"focus.emit($event)\"\n    (blur)=\"blur.emit($event)\">\n    <ng-content select=\"span\" />\n    @if (symbolId()) {\n        <ap-symbol [symbolId]=\"symbolId()\" />\n    } @else {\n        <ng-content select=\"ap-symbol\" />\n    }\n</button>\n<button\n    #splitButton\n    type=\"button\"\n    [class.primary]=\"config().style === 'primary'\"\n    [class.orange]=\"config().color === 'orange'\"\n    [class.blue]=\"config().color === 'blue'\"\n    [disabled]=\"splitDisabled()\"\n    [id]=\"id + '-split'\"\n    [attr.aria-labelledby]=\"id + '-split ' + id\"\n    [attr.data-test]=\"splitButtonDataTest() ?? name() + '-split'\"\n    [apActionDropdownTrigger]=\"actionDropdownTrigger()\"\n    [matMenuTriggerFor]=\"menuTrigger()\"\n    (click)=\"onSplitButtonClickHandle($event)\"\n    (menuClosed)=\"handleMenuClosed()\"\n    (menuOpened)=\"handleMenuOpened()\">\n    <ap-symbol\n        symbolId=\"chevron-down\"\n        size=\"sm\"\n        [class.opened]=\"menuOpen\" />\n    <span class=\"visually-hidden\">Toggle</span>\n</button>\n", styles: ["ap-split-button{--loading-bar-width: 50px;display:inline-flex;gap:1px;position:relative}ap-split-button[disabled]{pointer-events:none}ap-split-button button{border:none;position:relative;padding:var(--comp-split-button-padding-horizontal) var(--comp-split-button-padding-vertical);max-height:var(--comp-button-height);min-height:var(--comp-button-height);overflow:hidden;display:flex;flex-direction:row;justify-content:center;align-items:center;gap:10px}ap-split-button button ap-symbol{width:16px;min-width:16px;max-width:16px;height:16px;min-height:16px;max-height:16px}ap-split-button button.inverse{flex-direction:row-reverse}ap-split-button button:hover:not(:disabled):not(.loading){cursor:pointer}ap-split-button button:disabled{pointer-events:none}@media(hover:hover){ap-split-button button:focus:not(:disabled):not(:active):not(.loading){outline:2px solid var(--ref-color-electric-blue-100);outline-offset:1px;z-index:10}}ap-split-button button span{font-size:var(--comp-split-button-text-size);font-family:var(--comp-split-button-text-font-family);line-height:var(--comp-split-button-text-line-height);font-weight:var(--comp-split-button-text-weight);white-space:nowrap;text-overflow:ellipsis;overflow:hidden}ap-split-button button.loading{pointer-events:none}ap-split-button button.primary span,ap-split-button button.primary ap-symbol{color:var(--ref-color-white)}ap-split-button button.primary.orange{background:var(--ref-color-orange-100)}ap-split-button button.primary.orange:hover{background-color:var(--ref-color-orange-80)}ap-split-button button.primary.orange:active:not(:disabled){background-color:var(--ref-color-orange-60)}ap-split-button button.primary.orange:disabled{background-color:var(--ref-color-orange-20)}ap-split-button button.primary.orange.loading{background-color:var(--ref-color-orange-60)}ap-split-button button.primary.orange .loading-bar{background-color:var(--ref-color-orange-100)}ap-split-button button.primary.blue{background:var(--ref-color-electric-blue-100)}ap-split-button button.primary.blue:hover{background-color:var(--ref-color-electric-blue-80)}ap-split-button button.primary.blue:active:not(:disabled){background-color:var(--ref-color-electric-blue-60)}ap-split-button button.primary.blue:disabled{background-color:var(--ref-color-electric-blue-20)}ap-split-button button.primary.blue.loading{background-color:var(--ref-color-electric-blue-60)}ap-split-button button.primary.blue .loading-bar{background-color:var(--ref-color-electric-blue-100)}ap-split-button button:first-child{border-top-left-radius:var(--comp-split-button-border-radius);border-bottom-left-radius:var(--comp-split-button-border-radius)}ap-split-button button:last-child{border-top-right-radius:var(--comp-split-button-border-radius);border-bottom-right-radius:var(--comp-split-button-border-radius);padding:var(--comp-split-button-padding-horizontal) 10px var(--comp-split-button-padding-horizontal) 10px}ap-split-button button ap-symbol{will-change:transform;transition:.2s ease-in-out}ap-split-button button ap-symbol.opened{transform:rotate(180deg)}.visually-hidden{width:1px!important;height:1px!important;overflow:hidden!important;clip:rect(0,0,0,0)!important;white-space:nowrap!important;position:absolute!important}\n"], dependencies: [{ kind: "component", type: SymbolComponent, selector: "ap-symbol", inputs: ["symbolId", "color", "size"], outputs: ["sizeChange"] }, { kind: "ngmodule", type: MatMenuModule }, { kind: "directive", type: i2.MatMenuTrigger, selector: "[mat-menu-trigger-for], [matMenuTriggerFor]", inputs: ["mat-menu-trigger-for", "matMenuTriggerFor", "matMenuTriggerData", "matMenuTriggerRestoreFocus"], outputs: ["menuOpened", "onMenuOpen", "menuClosed", "onMenuClose"], exportAs: ["matMenuTrigger"] }, { kind: "directive", type: ActionDropdownTriggerDirective, selector: "[apActionDropdownTrigger]", inputs: ["apActionDropdownTrigger"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.16", ngImport: i0, type: SplitButtonComponent, decorators: [{
            type: Component,
            args: [{ changeDetection: ChangeDetectionStrategy.OnPush, selector: 'ap-split-button', imports: [SymbolComponent, MatMenuModule, ActionDropdownTriggerDirective], encapsulation: ViewEncapsulation.None, hostDirectives: [BaseButtonDirective], host: {
                        '[attr.disabled]': '(disabled() && splitDisabled())  || null',
                    }, template: "<button\n    #button\n    type=\"button\"\n    [class.primary]=\"config().style === 'primary'\"\n    [class.orange]=\"config().color === 'orange'\"\n    [class.blue]=\"config().color === 'blue'\"\n    [class.inverse]=\"symbolPosition() === 'left'\"\n    [disabled]=\"disabled()\"\n    [name]=\"name()\"\n    [id]=\"id\"\n    [attr.data-test]=\"baseButtonDirective.hostDataTest ?? name()\"\n    (click)=\"onClickHandle($event)\"\n    (focus)=\"focus.emit($event)\"\n    (blur)=\"blur.emit($event)\">\n    <ng-content select=\"span\" />\n    @if (symbolId()) {\n        <ap-symbol [symbolId]=\"symbolId()\" />\n    } @else {\n        <ng-content select=\"ap-symbol\" />\n    }\n</button>\n<button\n    #splitButton\n    type=\"button\"\n    [class.primary]=\"config().style === 'primary'\"\n    [class.orange]=\"config().color === 'orange'\"\n    [class.blue]=\"config().color === 'blue'\"\n    [disabled]=\"splitDisabled()\"\n    [id]=\"id + '-split'\"\n    [attr.aria-labelledby]=\"id + '-split ' + id\"\n    [attr.data-test]=\"splitButtonDataTest() ?? name() + '-split'\"\n    [apActionDropdownTrigger]=\"actionDropdownTrigger()\"\n    [matMenuTriggerFor]=\"menuTrigger()\"\n    (click)=\"onSplitButtonClickHandle($event)\"\n    (menuClosed)=\"handleMenuClosed()\"\n    (menuOpened)=\"handleMenuOpened()\">\n    <ap-symbol\n        symbolId=\"chevron-down\"\n        size=\"sm\"\n        [class.opened]=\"menuOpen\" />\n    <span class=\"visually-hidden\">Toggle</span>\n</button>\n", styles: ["ap-split-button{--loading-bar-width: 50px;display:inline-flex;gap:1px;position:relative}ap-split-button[disabled]{pointer-events:none}ap-split-button button{border:none;position:relative;padding:var(--comp-split-button-padding-horizontal) var(--comp-split-button-padding-vertical);max-height:var(--comp-button-height);min-height:var(--comp-button-height);overflow:hidden;display:flex;flex-direction:row;justify-content:center;align-items:center;gap:10px}ap-split-button button ap-symbol{width:16px;min-width:16px;max-width:16px;height:16px;min-height:16px;max-height:16px}ap-split-button button.inverse{flex-direction:row-reverse}ap-split-button button:hover:not(:disabled):not(.loading){cursor:pointer}ap-split-button button:disabled{pointer-events:none}@media(hover:hover){ap-split-button button:focus:not(:disabled):not(:active):not(.loading){outline:2px solid var(--ref-color-electric-blue-100);outline-offset:1px;z-index:10}}ap-split-button button span{font-size:var(--comp-split-button-text-size);font-family:var(--comp-split-button-text-font-family);line-height:var(--comp-split-button-text-line-height);font-weight:var(--comp-split-button-text-weight);white-space:nowrap;text-overflow:ellipsis;overflow:hidden}ap-split-button button.loading{pointer-events:none}ap-split-button button.primary span,ap-split-button button.primary ap-symbol{color:var(--ref-color-white)}ap-split-button button.primary.orange{background:var(--ref-color-orange-100)}ap-split-button button.primary.orange:hover{background-color:var(--ref-color-orange-80)}ap-split-button button.primary.orange:active:not(:disabled){background-color:var(--ref-color-orange-60)}ap-split-button button.primary.orange:disabled{background-color:var(--ref-color-orange-20)}ap-split-button button.primary.orange.loading{background-color:var(--ref-color-orange-60)}ap-split-button button.primary.orange .loading-bar{background-color:var(--ref-color-orange-100)}ap-split-button button.primary.blue{background:var(--ref-color-electric-blue-100)}ap-split-button button.primary.blue:hover{background-color:var(--ref-color-electric-blue-80)}ap-split-button button.primary.blue:active:not(:disabled){background-color:var(--ref-color-electric-blue-60)}ap-split-button button.primary.blue:disabled{background-color:var(--ref-color-electric-blue-20)}ap-split-button button.primary.blue.loading{background-color:var(--ref-color-electric-blue-60)}ap-split-button button.primary.blue .loading-bar{background-color:var(--ref-color-electric-blue-100)}ap-split-button button:first-child{border-top-left-radius:var(--comp-split-button-border-radius);border-bottom-left-radius:var(--comp-split-button-border-radius)}ap-split-button button:last-child{border-top-right-radius:var(--comp-split-button-border-radius);border-bottom-right-radius:var(--comp-split-button-border-radius);padding:var(--comp-split-button-padding-horizontal) 10px var(--comp-split-button-padding-horizontal) 10px}ap-split-button button ap-symbol{will-change:transform;transition:.2s ease-in-out}ap-split-button button ap-symbol.opened{transform:rotate(180deg)}.visually-hidden{width:1px!important;height:1px!important;overflow:hidden!important;clip:rect(0,0,0,0)!important;white-space:nowrap!important;position:absolute!important}\n"] }]
        }], ctorParameters: () => [], propDecorators: { disabled: [{ type: i0.Input, args: [{ isSignal: true, alias: "disabled", required: false }] }], config: [{ type: i0.Input, args: [{ isSignal: true, alias: "config", required: false }] }], actionDropdownTrigger: [{ type: i0.Input, args: [{ isSignal: true, alias: "actionDropdownTrigger", required: false }] }], menuTrigger: [{ type: i0.Input, args: [{ isSignal: true, alias: "menuTrigger", required: false }] }], splitDisabled: [{ type: i0.Input, args: [{ isSignal: true, alias: "splitDisabled", required: false }] }], symbolPosition: [{ type: i0.Input, args: [{ isSignal: true, alias: "symbolPosition", required: false }] }], splitButtonDataTest: [{ type: i0.Input, args: [{ isSignal: true, alias: "splitButtonDataTest", required: false }] }], symbolId: [{ type: i0.Input, args: [{ isSignal: true, alias: "symbolId", required: false }] }], name: [{ type: i0.Input, args: [{ isSignal: true, alias: "name", required: false }] }], menuOpened: [{ type: i0.Output, args: ["menuOpened"] }], menuClosed: [{ type: i0.Output, args: ["menuClosed"] }], mainButtonClick: [{ type: i0.Output, args: ["mainButtonClick"] }], focus: [{ type: i0.Output, args: ["focus"] }], blur: [{ type: i0.Output, args: ["blur"] }], buttonElement: [{ type: i0.ViewChild, args: ['button', { isSignal: true }] }], splitButtonElement: [{ type: i0.ViewChild, args: ['splitButton', { isSignal: true }] }], symbolComponent: [{ type: i0.ContentChild, args: [i0.forwardRef(() => SymbolComponent), { isSignal: true }] }], onSpaceKeyUp: [{
                type: HostListener,
                args: ['window:keyup.space', ['$event']]
            }] } });

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

export { SplitButtonComponent };
//# sourceMappingURL=agorapulse-ui-components-split-button.mjs.map
