import { Component, forwardRef, Input, ViewChild, } from '@angular/core';
import { NG_VALUE_ACCESSOR } from '@angular/forms';
import { EvoBaseControl } from '../../common/evo-base-control';
import { Subject } from 'rxjs';
import { tap } from 'rxjs/operators';
import * as i0 from "@angular/core";
import * as i1 from "../evo-control-error/evo-control-error.component";
import * as i2 from "../../directives/evo-ui-class.directive";
import * as i3 from "@angular/forms";
import * as i4 from "@angular/common";
export class EvoSelectComponent extends EvoBaseControl {
    constructor() {
        super(...arguments);
        this.style = 'input';
        this.disabled = false;
        this.contentChanges$ = new Subject();
        this.propagateChange = (_) => { };
    }
    set selectedValue(value) {
        this._selectedValue = value;
        [].slice.call(this.select.nativeElement.options).some((option, index) => {
            if (option && option.value === value) {
                this.selectedLabel = option.innerText;
                return true;
            }
            return false;
        });
    }
    get selectedValue() {
        return this._selectedValue;
    }
    ngAfterContentInit() {
        if (!this.selectedValue) {
            const selectOptions = this.select.nativeElement.options;
            this.selectedValue = selectOptions && selectOptions.length > 0 ? selectOptions[0].value : undefined;
        }
        else {
            this.setLabel();
        }
        this.contentChangesSubscription = this.contentChanges$.pipe(tap(() => this.setLabel())).subscribe();
    }
    ngAfterContentChecked() {
        this.contentChanges$.next();
    }
    ngOnDestroy() {
        this.contentChangesSubscription.unsubscribe();
    }
    writeValue(value) {
        if (value !== undefined) {
            this.selectedValue = value;
        }
    }
    registerOnChange(fn) {
        this.propagateChange = fn;
    }
    registerOnTouched() { }
    getSelectClasses() {
        return {
            [this.style]: true,
            [this.theme]: this.theme,
            disabled: this.disabled,
            invalid: this.currentState.invalid,
            valid: this.currentState.valid,
        };
    }
    onChange(newValue) {
        this.propagateChange(newValue);
    }
    setDisabledState(isDisabled) {
        this.disabled = isDisabled;
    }
    get currentState() {
        return Object.assign({
            valid: this.control ? this.control.dirty && this.control.valid : undefined,
            invalid: this.control ? this.control.dirty && this.control.invalid : undefined,
        }, this.state);
    }
    setLabel() {
        const optionsArray = [].slice.call(this.select.nativeElement.options);
        const selectedIndex = optionsArray.findIndex((option) => option.value === this.selectedValue);
        if (selectedIndex >= 0) {
            const selectedOption = optionsArray[selectedIndex];
            this.selectedLabel = selectedOption.innerText;
            this.select.nativeElement.selectedIndex = selectedIndex;
        }
    }
}
EvoSelectComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.4.0", ngImport: i0, type: EvoSelectComponent, deps: null, target: i0.ɵɵFactoryTarget.Component });
EvoSelectComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "13.4.0", type: EvoSelectComponent, selector: "evo-select", inputs: { style: "style", label: "label", theme: "theme" }, providers: [
        {
            provide: NG_VALUE_ACCESSOR,
            useExisting: forwardRef(() => EvoSelectComponent),
            multi: true,
        },
    ], viewQueries: [{ propertyName: "select", first: true, predicate: ["select"], descendants: true, static: true }], usesInheritance: true, ngImport: i0, template: "<label class=\"evo-select\" [evoUiClass]=\"getSelectClasses()\">\n    <div class=\"evo-select__field\" [evoUiClass]=\"getSelectClasses()\">{{selectedLabel}}</div>\n    <select #select class=\"evo-select__native\" [disabled]=\"disabled\" [(ngModel)]=\"selectedValue\" (ngModelChange)=\"onChange($event)\">\n        <ng-content></ng-content>\n    </select>\n    <span class=\"evo-select__icon-arrow\">\n        <svg width=\"7\" height=\"5\" viewBox=\"0 0 7 5\" xmlns=\"http://www.w3.org/2000/svg\">\n            <path fill-rule=\"evenodd\" clip-rule=\"evenodd\" d=\"M0 0H7L3.44199 5L0 0Z\" />\n        </svg>\n    </span>\n</label>\n<evo-control-error *ngIf=\"showErrors\"\n    [errors]=\"control.errors\"\n    [errorsMessages]=\"errorsMessages\"></evo-control-error>\n", styles: [":host{position:relative;display:inline-block}.evo-select{position:relative;display:flex;align-items:center}.evo-select:after{content:\"\";position:absolute;pointer-events:none}.evo-select_input{height:48px}.evo-select_input:after{right:20px;width:8px;height:12px;background:url(\"data:image/svg+xml,%3Csvg width%3D%228%22 height%3D%2212%22 viewBox%3D%220 0 8 12%22 fill%3D%22none%22 xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Cpath fill-rule%3D%22evenodd%22 clip-rule%3D%22evenodd%22 d%3D%22M0 0H8L3.93371 3.99997L0 0Z%22 transform%3D%22translate(0 8)%22 fill%3D%22%23212121%22%2F%3E%3Cpath fill-rule%3D%22evenodd%22 clip-rule%3D%22evenodd%22 d%3D%22M0 0H8L3.93371 3.99997L0 0Z%22 transform%3D%22translate(0 4) scale(1 -1)%22 fill%3D%22%23212121%22%2F%3E%3C%2Fsvg%3E\");background-repeat:no-repeat;background-position:center}.evo-select_disabled{pointer-events:none}.evo-select_disabled:after{opacity:.4}.evo-select_inline .evo-select__icon-arrow{display:flex;margin-left:10px}.evo-select_inline .evo-select__icon-arrow svg{fill:#212121}.evo-select_inline.evo-select_disabled .evo-select__icon-arrow svg{fill:#9b9b9b}.evo-select__icon-arrow{display:none}.evo-select__native{position:absolute;top:0;left:0;z-index:10;display:block;width:100%;height:100%;cursor:pointer;opacity:0;appearance:none}.evo-select__field{width:100%;height:100%}.evo-select__field_input{display:inline-block;padding:10px 38px 10px 20px;overflow:hidden;line-height:26px;text-overflow:ellipsis;--evo-input-height: 40px;--evo-input-border-radius: 4px;--evo-input-font-size: 14px;--evo-input-line-height: 24px;display:flex;align-items:center;height:var(--evo-input-height);color:#212121;font-weight:400;font-size:var(--evo-input-font-size);font-family:var(--evo-font);line-height:var(--evo-input-line-height);white-space:nowrap;background-color:#fff;border:1px solid #C6C6C6;border-radius:var(--evo-input-border-radius);outline:none;transition:color .3s,box-shadow .3s,background .3s,border .3s}.evo-select__field_input:hover{border:1px solid #9B9B9B}.evo-select__field_input{display:inline-block}.evo-select__field_valid{border-color:#21c68b}.evo-select__field_invalid{border-color:#ff1817}.evo-select__field_disabled{color:#9b9b9b;background:#F4F6F8}.evo-select__field_inline{font-weight:600;background:transparent}.evo-select__field_inline.evo-select__field_disabled{background:transparent}.evo-select_simple .evo-select__field_input{height:auto;padding:0 30px 0 0;font-weight:600;line-height:1;background:transparent;border:none}.evo-select_simple .evo-select_input,.evo-select_input.evo-select_simple{height:auto}.evo-select_input.evo-select_simple:after{top:-2px;right:0;width:24px;height:24px;background:url(\"data:image/svg+xml,%3Csvg xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22 width%3D%2224%22 height%3D%2224%22 viewBox%3D%220 0 24 24%22 fill%3D%22none%22%3E    %3Cmask id%3D%22mask0%22 mask-type%3D%22alpha%22 maskUnits%3D%22userSpaceOnUse%22 x%3D%228%22 y%3D%2210%22 width%3D%228%22 height%3D%225%22%3E        %3Cpath d%3D%22M8.81066 10C8.14248 10 7.80786 10.8079 8.28033 11.2803L11.4697 14.4697C11.7626 14.7626 12.2374 14.7626 12.5303 14.4697L15.7197 11.2803C16.1921 10.8079 15.8575 10 15.1893 10H8.81066Z%22 fill%3D%22black%22%2F%3E    %3C%2Fmask%3E    %3Cg mask%3D%22url(%23mask0)%22%3E        %3Crect width%3D%2224%22 height%3D%2224%22 fill%3D%22%23212121%22%2F%3E    %3C%2Fg%3E%3C%2Fsvg%3E\")}\n"], components: [{ type: i1.EvoControlErrorComponent, selector: "evo-control-error", inputs: ["errors", "errorsMessages", "showCount"] }], directives: [{ type: i2.EvoUiClassDirective, selector: "[evoUiClass]", inputs: ["class", "evoUiClass"] }, { type: i3.SelectControlValueAccessor, selector: "select:not([multiple])[formControlName],select:not([multiple])[formControl],select:not([multiple])[ngModel]", inputs: ["compareWith"] }, { type: i3.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { type: i3.NgModel, selector: "[ngModel]:not([formControlName]):not([formControl])", inputs: ["name", "disabled", "ngModel", "ngModelOptions"], outputs: ["ngModelChange"], exportAs: ["ngModel"] }, { type: i4.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }] });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.4.0", ngImport: i0, type: EvoSelectComponent, decorators: [{
            type: Component,
            args: [{ selector: 'evo-select', providers: [
                        {
                            provide: NG_VALUE_ACCESSOR,
                            useExisting: forwardRef(() => EvoSelectComponent),
                            multi: true,
                        },
                    ], template: "<label class=\"evo-select\" [evoUiClass]=\"getSelectClasses()\">\n    <div class=\"evo-select__field\" [evoUiClass]=\"getSelectClasses()\">{{selectedLabel}}</div>\n    <select #select class=\"evo-select__native\" [disabled]=\"disabled\" [(ngModel)]=\"selectedValue\" (ngModelChange)=\"onChange($event)\">\n        <ng-content></ng-content>\n    </select>\n    <span class=\"evo-select__icon-arrow\">\n        <svg width=\"7\" height=\"5\" viewBox=\"0 0 7 5\" xmlns=\"http://www.w3.org/2000/svg\">\n            <path fill-rule=\"evenodd\" clip-rule=\"evenodd\" d=\"M0 0H7L3.44199 5L0 0Z\" />\n        </svg>\n    </span>\n</label>\n<evo-control-error *ngIf=\"showErrors\"\n    [errors]=\"control.errors\"\n    [errorsMessages]=\"errorsMessages\"></evo-control-error>\n", styles: [":host{position:relative;display:inline-block}.evo-select{position:relative;display:flex;align-items:center}.evo-select:after{content:\"\";position:absolute;pointer-events:none}.evo-select_input{height:48px}.evo-select_input:after{right:20px;width:8px;height:12px;background:url(\"data:image/svg+xml,%3Csvg width%3D%228%22 height%3D%2212%22 viewBox%3D%220 0 8 12%22 fill%3D%22none%22 xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Cpath fill-rule%3D%22evenodd%22 clip-rule%3D%22evenodd%22 d%3D%22M0 0H8L3.93371 3.99997L0 0Z%22 transform%3D%22translate(0 8)%22 fill%3D%22%23212121%22%2F%3E%3Cpath fill-rule%3D%22evenodd%22 clip-rule%3D%22evenodd%22 d%3D%22M0 0H8L3.93371 3.99997L0 0Z%22 transform%3D%22translate(0 4) scale(1 -1)%22 fill%3D%22%23212121%22%2F%3E%3C%2Fsvg%3E\");background-repeat:no-repeat;background-position:center}.evo-select_disabled{pointer-events:none}.evo-select_disabled:after{opacity:.4}.evo-select_inline .evo-select__icon-arrow{display:flex;margin-left:10px}.evo-select_inline .evo-select__icon-arrow svg{fill:#212121}.evo-select_inline.evo-select_disabled .evo-select__icon-arrow svg{fill:#9b9b9b}.evo-select__icon-arrow{display:none}.evo-select__native{position:absolute;top:0;left:0;z-index:10;display:block;width:100%;height:100%;cursor:pointer;opacity:0;appearance:none}.evo-select__field{width:100%;height:100%}.evo-select__field_input{display:inline-block;padding:10px 38px 10px 20px;overflow:hidden;line-height:26px;text-overflow:ellipsis;--evo-input-height: 40px;--evo-input-border-radius: 4px;--evo-input-font-size: 14px;--evo-input-line-height: 24px;display:flex;align-items:center;height:var(--evo-input-height);color:#212121;font-weight:400;font-size:var(--evo-input-font-size);font-family:var(--evo-font);line-height:var(--evo-input-line-height);white-space:nowrap;background-color:#fff;border:1px solid #C6C6C6;border-radius:var(--evo-input-border-radius);outline:none;transition:color .3s,box-shadow .3s,background .3s,border .3s}.evo-select__field_input:hover{border:1px solid #9B9B9B}.evo-select__field_input{display:inline-block}.evo-select__field_valid{border-color:#21c68b}.evo-select__field_invalid{border-color:#ff1817}.evo-select__field_disabled{color:#9b9b9b;background:#F4F6F8}.evo-select__field_inline{font-weight:600;background:transparent}.evo-select__field_inline.evo-select__field_disabled{background:transparent}.evo-select_simple .evo-select__field_input{height:auto;padding:0 30px 0 0;font-weight:600;line-height:1;background:transparent;border:none}.evo-select_simple .evo-select_input,.evo-select_input.evo-select_simple{height:auto}.evo-select_input.evo-select_simple:after{top:-2px;right:0;width:24px;height:24px;background:url(\"data:image/svg+xml,%3Csvg xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22 width%3D%2224%22 height%3D%2224%22 viewBox%3D%220 0 24 24%22 fill%3D%22none%22%3E    %3Cmask id%3D%22mask0%22 mask-type%3D%22alpha%22 maskUnits%3D%22userSpaceOnUse%22 x%3D%228%22 y%3D%2210%22 width%3D%228%22 height%3D%225%22%3E        %3Cpath d%3D%22M8.81066 10C8.14248 10 7.80786 10.8079 8.28033 11.2803L11.4697 14.4697C11.7626 14.7626 12.2374 14.7626 12.5303 14.4697L15.7197 11.2803C16.1921 10.8079 15.8575 10 15.1893 10H8.81066Z%22 fill%3D%22black%22%2F%3E    %3C%2Fmask%3E    %3Cg mask%3D%22url(%23mask0)%22%3E        %3Crect width%3D%2224%22 height%3D%2224%22 fill%3D%22%23212121%22%2F%3E    %3C%2Fg%3E%3C%2Fsvg%3E\")}\n"] }]
        }], propDecorators: { style: [{
                type: Input
            }], label: [{
                type: Input
            }], theme: [{
                type: Input
            }], select: [{
                type: ViewChild,
                args: ['select', { static: true }]
            }] } });
//# sourceMappingURL=data:application/json;base64, 