import { Component, Inject, Input, Optional, ViewChild } from '@angular/core';
import { NG_ASYNC_VALIDATORS, NG_VALIDATORS, NG_VALUE_ACCESSOR, NgModel } from '@angular/forms';
import { ElementBase } from '../../base/element-base';
import { INPUT_FORMS_CONFIG } from '../../input-forms-config.constants';
import * as i0 from "@angular/core";
import * as i1 from "@angular/common";
import * as i2 from "@angular/forms";
import * as i3 from "ngx-bootstrap/tooltip";
import * as i4 from "../input-validations/input-validations.component";
let identifier = 0;
export class InputSelectComponent extends ElementBase {
    constructor(validators, asyncValidators, config) {
        super(validators, asyncValidators, config);
        this.config = config;
        this.identifier = `input-select-${identifier++}`;
    }
    ngOnInit() {
        setTimeout(() => {
            this.handleInitialValue();
        });
    }
    ngDoCheck() {
        this.handleInitialValue();
    }
    getOptionDisplayText(option) {
        const prop = this.displayTextProperty || 'displayText';
        return option[prop];
    }
    getOptionValue(option) {
        const prop = this.valueProperty || 'value';
        return option[prop];
    }
    handleInitialValue() {
        if (this.value != undefined && this.value != null) {
            this.value = this.value.toString();
        }
        else {
            this.writeValue('');
        }
    }
}
InputSelectComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: InputSelectComponent, deps: [{ token: NG_VALIDATORS, optional: true }, { token: NG_ASYNC_VALIDATORS, optional: true }, { token: INPUT_FORMS_CONFIG }], target: i0.ɵɵFactoryTarget.Component });
InputSelectComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.2.10", type: InputSelectComponent, selector: "input-select", inputs: { displayTextProperty: "displayTextProperty", valueProperty: "valueProperty", defaultOption: "defaultOption", options: "options" }, providers: [{
            provide: NG_VALUE_ACCESSOR,
            useExisting: InputSelectComponent,
            multi: true
        }], viewQueries: [{ propertyName: "model", first: true, predicate: NgModel, descendants: true, static: true }], usesInheritance: true, ngImport: i0, template: "<label *ngIf=\"label\" [attr.for]=\"identifier\">\n  {{label}}\n  <span class=\"required-symbol\" *ngIf=\"isRequired\"> *</span>\n  <i class=\"fa fa-question-circle ml-2\" tooltip=\"{{help}}\" container=\"body\" *ngIf=\"help\"></i>\n</label>\n\n<select class=\"form-control\" \n  [(ngModel)]=\"value\"\n  [id]=\"identifier\" \n  [disabled]=\"disabled\" \n  [ngClass]=\"{\n    'is-valid': showValidations && !disabled && touched && !(invalid | async),\n    'is-invalid': showValidations && !disabled && touched && (invalid | async)\n  }\">\n  <option value=\"\" *ngIf=\"defaultOption\">{{defaultOption}}</option>\n  <option [value]=\"getOptionValue(option)\" *ngFor=\"let option of options\">{{getOptionDisplayText(option)}}</option>\n  <ng-content></ng-content>\n</select>\n\n<small class=\"text-muted\" *ngIf=\"description\">{{description}}</small>\n\n<input-validations\n  *ngIf=\"showValidations && !disabled && touched && (invalid | async)\"\n  [messages]=\"failures | async\">\n</input-validations>\n", styles: [".form-control.is-invalid,.was-validated .form-control:invalid,.form-control.is-valid,.was-validated .form-control:valid{background-position:center right calc(.875em + .1875rem)}\n"], dependencies: [{ kind: "directive", type: i1.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "directive", type: i1.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { kind: "directive", type: i1.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: i2.NgSelectOption, selector: "option", inputs: ["ngValue", "value"] }, { kind: "directive", type: i2.ɵNgSelectMultipleOption, selector: "option", inputs: ["ngValue", "value"] }, { kind: "directive", type: i2.SelectControlValueAccessor, selector: "select:not([multiple])[formControlName],select:not([multiple])[formControl],select:not([multiple])[ngModel]", inputs: ["compareWith"] }, { kind: "directive", type: i2.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i2.NgModel, selector: "[ngModel]:not([formControlName]):not([formControl])", inputs: ["name", "disabled", "ngModel", "ngModelOptions"], outputs: ["ngModelChange"], exportAs: ["ngModel"] }, { kind: "directive", type: i3.TooltipDirective, selector: "[tooltip], [tooltipHtml]", inputs: ["containerClass", "tooltipAnimation", "tooltipFadeDuration", "isOpen", "tooltipHtml", "tooltip", "tooltipPlacement", "placement", "tooltipIsOpen", "tooltipEnable", "isDisabled", "tooltipAppendToBody", "container", "tooltipClass", "tooltipContext", "tooltipPopupDelay", "delay", "tooltipTrigger", "triggers", "adaptivePosition"], outputs: ["tooltipChange", "tooltipStateChanged", "onShown", "onHidden"], exportAs: ["bs-tooltip"] }, { kind: "component", type: i4.InputValidationsComponent, selector: "input-validations", inputs: ["messages"] }, { kind: "pipe", type: i1.AsyncPipe, name: "async" }] });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: InputSelectComponent, decorators: [{
            type: Component,
            args: [{ selector: 'input-select', providers: [{
                            provide: NG_VALUE_ACCESSOR,
                            useExisting: InputSelectComponent,
                            multi: true
                        }], template: "<label *ngIf=\"label\" [attr.for]=\"identifier\">\n  {{label}}\n  <span class=\"required-symbol\" *ngIf=\"isRequired\"> *</span>\n  <i class=\"fa fa-question-circle ml-2\" tooltip=\"{{help}}\" container=\"body\" *ngIf=\"help\"></i>\n</label>\n\n<select class=\"form-control\" \n  [(ngModel)]=\"value\"\n  [id]=\"identifier\" \n  [disabled]=\"disabled\" \n  [ngClass]=\"{\n    'is-valid': showValidations && !disabled && touched && !(invalid | async),\n    'is-invalid': showValidations && !disabled && touched && (invalid | async)\n  }\">\n  <option value=\"\" *ngIf=\"defaultOption\">{{defaultOption}}</option>\n  <option [value]=\"getOptionValue(option)\" *ngFor=\"let option of options\">{{getOptionDisplayText(option)}}</option>\n  <ng-content></ng-content>\n</select>\n\n<small class=\"text-muted\" *ngIf=\"description\">{{description}}</small>\n\n<input-validations\n  *ngIf=\"showValidations && !disabled && touched && (invalid | async)\"\n  [messages]=\"failures | async\">\n</input-validations>\n", styles: [".form-control.is-invalid,.was-validated .form-control:invalid,.form-control.is-valid,.was-validated .form-control:valid{background-position:center right calc(.875em + .1875rem)}\n"] }]
        }], ctorParameters: function () { return [{ type: Array, decorators: [{
                    type: Optional
                }, {
                    type: Inject,
                    args: [NG_VALIDATORS]
                }] }, { type: Array, decorators: [{
                    type: Optional
                }, {
                    type: Inject,
                    args: [NG_ASYNC_VALIDATORS]
                }] }, { type: undefined, decorators: [{
                    type: Inject,
                    args: [INPUT_FORMS_CONFIG]
                }] }]; }, propDecorators: { displayTextProperty: [{
                type: Input
            }], valueProperty: [{
                type: Input
            }], defaultOption: [{
                type: Input
            }], options: [{
                type: Input
            }], model: [{
                type: ViewChild,
                args: [NgModel, { static: true }]
            }] } });
//# sourceMappingURL=data:application/json;base64, 