import { Component, forwardRef, Input } from '@angular/core';
import { NG_VALUE_ACCESSOR } from '@angular/forms';
import { EvoBaseControl } from '../../common/evo-base-control';
import * as i0 from "@angular/core";
import * as i1 from "@angular/forms";
import * as i2 from "../../directives/evo-ui-class.directive";
import * as i3 from "@angular/common";
export * from './typings/options';
export var EvoRadioGroupThemes;
(function (EvoRadioGroupThemes) {
    EvoRadioGroupThemes["light"] = "light";
    EvoRadioGroupThemes["segment"] = "segment";
})(EvoRadioGroupThemes || (EvoRadioGroupThemes = {}));
export var EvoRadioGroupDirections;
(function (EvoRadioGroupDirections) {
    EvoRadioGroupDirections["row"] = "row";
    EvoRadioGroupDirections["column"] = "column";
})(EvoRadioGroupDirections || (EvoRadioGroupDirections = {}));
export class EvoRadioGroupComponent extends EvoBaseControl {
    constructor(formBuilder, injector) {
        super(injector);
        this.formBuilder = formBuilder;
        this.injector = injector;
        this.disabled = false;
        this.onChange = (_) => { };
        this.onTouched = () => { };
    }
    get value() {
        return this._value;
    }
    set value(value) {
        this._value = value;
        this.onChange(value);
    }
    ngOnInit() {
        this.createFormGroup();
    }
    writeValue(value) {
        this.value = value;
    }
    registerOnChange(fn) {
        this.onChange = fn;
    }
    registerOnTouched(fn) {
        this.onTouched = fn;
    }
    setDisabledState(state) {
        this.disabled = state;
    }
    /**
     * Обработчик на смену значения
     * @param value значение
     */
    onChangedValue(value) {
        this.value = value;
    }
    /**
    * Геттер на возможные варианты отчета в формате массива
    * презентационного текста для радио группа
    */
    get optionArray() {
        return this.generateOptionArray(this.options);
    }
    get totalClasses() {
        const classes = [];
        if (this.theme) {
            classes.push(this.theme);
        }
        if (this.direction) {
            classes.push(this.direction);
        }
        return classes;
    }
    /**
    * Генерирует из опций массив
    * @param source объект с вариантами
    */
    generateOptionArray(source) {
        const array = [];
        for (const key in source) {
            if (source.hasOwnProperty(key)) {
                array.push(source[key]);
            }
        }
        return array;
    }
    /**
    * Создание группы
    */
    createFormGroup() {
        this.formGroup = this.formBuilder.group({
            value: [this.value],
        });
    }
}
EvoRadioGroupComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.4.0", ngImport: i0, type: EvoRadioGroupComponent, deps: [{ token: i1.FormBuilder }, { token: i0.Injector }], target: i0.ɵɵFactoryTarget.Component });
EvoRadioGroupComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "13.4.0", type: EvoRadioGroupComponent, selector: "evo-radio-group", inputs: { options: "options", _value: ["value", "_value"], theme: "theme", direction: "direction" }, providers: [
        {
            provide: NG_VALUE_ACCESSOR,
            useExisting: forwardRef(() => EvoRadioGroupComponent),
            multi: true,
        },
    ], usesInheritance: true, ngImport: i0, template: "<div class=\"evo-radio-group\" [evoUiClass]=\"totalClasses\" [formGroup]=\"formGroup\">\n    <label class=\"evo-radio-group__radio\" *ngFor=\"let option of optionArray\">\n        <!-- \u041F\u0435\u0440\u0435\u043A\u043B\u044E\u0447\u0435\u043D\u0438\u0435 \u0441\u0442\u0438\u043B\u0435\u0439 \u0432\u044B\u043F\u043E\u043B\u043D\u044F\u0435\u0442\u0441\u044F \u0441 \u043F\u043E\u043C\u043E\u0449\u044C\u044E \u043F\u0441\u0435\u0432\u0434\u043E\u0441\u0435\u043B\u0435\u043A\u0442\u043E\u0440\u0430 :checked -->\n        <input class=\"evo-radio-group__radio-control\" (ngModelChange) = \"onChangedValue($event)\" formControlName=\"value\" type=\"radio\" value={{option.value}}>\n        <div class=\"evo-radio-group__radio-view\">\n            <span class=\"evo-radio-group__radio-icon\"></span>\n            <span class=\"evo-radio-group__radio-value\">{{option.presentationText}}</span>\n        </div>\n    </label>\n</div>\n", styles: [":host{display:block}.evo-radio-group{display:flex;flex-wrap:wrap}.evo-radio-group__radio{flex:1;margin-right:30px;cursor:pointer}.evo-radio-group__radio:last-child{margin-right:0}.evo-radio-group__radio-control{display:none}.evo-radio-group__radio-control:checked+.evo-radio-group__radio-view{background-color:#4568a50d;border-color:#0986e2}.evo-radio-group__radio-control:checked+.evo-radio-group__radio-view .evo-radio-group__radio-icon:before{display:block}.evo-radio-group__radio-view{display:flex;align-items:center;padding:20px;border:1px solid #C6C6C6;border-radius:8px}.evo-radio-group__radio-icon{position:relative;display:inline-block;flex-shrink:0;width:20px;height:20px;margin-right:20px;background-color:#fff;border:2px solid #C6C6C6;border-radius:50%}.evo-radio-group__radio-icon:before{position:absolute;top:50%;left:50%;display:none;box-sizing:border-box;width:10px;height:10px;content:\"\";margin-top:-5px;margin-left:-5px;background-color:#0986e2;border-radius:50%}.evo-radio-group__radio-value{color:#000;font-weight:600;font-size:18px}.evo-radio-group_light .evo-radio-group__radio{flex:initial}.evo-radio-group_light .evo-radio-group__radio-view{padding:0;background:none;border:none}.evo-radio-group_light .evo-radio-group__radio-value{font-size:14px}.evo-radio-group_light .evo-radio-group__radio-control:checked+.evo-radio-group__radio-view{background:none}.evo-radio-group_segment .evo-radio-group__radio{flex:initial;margin-right:16px;margin-bottom:16px}.evo-radio-group_segment .evo-radio-group__radio-icon{display:none}.evo-radio-group_segment .evo-radio-group__radio-view{padding:8px 12px;background-color:#f4f6f8;border:none;border-radius:16px}.evo-radio-group_segment .evo-radio-group__radio-value{color:#0986e2;font-size:14px;line-height:1}.evo-radio-group_segment .evo-radio-group__radio-control:checked+.evo-radio-group__radio-view{background-color:#0986e2}.evo-radio-group_segment .evo-radio-group__radio-control:checked+.evo-radio-group__radio-view .evo-radio-group__radio-value{color:#fff}.evo-radio-group_column{flex-direction:column}.evo-radio-group_column .evo-radio-group__radio{margin-top:20px;margin-right:0}.evo-radio-group_column .evo-radio-group__radio:first-child{margin-top:0}\n"], directives: [{ type: i2.EvoUiClassDirective, selector: "[evoUiClass]", inputs: ["class", "evoUiClass"] }, { type: i1.NgControlStatusGroup, selector: "[formGroupName],[formArrayName],[ngModelGroup],[formGroup],form:not([ngNoForm]),[ngForm]" }, { type: i1.FormGroupDirective, selector: "[formGroup]", inputs: ["formGroup"], outputs: ["ngSubmit"], exportAs: ["ngForm"] }, { type: i3.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { type: i1.DefaultValueAccessor, selector: "input:not([type=checkbox])[formControlName],textarea[formControlName],input:not([type=checkbox])[formControl],textarea[formControl],input:not([type=checkbox])[ngModel],textarea[ngModel],[ngDefaultControl]" }, { type: i1.RadioControlValueAccessor, selector: "input[type=radio][formControlName],input[type=radio][formControl],input[type=radio][ngModel]", inputs: ["name", "formControlName", "value"] }, { type: i1.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { type: i1.FormControlName, selector: "[formControlName]", inputs: ["formControlName", "disabled", "ngModel"], outputs: ["ngModelChange"] }] });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.4.0", ngImport: i0, type: EvoRadioGroupComponent, decorators: [{
            type: Component,
            args: [{ selector: 'evo-radio-group', providers: [
                        {
                            provide: NG_VALUE_ACCESSOR,
                            useExisting: forwardRef(() => EvoRadioGroupComponent),
                            multi: true,
                        },
                    ], template: "<div class=\"evo-radio-group\" [evoUiClass]=\"totalClasses\" [formGroup]=\"formGroup\">\n    <label class=\"evo-radio-group__radio\" *ngFor=\"let option of optionArray\">\n        <!-- \u041F\u0435\u0440\u0435\u043A\u043B\u044E\u0447\u0435\u043D\u0438\u0435 \u0441\u0442\u0438\u043B\u0435\u0439 \u0432\u044B\u043F\u043E\u043B\u043D\u044F\u0435\u0442\u0441\u044F \u0441 \u043F\u043E\u043C\u043E\u0449\u044C\u044E \u043F\u0441\u0435\u0432\u0434\u043E\u0441\u0435\u043B\u0435\u043A\u0442\u043E\u0440\u0430 :checked -->\n        <input class=\"evo-radio-group__radio-control\" (ngModelChange) = \"onChangedValue($event)\" formControlName=\"value\" type=\"radio\" value={{option.value}}>\n        <div class=\"evo-radio-group__radio-view\">\n            <span class=\"evo-radio-group__radio-icon\"></span>\n            <span class=\"evo-radio-group__radio-value\">{{option.presentationText}}</span>\n        </div>\n    </label>\n</div>\n", styles: [":host{display:block}.evo-radio-group{display:flex;flex-wrap:wrap}.evo-radio-group__radio{flex:1;margin-right:30px;cursor:pointer}.evo-radio-group__radio:last-child{margin-right:0}.evo-radio-group__radio-control{display:none}.evo-radio-group__radio-control:checked+.evo-radio-group__radio-view{background-color:#4568a50d;border-color:#0986e2}.evo-radio-group__radio-control:checked+.evo-radio-group__radio-view .evo-radio-group__radio-icon:before{display:block}.evo-radio-group__radio-view{display:flex;align-items:center;padding:20px;border:1px solid #C6C6C6;border-radius:8px}.evo-radio-group__radio-icon{position:relative;display:inline-block;flex-shrink:0;width:20px;height:20px;margin-right:20px;background-color:#fff;border:2px solid #C6C6C6;border-radius:50%}.evo-radio-group__radio-icon:before{position:absolute;top:50%;left:50%;display:none;box-sizing:border-box;width:10px;height:10px;content:\"\";margin-top:-5px;margin-left:-5px;background-color:#0986e2;border-radius:50%}.evo-radio-group__radio-value{color:#000;font-weight:600;font-size:18px}.evo-radio-group_light .evo-radio-group__radio{flex:initial}.evo-radio-group_light .evo-radio-group__radio-view{padding:0;background:none;border:none}.evo-radio-group_light .evo-radio-group__radio-value{font-size:14px}.evo-radio-group_light .evo-radio-group__radio-control:checked+.evo-radio-group__radio-view{background:none}.evo-radio-group_segment .evo-radio-group__radio{flex:initial;margin-right:16px;margin-bottom:16px}.evo-radio-group_segment .evo-radio-group__radio-icon{display:none}.evo-radio-group_segment .evo-radio-group__radio-view{padding:8px 12px;background-color:#f4f6f8;border:none;border-radius:16px}.evo-radio-group_segment .evo-radio-group__radio-value{color:#0986e2;font-size:14px;line-height:1}.evo-radio-group_segment .evo-radio-group__radio-control:checked+.evo-radio-group__radio-view{background-color:#0986e2}.evo-radio-group_segment .evo-radio-group__radio-control:checked+.evo-radio-group__radio-view .evo-radio-group__radio-value{color:#fff}.evo-radio-group_column{flex-direction:column}.evo-radio-group_column .evo-radio-group__radio{margin-top:20px;margin-right:0}.evo-radio-group_column .evo-radio-group__radio:first-child{margin-top:0}\n"] }]
        }], ctorParameters: function () { return [{ type: i1.FormBuilder }, { type: i0.Injector }]; }, propDecorators: { options: [{
                type: Input
            }], _value: [{
                type: Input,
                args: ['value']
            }], theme: [{
                type: Input
            }], direction: [{
                type: Input
            }] } });
//# sourceMappingURL=data:application/json;base64, 