import * as i0 from '@angular/core';
import { EventEmitter, Component, Output, Input, NgModule } from '@angular/core';
import { Color } from '@mintplayer/ng-bootstrap';
import * as i1 from '@angular/common';
import { CommonModule } from '@angular/common';
import * as i2 from '@angular/forms';
import { FormsModule } from '@angular/forms';
import * as i3 from '@mintplayer/ng-bootstrap/enhanced-paste';
import { EnhancedPasteModule } from '@mintplayer/ng-bootstrap/enhanced-paste';
import * as i4 from '@mintplayer/ng-bootstrap/form';
import { BsFormModule } from '@mintplayer/ng-bootstrap/form';
import * as i5 from '@mintplayer/ng-bootstrap/icon';
import { BsIconModule } from '@mintplayer/ng-bootstrap/icon';
import * as i6 from '@mintplayer/ng-bootstrap/dropdown';
import { BsDropdownModule } from '@mintplayer/ng-bootstrap/dropdown';
import * as i7 from '@mintplayer/ng-bootstrap/has-overlay';
import { BsHasOverlayModule } from '@mintplayer/ng-bootstrap/has-overlay';
import * as i8 from '@mintplayer/ng-bootstrap/dropdown-menu';
import { BsDropdownMenuModule } from '@mintplayer/ng-bootstrap/dropdown-menu';
import * as i9 from '@mintplayer/ng-bootstrap/input-group';
import { BsInputGroupModule } from '@mintplayer/ng-bootstrap/input-group';
import * as i10 from '@mintplayer/ng-bootstrap/button-type';
import { BsButtonTypeModule } from '@mintplayer/ng-bootstrap/button-type';

class BsTimepickerComponent {
    constructor(ref, zone, renderer) {
        this.ref = ref;
        this.zone = zone;
        this.renderer = renderer;
        this.colors = Color;
        this.isOpen = false;
        this.presetTimestamps = [];
        this.isFocused = false;
        //#region SelectedTime
        this._selectedTime = new Date();
        this.selectedTimeChange = new EventEmitter();
        const today = new Date();
        today.setHours(0);
        today.setMinutes(0);
        today.setSeconds(0);
        const interval = 900;
        this.presetTimestamps = Array.from(Array(24 * 60 * 60 / interval).keys())
            .map(i => {
            const clone = new Date(today);
            clone.setTime(clone.getTime() + i * interval * 1000);
            return clone;
        });
    }
    selectAll(box) {
        box.select();
        // box.setSelectionRange(0, box.value.length);
        this.isFocused = true;
    }
    setNumber(event, max, nextInput) {
        event.preventDefault();
        const input = event.target;
        const val = parseInt(input.value);
        if (isNaN(val)) {
            input.value = '00';
        }
        else {
            const result = Math.min(max, Math.abs(val));
            input.value = result.toString().padStart(2, '0');
            if (nextInput) {
                // const maxAllowedNumberOfDigits = input.max.length;
                if (result * 10 > parseInt(input.max)) {
                    nextInput.focus();
                }
            }
        }
    }
    setTime(time) {
        this.selectedTime = time;
        this.isOpen = false;
    }
    get selectedTime() {
        return this._selectedTime;
    }
    set selectedTime(value) {
        // this.hours = value.getHours();
        // this.minutes = value.getMinutes();
        this._selectedTime = value;
        this.selectedTimeChange.emit(this._selectedTime);
    }
    //#endregion
    //#region Hours
    // private _hours = 0;
    get hours() {
        // return this._hours;
        return this.selectedTime.getHours();
    }
    set hours(value) {
        // this._hours = value;
        const clone = new Date(this.selectedTime);
        clone.setHours(value);
        this.selectedTime = clone;
    }
    // hours = 0;
    //#endregion
    //#region Minutes
    // private _minutes = 0;
    get minutes() {
        // return this._minutes;
        return this.selectedTime.getMinutes();
    }
    set minutes(value) {
        // this._minutes = value;
        // this.selectedTime.setMinutes(value);
        const clone = new Date(this.selectedTime);
        clone.setMinutes(value);
        this.selectedTime = clone;
    }
    //#endregion
    timesEqual(time1, time2) {
        return (time1.getHours() === time2.getHours()) && (time1.getMinutes() === time2.getMinutes());
    }
}
BsTimepickerComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: BsTimepickerComponent, deps: [{ token: i0.ChangeDetectorRef }, { token: i0.NgZone }, { token: i0.Renderer2 }], target: i0.ɵɵFactoryTarget.Component });
BsTimepickerComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.2.7", type: BsTimepickerComponent, selector: "bs-timepicker", inputs: { selectedTime: "selectedTime" }, outputs: { selectedTimeChange: "selectedTimeChange" }, ngImport: i0, template: "<!-- <bs-dropdown [(isOpen)]=\"isOpen\" [sameDropdownWidth]=\"true\"></bs-dropdown> -->\n<div bsDropdown [(isOpen)]=\"isOpen\" [sameDropdownWidth]=\"true\">\n    <bs-form>\n        <bs-input-group>\n            <span class=\"form-control d-flex\" [class.focus]=\"isFocused\">\n                <div class=\"flex-grow-1\">\n                    <input type=\"number\" [min]=\"0\" [max]=\"23\" (input)=\"setNumber($event, 23, minuteBox)\" bsEnhancedPaste [ngModel]=\"hours | number: '2.0'\" (ngModelChange)=\"hours = $event\" (focus)=\"selectAll(hourBox)\" (blur)=\"isFocused = false\" #hourBox class=\"w-100 border-0 bg-transparent text-end no-form-control\">\n                </div>\n                <span class=\"px-1\">:</span>\n                <div class=\"flex-grow-1\">\n                    <input type=\"number\" [min]=\"0\" [max]=\"59\" (input)=\"setNumber($event, 59, null)\" bsEnhancedPaste [ngModel]=\"minutes | number: '2.0'\" (ngModelChange)=\"minutes = $event\"  (focus)=\"selectAll(minuteBox)\" (blur)=\"isFocused = false\" #minuteBox class=\"w-100 border-0 bg-transparent no-form-control\">\n                </div>\n            </span>\n            <button [color]=\"colors.secondary\" (click)=\"isOpen = !isOpen\">\n                <bs-icon [icon]=\"'clock'\"></bs-icon>\n            </button>\n        </bs-input-group>\n    </bs-form>\n    <bs-has-overlay></bs-has-overlay>\n    <bs-dropdown-menu class=\"overflow-auto\" *bsDropdownMenu>\n        <bs-dropdown-item [isSelected]=\"timesEqual(selectedTime, timestamp)\" *ngFor=\"let timestamp of presetTimestamps\" (click)=\"setTime(timestamp)\">\n            {{ timestamp | date: 'HH:mm' }}\n        </bs-dropdown-item>\n    </bs-dropdown-menu>\n</div>", styles: [":host{display:inline-block}input::-webkit-outer-spin-button,input::-webkit-inner-spin-button{-webkit-appearance:none;margin:0}input[type=number]{-moz-appearance:textfield;outline:0px!important}.form-control{transition:border-color .15s ease-in-out,box-shadow .15s ease-in-out}.form-control.focus{color:#495057;background-color:#fff;border-color:#80bdff!important;outline:0;box-shadow:0 0 0 .2rem #007bff40}bs-dropdown-menu{max-height:250px}\n"], dependencies: [{ kind: "directive", type: i1.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { kind: "directive", type: i2.DefaultValueAccessor, selector: "input:not([type=checkbox])[formControlName],textarea[formControlName],input:not([type=checkbox])[formControl],textarea[formControl],input:not([type=checkbox])[ngModel],textarea[ngModel],[ngDefaultControl]" }, { kind: "directive", type: i2.NumberValueAccessor, selector: "input[type=number][formControlName],input[type=number][formControl],input[type=number][ngModel]" }, { kind: "directive", type: i2.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i2.MinValidator, selector: "input[type=number][min][formControlName],input[type=number][min][formControl],input[type=number][min][ngModel]", inputs: ["min"] }, { kind: "directive", type: i2.MaxValidator, selector: "input[type=number][max][formControlName],input[type=number][max][formControl],input[type=number][max][ngModel]", inputs: ["max"] }, { kind: "directive", type: i2.NgModel, selector: "[ngModel]:not([formControlName]):not([formControl])", inputs: ["name", "disabled", "ngModel", "ngModelOptions"], outputs: ["ngModelChange"], exportAs: ["ngModel"] }, { kind: "directive", type: i3.EnhancedPasteDirective, selector: "input[type=\"number\"][bsEnhancedPaste]", outputs: ["numberOverflow"] }, { kind: "component", type: i4.BsFormComponent, selector: "bs-form", outputs: ["submitted"] }, { kind: "component", type: i5.BsIconComponent, selector: "bs-icon", inputs: ["icon"] }, { kind: "directive", type: i6.BsDropdownDirective, selector: "[bsDropdown]", inputs: ["hasBackdrop", "sameWidth", "closeOnClickOutside", "sameDropdownWidth", "isOpen"], outputs: ["isOpenChange"] }, { kind: "directive", type: i6.BsDropdownMenuDirective, selector: "[bsDropdownMenu]" }, { kind: "component", type: i7.BsHasOverlayComponent, selector: "bs-has-overlay" }, { kind: "component", type: i8.BsDropdownMenuComponent, selector: "bs-dropdown-menu", inputs: ["maxHeight"] }, { kind: "component", type: i8.BsDropdownItemComponent, selector: "bs-dropdown-item", inputs: ["isSelected", "disabled"] }, { kind: "component", type: i9.BsInputGroupComponent, selector: "bs-input-group" }, { kind: "directive", type: i10.BsButtonTypeDirective, selector: "button[color],input[type=\"button\"][color],input[type=\"submit\"][color]", inputs: ["color"] }, { kind: "pipe", type: i1.DecimalPipe, name: "number" }, { kind: "pipe", type: i1.DatePipe, name: "date" }] });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: BsTimepickerComponent, decorators: [{
            type: Component,
            args: [{ selector: 'bs-timepicker', template: "<!-- <bs-dropdown [(isOpen)]=\"isOpen\" [sameDropdownWidth]=\"true\"></bs-dropdown> -->\n<div bsDropdown [(isOpen)]=\"isOpen\" [sameDropdownWidth]=\"true\">\n    <bs-form>\n        <bs-input-group>\n            <span class=\"form-control d-flex\" [class.focus]=\"isFocused\">\n                <div class=\"flex-grow-1\">\n                    <input type=\"number\" [min]=\"0\" [max]=\"23\" (input)=\"setNumber($event, 23, minuteBox)\" bsEnhancedPaste [ngModel]=\"hours | number: '2.0'\" (ngModelChange)=\"hours = $event\" (focus)=\"selectAll(hourBox)\" (blur)=\"isFocused = false\" #hourBox class=\"w-100 border-0 bg-transparent text-end no-form-control\">\n                </div>\n                <span class=\"px-1\">:</span>\n                <div class=\"flex-grow-1\">\n                    <input type=\"number\" [min]=\"0\" [max]=\"59\" (input)=\"setNumber($event, 59, null)\" bsEnhancedPaste [ngModel]=\"minutes | number: '2.0'\" (ngModelChange)=\"minutes = $event\"  (focus)=\"selectAll(minuteBox)\" (blur)=\"isFocused = false\" #minuteBox class=\"w-100 border-0 bg-transparent no-form-control\">\n                </div>\n            </span>\n            <button [color]=\"colors.secondary\" (click)=\"isOpen = !isOpen\">\n                <bs-icon [icon]=\"'clock'\"></bs-icon>\n            </button>\n        </bs-input-group>\n    </bs-form>\n    <bs-has-overlay></bs-has-overlay>\n    <bs-dropdown-menu class=\"overflow-auto\" *bsDropdownMenu>\n        <bs-dropdown-item [isSelected]=\"timesEqual(selectedTime, timestamp)\" *ngFor=\"let timestamp of presetTimestamps\" (click)=\"setTime(timestamp)\">\n            {{ timestamp | date: 'HH:mm' }}\n        </bs-dropdown-item>\n    </bs-dropdown-menu>\n</div>", styles: [":host{display:inline-block}input::-webkit-outer-spin-button,input::-webkit-inner-spin-button{-webkit-appearance:none;margin:0}input[type=number]{-moz-appearance:textfield;outline:0px!important}.form-control{transition:border-color .15s ease-in-out,box-shadow .15s ease-in-out}.form-control.focus{color:#495057;background-color:#fff;border-color:#80bdff!important;outline:0;box-shadow:0 0 0 .2rem #007bff40}bs-dropdown-menu{max-height:250px}\n"] }]
        }], ctorParameters: function () { return [{ type: i0.ChangeDetectorRef }, { type: i0.NgZone }, { type: i0.Renderer2 }]; }, propDecorators: { selectedTimeChange: [{
                type: Output
            }], selectedTime: [{
                type: Input
            }] } });

class BsTimepickerModule {
}
BsTimepickerModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: BsTimepickerModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
BsTimepickerModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.2.7", ngImport: i0, type: BsTimepickerModule, declarations: [BsTimepickerComponent], imports: [CommonModule,
        FormsModule,
        EnhancedPasteModule,
        BsFormModule,
        BsIconModule,
        BsDropdownModule,
        BsDropdownMenuModule,
        BsInputGroupModule,
        BsButtonTypeModule,
        BsHasOverlayModule], exports: [BsTimepickerComponent] });
BsTimepickerModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: BsTimepickerModule, imports: [CommonModule,
        FormsModule,
        EnhancedPasteModule,
        BsFormModule,
        BsIconModule,
        BsDropdownModule,
        BsDropdownMenuModule,
        BsInputGroupModule,
        BsButtonTypeModule,
        BsHasOverlayModule] });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: BsTimepickerModule, decorators: [{
            type: NgModule,
            args: [{
                    declarations: [
                        BsTimepickerComponent
                    ],
                    imports: [
                        CommonModule,
                        FormsModule,
                        EnhancedPasteModule,
                        BsFormModule,
                        BsIconModule,
                        BsDropdownModule,
                        BsDropdownMenuModule,
                        BsInputGroupModule,
                        BsButtonTypeModule,
                        BsHasOverlayModule,
                    ],
                    exports: [
                        BsTimepickerComponent
                    ]
                }]
        }] });

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

export { BsTimepickerComponent, BsTimepickerModule };
//# sourceMappingURL=mintplayer-ng-bootstrap-timepicker.mjs.map
