import * as i0 from '@angular/core';
import { EventEmitter, Directive, Output, HostListener, NgModule } from '@angular/core';
import * as i1 from '@angular/forms';
import { CommonModule } from '@angular/common';

class EnhancedPasteDirective {
    constructor(element, model) {
        this.element = element;
        this.model = model;
        this.numberOverflow = new EventEmitter();
    }
    onPaste(event) {
        // Prevent the default paste event
        event.preventDefault();
        // Get data from clipboard
        const data = event.clipboardData || window.clipboardData;
        const contents = data.getData('text');
        // Get min and max from input
        const min = parseFloat(this.element.nativeElement.min);
        const max = parseFloat(this.element.nativeElement.max);
        const filtered = this.filterInput(contents, min, max);
        if (filtered) {
            this.numberOverflow.emit(filtered);
            if (filtered.boundaryValue) {
                // Update NgModel
                this.model.control.setValue(filtered?.boundaryValue, { emitEvent: false, onlySelf: true });
            }
        }
    }
    filterInput(value, min, max) {
        const val = parseInt(value);
        if (isNaN(val)) {
            return { boundary: 'invalid' };
        }
        else if (val > max) {
            return { boundary: 'max', inputValue: val, boundaryValue: max };
        }
        else if (val < min) {
            return { boundary: 'min', inputValue: val, boundaryValue: min };
        }
        else {
            return null;
        }
    }
}
EnhancedPasteDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: EnhancedPasteDirective, deps: [{ token: i0.ElementRef }, { token: i1.NgModel }], target: i0.ɵɵFactoryTarget.Directive });
EnhancedPasteDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "15.2.7", type: EnhancedPasteDirective, selector: "input[type=\"number\"][bsEnhancedPaste]", outputs: { numberOverflow: "numberOverflow" }, host: { listeners: { "paste": "onPaste($event)" } }, ngImport: i0 });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: EnhancedPasteDirective, decorators: [{
            type: Directive,
            args: [{
                    selector: 'input[type="number"][bsEnhancedPaste]'
                }]
        }], ctorParameters: function () { return [{ type: i0.ElementRef }, { type: i1.NgModel }]; }, propDecorators: { numberOverflow: [{
                type: Output
            }], onPaste: [{
                type: HostListener,
                args: ['paste', ['$event']]
            }] } });

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

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

export { EnhancedPasteDirective, EnhancedPasteModule };
//# sourceMappingURL=mintplayer-ng-bootstrap-enhanced-paste.mjs.map
