import * as i0 from '@angular/core';
import { EventEmitter, Component, ViewChild, HostBinding, Input, Output, Directive, ContentChildren, forwardRef, NgModule } from '@angular/core';
import { BehaviorSubject, map, combineLatest, Subject, fromEvent, takeUntil } from 'rxjs';
import * as i1 from '@angular/common';
import { CommonModule } from '@angular/common';
import { NG_VALUE_ACCESSOR } from '@angular/forms';

class BsToggleButtonComponent {
    constructor() {
        this.dInlineBlockClass = true;
        this.disableAnimations = true;
        //#region Type
        this.type$ = new BehaviorSubject('checkbox');
        //#endregion
        //#region isToggled
        this._isToggled = false;
        this.isToggledChange = new EventEmitter();
        //#endregion
        //#region disabled
        this.disabled = false;
        //#endregion
        //#region name
        this.name$ = new BehaviorSubject(null);
        //#endregion
        //#region value
        this.value$ = new BehaviorSubject(null);
        //#endregion
        //#region Group
        this.group$ = new BehaviorSubject(null);
        this.mainCheckStyle$ = this.type$.pipe(map((type) => {
            switch (type) {
                case 'checkbox':
                case 'radio':
                case 'switch':
                    return 'form-check';
                default:
                    return null;
            }
        }));
        this.isSwitch$ = this.type$.pipe(map((type) => {
            switch (type) {
                case 'switch':
                    return true;
                default:
                    return false;
            }
        }));
        this.inputClass$ = this.type$.pipe(map((type) => {
            switch (type) {
                case 'checkbox':
                case 'radio':
                case 'switch':
                    return 'form-check-input';
                default:
                    return 'btn-check';
            }
        }));
        this.labelClass$ = this.type$.pipe(map((type) => {
            switch (type) {
                case 'checkbox':
                case 'radio':
                case 'switch':
                    return 'form-check-label';
                case 'toggle_button':
                    return 'btn btn-primary';
                case 'radio_toggle_button':
                    return 'btn btn-secondary';
            }
        }));
        this.checkOrRadio$ = this.type$.pipe(map((type) => {
            switch (type) {
                case 'radio':
                case 'radio_toggle_button':
                    return 'radio';
                default:
                    return 'checkbox';
            }
        }));
        this.nameResult$ = combineLatest([this.name$, this.type$, this.group$])
            .pipe(map(([name, type, group]) => {
            switch (type) {
                case 'radio':
                case 'radio_toggle_button':
                    return name;
                case 'checkbox':
                case 'toggle_button':
                case 'switch':
                    if (group) {
                        return `${name}[]`;
                    }
                    else {
                        return name;
                    }
                default:
                    throw 'Invalid value';
            }
        }));
    }
    get type() {
        return this.type$.value;
    }
    set type(value) {
        this.type$.next(value);
    }
    get isToggled() {
        return this._isToggled;
    }
    set isToggled(value) {
        this._isToggled = value;
        this.isToggledChange.emit(this._isToggled);
    }
    get name() {
        return this.name$.value;
    }
    set name(value) {
        this.name$.next(value);
    }
    get value() {
        return this.value$.value;
    }
    set value(value) {
        this.value$.next(value);
    }
    get group() {
        return this.group$.value;
    }
    set group(value) {
        this.group$.next(value);
    }
    //#endregion
    ngAfterViewInit() {
        this.disableAnimations = false;
    }
}
BsToggleButtonComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.0.4", ngImport: i0, type: BsToggleButtonComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
BsToggleButtonComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.0.4", type: BsToggleButtonComponent, selector: "bs-toggle-button", inputs: { type: "type", isToggled: "isToggled", disabled: "disabled", name: "name", value: "value", group: "group" }, outputs: { isToggledChange: "isToggledChange" }, host: { properties: { "class.d-inline-block": "this.dInlineBlockClass" } }, viewQueries: [{ propertyName: "checkbox", first: true, predicate: ["checkbox"], descendants: true }], ngImport: i0, template: "<label [class]=\"mainCheckStyle$ | async\" [class.form-switch]=\"isSwitch$ | async\">\n    <input #checkbox [class]=\"inputClass$ | async\" [type]=\"checkOrRadio$ | async\" [name]=\"name$ | async\" [value]=\"value$ | async\">\n    <span [class]=\"labelClass$ | async\">\n        <ng-content></ng-content>\n    </span>\n</label>", styles: [":host ::ng-deep .form-check{display:block;min-height:1.5rem;padding-left:1.5em;margin-bottom:.125rem}:host ::ng-deep .form-check .form-check-input{float:left;margin-left:-1.5em}:host ::ng-deep .form-check-reverse{padding-right:1.5em;padding-left:0;text-align:right}:host ::ng-deep .form-check-reverse .form-check-input{float:right;margin-right:-1.5em;margin-left:0}:host ::ng-deep .form-check-input{width:1em;height:1em;margin-top:.25em;vertical-align:top;background-color:#fff;background-repeat:no-repeat;background-position:center;background-size:contain;border:1px solid rgba(0,0,0,.25);-webkit-appearance:none;appearance:none;-webkit-print-color-adjust:exact;print-color-adjust:exact}:host ::ng-deep .form-check-input[type=checkbox]{border-radius:.25em}:host ::ng-deep .form-check-input[type=radio]{border-radius:50%}:host ::ng-deep .form-check-input:active{filter:brightness(90%)}:host ::ng-deep .form-check-input:focus{border-color:#86b7fe;outline:0;box-shadow:0 0 0 .25rem #0d6efd40}:host ::ng-deep .form-check-input:checked{background-color:#0d6efd;border-color:#0d6efd}:host ::ng-deep .form-check-input:checked[type=checkbox]{background-image:url(\"data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3e%3cpath fill='none' stroke='%23fff' stroke-linecap='round' stroke-linejoin='round' stroke-width='3' d='m6 10 3 3 6-6'/%3e%3c/svg%3e\")}:host ::ng-deep .form-check-input:checked[type=radio]{background-image:url(\"data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='-4 -4 8 8'%3e%3ccircle r='2' fill='%23fff'/%3e%3c/svg%3e\")}:host ::ng-deep .form-check-input[type=checkbox]:indeterminate{background-color:#0d6efd;border-color:#0d6efd;background-image:url(\"data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3e%3cpath fill='none' stroke='%23fff' stroke-linecap='round' stroke-linejoin='round' stroke-width='3' d='M6 10h8'/%3e%3c/svg%3e\")}:host ::ng-deep .form-check-input:disabled{pointer-events:none;filter:none;opacity:.5}:host ::ng-deep .form-check-input[disabled]~.form-check-label,:host ::ng-deep .form-check-input:disabled~.form-check-label{cursor:default;opacity:.5}:host ::ng-deep .form-switch{padding-left:2.5em}:host ::ng-deep .form-switch .form-check-input{width:2em;margin-left:-2.5em;background-image:url(\"data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='-4 -4 8 8'%3e%3ccircle r='3' fill='rgba%280, 0, 0, 0.25%29'/%3e%3c/svg%3e\");background-position:left center;border-radius:2em;transition:background-position .15s ease-in-out}@media (prefers-reduced-motion: reduce){:host ::ng-deep .form-switch .form-check-input{transition:none}}:host ::ng-deep .form-switch .form-check-input:focus{background-image:url(\"data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='-4 -4 8 8'%3e%3ccircle r='3' fill='%2386b7fe'/%3e%3c/svg%3e\")}:host ::ng-deep .form-switch .form-check-input:checked{background-position:right center;background-image:url(\"data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='-4 -4 8 8'%3e%3ccircle r='3' fill='%23fff'/%3e%3c/svg%3e\")}:host ::ng-deep .form-switch.form-check-reverse{padding-right:2.5em;padding-left:0}:host ::ng-deep .form-switch.form-check-reverse .form-check-input{margin-right:-2.5em;margin-left:0}:host ::ng-deep .form-check-inline{display:inline-block;margin-right:1rem}:host ::ng-deep .btn-check{position:absolute;clip:rect(0,0,0,0);pointer-events:none}:host ::ng-deep .btn-check[disabled]+.btn,:host ::ng-deep .btn-check:disabled+.btn{pointer-events:none;filter:none;opacity:.65}\n"], dependencies: [{ kind: "pipe", type: i1.AsyncPipe, name: "async" }] });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.0.4", ngImport: i0, type: BsToggleButtonComponent, decorators: [{
            type: Component,
            args: [{ selector: 'bs-toggle-button', template: "<label [class]=\"mainCheckStyle$ | async\" [class.form-switch]=\"isSwitch$ | async\">\n    <input #checkbox [class]=\"inputClass$ | async\" [type]=\"checkOrRadio$ | async\" [name]=\"name$ | async\" [value]=\"value$ | async\">\n    <span [class]=\"labelClass$ | async\">\n        <ng-content></ng-content>\n    </span>\n</label>", styles: [":host ::ng-deep .form-check{display:block;min-height:1.5rem;padding-left:1.5em;margin-bottom:.125rem}:host ::ng-deep .form-check .form-check-input{float:left;margin-left:-1.5em}:host ::ng-deep .form-check-reverse{padding-right:1.5em;padding-left:0;text-align:right}:host ::ng-deep .form-check-reverse .form-check-input{float:right;margin-right:-1.5em;margin-left:0}:host ::ng-deep .form-check-input{width:1em;height:1em;margin-top:.25em;vertical-align:top;background-color:#fff;background-repeat:no-repeat;background-position:center;background-size:contain;border:1px solid rgba(0,0,0,.25);-webkit-appearance:none;appearance:none;-webkit-print-color-adjust:exact;print-color-adjust:exact}:host ::ng-deep .form-check-input[type=checkbox]{border-radius:.25em}:host ::ng-deep .form-check-input[type=radio]{border-radius:50%}:host ::ng-deep .form-check-input:active{filter:brightness(90%)}:host ::ng-deep .form-check-input:focus{border-color:#86b7fe;outline:0;box-shadow:0 0 0 .25rem #0d6efd40}:host ::ng-deep .form-check-input:checked{background-color:#0d6efd;border-color:#0d6efd}:host ::ng-deep .form-check-input:checked[type=checkbox]{background-image:url(\"data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3e%3cpath fill='none' stroke='%23fff' stroke-linecap='round' stroke-linejoin='round' stroke-width='3' d='m6 10 3 3 6-6'/%3e%3c/svg%3e\")}:host ::ng-deep .form-check-input:checked[type=radio]{background-image:url(\"data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='-4 -4 8 8'%3e%3ccircle r='2' fill='%23fff'/%3e%3c/svg%3e\")}:host ::ng-deep .form-check-input[type=checkbox]:indeterminate{background-color:#0d6efd;border-color:#0d6efd;background-image:url(\"data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3e%3cpath fill='none' stroke='%23fff' stroke-linecap='round' stroke-linejoin='round' stroke-width='3' d='M6 10h8'/%3e%3c/svg%3e\")}:host ::ng-deep .form-check-input:disabled{pointer-events:none;filter:none;opacity:.5}:host ::ng-deep .form-check-input[disabled]~.form-check-label,:host ::ng-deep .form-check-input:disabled~.form-check-label{cursor:default;opacity:.5}:host ::ng-deep .form-switch{padding-left:2.5em}:host ::ng-deep .form-switch .form-check-input{width:2em;margin-left:-2.5em;background-image:url(\"data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='-4 -4 8 8'%3e%3ccircle r='3' fill='rgba%280, 0, 0, 0.25%29'/%3e%3c/svg%3e\");background-position:left center;border-radius:2em;transition:background-position .15s ease-in-out}@media (prefers-reduced-motion: reduce){:host ::ng-deep .form-switch .form-check-input{transition:none}}:host ::ng-deep .form-switch .form-check-input:focus{background-image:url(\"data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='-4 -4 8 8'%3e%3ccircle r='3' fill='%2386b7fe'/%3e%3c/svg%3e\")}:host ::ng-deep .form-switch .form-check-input:checked{background-position:right center;background-image:url(\"data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='-4 -4 8 8'%3e%3ccircle r='3' fill='%23fff'/%3e%3c/svg%3e\")}:host ::ng-deep .form-switch.form-check-reverse{padding-right:2.5em;padding-left:0}:host ::ng-deep .form-switch.form-check-reverse .form-check-input{margin-right:-2.5em;margin-left:0}:host ::ng-deep .form-check-inline{display:inline-block;margin-right:1rem}:host ::ng-deep .btn-check{position:absolute;clip:rect(0,0,0,0);pointer-events:none}:host ::ng-deep .btn-check[disabled]+.btn,:host ::ng-deep .btn-check:disabled+.btn{pointer-events:none;filter:none;opacity:.65}\n"] }]
        }], ctorParameters: function () { return []; }, propDecorators: { checkbox: [{
                type: ViewChild,
                args: ['checkbox']
            }], dInlineBlockClass: [{
                type: HostBinding,
                args: ['class.d-inline-block']
            }], type: [{
                type: Input
            }], isToggledChange: [{
                type: Output
            }], isToggled: [{
                type: Input
            }], disabled: [{
                type: Input
            }], name: [{
                type: Input
            }], value: [{
                type: Input
            }], group: [{
                type: Input
            }] } });

class BsToggleButtonGroupDirective {
    constructor() { }
}
BsToggleButtonGroupDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.0.4", ngImport: i0, type: BsToggleButtonGroupDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive });
BsToggleButtonGroupDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "15.0.4", type: BsToggleButtonGroupDirective, selector: "[bsToggleButtonGroup]", queries: [{ propertyName: "toggleButtons", predicate: BsToggleButtonComponent, descendants: true }], exportAs: ["bsToggleButtonGroup"], ngImport: i0 });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.0.4", ngImport: i0, type: BsToggleButtonGroupDirective, decorators: [{
            type: Directive,
            args: [{
                    selector: '[bsToggleButtonGroup]',
                    exportAs: 'bsToggleButtonGroup'
                }]
        }], ctorParameters: function () { return []; }, propDecorators: { toggleButtons: [{
                type: ContentChildren,
                args: [BsToggleButtonComponent, { descendants: true }]
            }] } });

class BsToggleButtonValueAccessor {
    constructor(host) {
        this.host = host;
        this.destroyed$ = new Subject();
    }
    //#region Lifecycle hooks
    ngAfterViewInit() {
        fromEvent(this.host.checkbox.nativeElement, 'change')
            .pipe(takeUntil(this.destroyed$))
            .subscribe((ev) => {
            if (this.onValueChange && this.host.checkbox) {
                const isChecked = ev.target.checked;
                switch (this.host.type) {
                    case 'radio':
                    case 'radio_toggle_button':
                        if (isChecked) {
                            this.onValueChange(this.host.checkbox.nativeElement.value);
                        }
                        break;
                    default:
                        if (this.host['group']) {
                            const group = this.host['group'];
                            const itemValue = this.host.checkbox.nativeElement.value;
                            const result = group.toggleButtons
                                .map(tb => ({ value: tb.value, checked: tb.checkbox.nativeElement.checked }))
                                .filter(tb => !!tb.value && tb.checked)
                                .map(tb => tb.value);
                            if (this.host.checkbox.nativeElement.checked) {
                                if (!result.includes(itemValue)) {
                                    result.push(itemValue);
                                }
                            }
                            else {
                                if (result.includes(itemValue)) {
                                    result.splice(result.indexOf(itemValue), 1);
                                }
                            }
                            this.onValueChange(result);
                        }
                        else {
                            this.onValueChange(isChecked);
                        }
                        break;
                }
            }
        });
    }
    ngOnDestroy() {
        this.destroyed$.next(true);
    }
    //#endregion
    //#region ControlValueAccessor implementation
    registerOnChange(fn) {
        this.onValueChange = fn;
    }
    registerOnTouched(fn) {
        this.onTouched = fn;
    }
    writeValue(value) {
        if (this.host.checkbox) {
            switch (this.host.type) {
                case 'radio':
                case 'radio_toggle_button':
                    if (value === this.host.value) {
                        this.host.checkbox.nativeElement.checked = true;
                    }
                    break;
                default:
                    if (this.host.group) {
                        this.host.checkbox.nativeElement.checked = value.includes(this.host.value);
                    }
                    else {
                        this.host.checkbox.nativeElement.checked = value;
                    }
                    break;
            }
        }
    }
    setDisabledState(isDisabled) {
        if (this.host.checkbox) {
            this.host.checkbox.nativeElement.disabled = isDisabled;
        }
    }
}
BsToggleButtonValueAccessor.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.0.4", ngImport: i0, type: BsToggleButtonValueAccessor, deps: [{ token: BsToggleButtonComponent }], target: i0.ɵɵFactoryTarget.Directive });
BsToggleButtonValueAccessor.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "15.0.4", type: BsToggleButtonValueAccessor, selector: "bs-toggle-button", providers: [{
            provide: NG_VALUE_ACCESSOR,
            useExisting: forwardRef(() => BsToggleButtonValueAccessor),
            multi: true,
        }], ngImport: i0 });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.0.4", ngImport: i0, type: BsToggleButtonValueAccessor, decorators: [{
            type: Directive,
            args: [{
                    selector: 'bs-toggle-button',
                    providers: [{
                            provide: NG_VALUE_ACCESSOR,
                            useExisting: forwardRef(() => BsToggleButtonValueAccessor),
                            multi: true,
                        }],
                }]
        }], ctorParameters: function () { return [{ type: BsToggleButtonComponent }]; } });

class BsToggleButtonModule {
}
BsToggleButtonModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.0.4", ngImport: i0, type: BsToggleButtonModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
BsToggleButtonModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.0.4", ngImport: i0, type: BsToggleButtonModule, declarations: [BsToggleButtonComponent,
        BsToggleButtonValueAccessor,
        BsToggleButtonGroupDirective], imports: [CommonModule], exports: [BsToggleButtonComponent,
        BsToggleButtonValueAccessor,
        BsToggleButtonGroupDirective] });
BsToggleButtonModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.0.4", ngImport: i0, type: BsToggleButtonModule, imports: [CommonModule] });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.0.4", ngImport: i0, type: BsToggleButtonModule, decorators: [{
            type: NgModule,
            args: [{
                    declarations: [
                        BsToggleButtonComponent,
                        BsToggleButtonValueAccessor,
                        BsToggleButtonGroupDirective
                    ],
                    imports: [
                        CommonModule
                    ],
                    exports: [
                        BsToggleButtonComponent,
                        BsToggleButtonValueAccessor,
                        BsToggleButtonGroupDirective
                    ]
                }]
        }] });

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

export { BsToggleButtonComponent, BsToggleButtonGroupDirective, BsToggleButtonModule, BsToggleButtonValueAccessor };
//# sourceMappingURL=mintplayer-ng-bootstrap-toggle-button.mjs.map
