import { SdLabelDefDirective } from '@sd-angular/core/common';
import { EventEmitter, Component, Input, ContentChild, Output, NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { FormControl, NgForm, Validators, FormsModule, ReactiveFormsModule } from '@angular/forms';
import { __classPrivateFieldSet, __classPrivateFieldGet } from 'tslib';
import { v4 } from 'uuid';
import { NgxMaterialTimepickerModule } from 'ngx-material-timepicker';

var _model, _name, _form;
class SdTime {
    constructor() {
        this.id = `I${v4()}`;
        this.isMobileOrTablet = false;
        _model.set(this, void 0);
        _name.set(this, v4());
        this.formControl = new FormControl();
        _form.set(this, void 0);
        this.isRequired = false;
        this.modelChange = new EventEmitter();
        this.sdChange = new EventEmitter();
        this.onTimeChanged = (val) => {
            __classPrivateFieldSet(this, _model, val);
            this.formControl.setValue(__classPrivateFieldGet(this, _model));
            this.modelChange.emit(__classPrivateFieldGet(this, _model));
            this.sdChange.emit(__classPrivateFieldGet(this, _model));
        };
    }
    set name(val) {
        if (val) {
            __classPrivateFieldSet(this, _name, val);
        }
    }
    set _min(val) {
        if (Date.isDate(val)) {
            this.min = new Date(val);
        }
        else {
            this.min = null;
        }
    }
    set _max(val) {
        if (Date.isDate(val)) {
            this.max = new Date(val);
        }
        else {
            this.max = null;
        }
    }
    set form(val) {
        if (val) {
            if (val instanceof NgForm) {
                __classPrivateFieldSet(this, _form, val.form);
            }
            else {
                __classPrivateFieldSet(this, _form, val);
            }
        }
    }
    set disabled(val) {
        val = (val === '') || val;
        if (val) {
            this.formControl.disable();
        }
        else {
            this.formControl.enable();
        }
    }
    set required(val) {
        this.isRequired = (val === '') || val;
        if (this.isRequired) {
            this.formControl.setValidators([Validators.required]);
        }
        else {
            this.formControl.clearValidators();
        }
    }
    set model(val) {
        if (__classPrivateFieldGet(this, _model) !== val) {
            __classPrivateFieldSet(this, _model, val);
            this.formControl.setValue(val);
        }
    }
    ngOnDestroy() {
        var _a;
        (_a = __classPrivateFieldGet(this, _form)) === null || _a === void 0 ? void 0 : _a.removeControl(__classPrivateFieldGet(this, _name));
    }
    ngOnInit() {
        var _a;
        (_a = __classPrivateFieldGet(this, _form)) === null || _a === void 0 ? void 0 : _a.addControl(__classPrivateFieldGet(this, _name), this.formControl);
    }
    ngAfterViewInit() {
    }
}
_model = new WeakMap(), _name = new WeakMap(), _form = new WeakMap();
SdTime.decorators = [
    { type: Component, args: [{
                selector: 'sd-time',
                template: "<label *ngIf=\"label&&!sdLabelDef?.templateRef\" class=\"d-block T14M\">{{label}} <span class=\"text-danger mb-2\" *ngIf=\"required\">*</span></label>\r\n<ng-container *ngIf=\"sdLabelDef?.templateRef\" matSuffix>\r\n  <ng-container *ngTemplateOutlet=\"sdLabelDef.templateRef\">\r\n  </ng-container>\r\n</ng-container>\r\n<ngx-timepicker-field [ngModel]=\"formControl?.value\" [format]=\"24\" (timeChanged)=\"onTimeChanged($event)\"\r\n  [min]=\"min\" [max]=\"max\" [disabled]=\"formControl?.disabled\" controlOnly></ngx-timepicker-field>"
            },] }
];
SdTime.ctorParameters = () => [];
SdTime.propDecorators = {
    name: [{ type: Input }],
    _min: [{ type: Input, args: ['min',] }],
    _max: [{ type: Input, args: ['max',] }],
    size: [{ type: Input }],
    form: [{ type: Input }],
    disabled: [{ type: Input }],
    required: [{ type: Input }],
    label: [{ type: Input }],
    defaultTime: [{ type: Input }],
    model: [{ type: Input }],
    sdLabelDef: [{ type: ContentChild, args: [SdLabelDefDirective,] }],
    modelChange: [{ type: Output }],
    sdChange: [{ type: Output }]
};

class SdTimeModule {
}
SdTimeModule.decorators = [
    { type: NgModule, args: [{
                imports: [
                    CommonModule,
                    FormsModule,
                    ReactiveFormsModule,
                    NgxMaterialTimepickerModule
                ],
                declarations: [
                    SdTime
                ],
                exports: [
                    SdTime
                ],
                providers: []
            },] }
];

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

export { SdTimeModule, SdTime as ɵa };
//# sourceMappingURL=sd-angular-core-time.js.map
