import { ɵɵdefineDirective, ɵsetClassMetadata, Directive, ɵɵdefineInjectable, Injectable, ɵɵdirectiveInject, ChangeDetectorRef, ɵɵdefineComponent, ɵɵclassProp, ɵɵProvidersFeature, forwardRef, ɵɵNgOnChangesFeature, ɵɵprojectionDef, ɵɵprojection, Component, ViewEncapsulation, ChangeDetectionStrategy, Input, ElementRef, ɵɵviewQuery, ɵɵqueryRefresh, ɵɵloadQuery, ɵɵlistener, ɵɵelementStart, ɵɵelement, ɵɵelementEnd, ɵɵadvance, ɵɵproperty, ɵɵattribute, Optional, ViewChild, ɵɵdefineNgModule, ɵɵdefineInjector, ɵɵsetNgModuleScope, NgModule } from '@angular/core';
import { __decorate, __metadata } from 'tslib';
import { NG_VALUE_ACCESSOR, FormsModule } from '@angular/forms';
import { InputBoolean } from 'ng-zorro-antd/core';
import { ReplaySubject, Subject } from 'rxjs';
import { FocusMonitor } from '@angular/cdk/a11y';
import { takeUntil } from 'rxjs/operators';
import { CommonModule } from '@angular/common';

/**
 * @license
 * Copyright Alibaba.com All Rights Reserved.
 *
 * Use of this source code is governed by an MIT-style license that can be
 * found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE
 */
var NzRadioButtonDirective = /** @class */ (function () {
    function NzRadioButtonDirective() {
    }
    /** @nocollapse */ NzRadioButtonDirective.ɵfac = function NzRadioButtonDirective_Factory(t) { return new (t || NzRadioButtonDirective)(); };
    /** @nocollapse */ NzRadioButtonDirective.ɵdir = ɵɵdefineDirective({ type: NzRadioButtonDirective, selectors: [["", "nz-radio-button", ""]] });
    return NzRadioButtonDirective;
}());
/*@__PURE__*/ (function () { ɵsetClassMetadata(NzRadioButtonDirective, [{
        type: Directive,
        args: [{
                selector: '[nz-radio-button]'
            }]
    }], null, null); })();

/**
 * @license
 * Copyright Alibaba.com All Rights Reserved.
 *
 * Use of this source code is governed by an MIT-style license that can be
 * found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE
 */
var NzRadioService = /** @class */ (function () {
    function NzRadioService() {
        this.selected$ = new ReplaySubject(1);
        this.touched$ = new Subject();
        this.disabled$ = new ReplaySubject(1);
        this.name$ = new ReplaySubject(1);
    }
    NzRadioService.prototype.touch = function () {
        this.touched$.next();
    };
    NzRadioService.prototype.select = function (value) {
        this.selected$.next(value);
    };
    NzRadioService.prototype.setDisabled = function (value) {
        this.disabled$.next(value);
    };
    NzRadioService.prototype.setName = function (value) {
        this.name$.next(value);
    };
    /** @nocollapse */ NzRadioService.ɵfac = function NzRadioService_Factory(t) { return new (t || NzRadioService)(); };
    /** @nocollapse */ NzRadioService.ɵprov = ɵɵdefineInjectable({ token: NzRadioService, factory: NzRadioService.ɵfac });
    return NzRadioService;
}());
/*@__PURE__*/ (function () { ɵsetClassMetadata(NzRadioService, [{
        type: Injectable
    }], null, null); })();

var _c0 = ["*"];
var NzRadioGroupComponent = /** @class */ (function () {
    function NzRadioGroupComponent(cdr, nzRadioService) {
        this.cdr = cdr;
        this.nzRadioService = nzRadioService;
        this.value = null;
        this.destroy$ = new Subject();
        this.onChange = function () { };
        this.onTouched = function () { };
        this.nzDisabled = false;
        this.nzButtonStyle = 'outline';
        this.nzSize = 'default';
        this.nzName = null;
    }
    NzRadioGroupComponent.prototype.ngOnInit = function () {
        var _this = this;
        this.nzRadioService.selected$.subscribe(function (value) {
            if (_this.value !== value) {
                _this.value = value;
                _this.onChange(_this.value);
            }
        });
        this.nzRadioService.touched$.subscribe(function () {
            Promise.resolve().then(function () { return _this.onTouched(); });
        });
    };
    NzRadioGroupComponent.prototype.ngOnChanges = function (changes) {
        var nzDisabled = changes.nzDisabled, nzName = changes.nzName;
        if (nzDisabled) {
            this.nzRadioService.setDisabled(this.nzDisabled);
        }
        if (nzName) {
            this.nzRadioService.setName(this.nzName);
        }
    };
    NzRadioGroupComponent.prototype.ngOnDestroy = function () {
        this.destroy$.next();
        this.destroy$.complete();
    };
    NzRadioGroupComponent.prototype.writeValue = function (value) {
        this.value = value;
        this.nzRadioService.select(value);
        this.cdr.markForCheck();
    };
    NzRadioGroupComponent.prototype.registerOnChange = function (fn) {
        this.onChange = fn;
    };
    NzRadioGroupComponent.prototype.registerOnTouched = function (fn) {
        this.onTouched = fn;
    };
    NzRadioGroupComponent.prototype.setDisabledState = function (isDisabled) {
        this.nzDisabled = isDisabled;
        this.nzRadioService.setDisabled(isDisabled);
        this.cdr.markForCheck();
    };
    /** @nocollapse */ NzRadioGroupComponent.ɵfac = function NzRadioGroupComponent_Factory(t) { return new (t || NzRadioGroupComponent)(ɵɵdirectiveInject(ChangeDetectorRef), ɵɵdirectiveInject(NzRadioService)); };
    /** @nocollapse */ NzRadioGroupComponent.ɵcmp = ɵɵdefineComponent({ type: NzRadioGroupComponent, selectors: [["nz-radio-group"]], hostVars: 8, hostBindings: function NzRadioGroupComponent_HostBindings(rf, ctx) { if (rf & 2) {
            ɵɵclassProp("ant-radio-group", true)("ant-radio-group-large", ctx.nzSize === "large")("ant-radio-group-small", ctx.nzSize === "small")("ant-radio-group-solid", ctx.nzButtonStyle === "solid");
        } }, inputs: { nzDisabled: "nzDisabled", nzButtonStyle: "nzButtonStyle", nzSize: "nzSize", nzName: "nzName" }, exportAs: ["nzRadioGroup"], features: [ɵɵProvidersFeature([
                NzRadioService,
                {
                    provide: NG_VALUE_ACCESSOR,
                    useExisting: forwardRef((function () { return NzRadioGroupComponent; })),
                    multi: true
                }
            ]), ɵɵNgOnChangesFeature], ngContentSelectors: _c0, decls: 1, vars: 0, template: function NzRadioGroupComponent_Template(rf, ctx) { if (rf & 1) {
            ɵɵprojectionDef();
            ɵɵprojection(0);
        } }, encapsulation: 2, changeDetection: 0 });
    __decorate([
        InputBoolean(),
        __metadata("design:type", Object)
    ], NzRadioGroupComponent.prototype, "nzDisabled", void 0);
    return NzRadioGroupComponent;
}());
/*@__PURE__*/ (function () { ɵsetClassMetadata(NzRadioGroupComponent, [{
        type: Component,
        args: [{
                selector: 'nz-radio-group',
                exportAs: 'nzRadioGroup',
                preserveWhitespaces: false,
                template: "\n    <ng-content></ng-content>\n  ",
                encapsulation: ViewEncapsulation.None,
                changeDetection: ChangeDetectionStrategy.OnPush,
                providers: [
                    NzRadioService,
                    {
                        provide: NG_VALUE_ACCESSOR,
                        useExisting: forwardRef((function () { return NzRadioGroupComponent; })),
                        multi: true
                    }
                ],
                host: {
                    '[class.ant-radio-group]': "true",
                    '[class.ant-radio-group-large]': "nzSize === 'large'",
                    '[class.ant-radio-group-small]': "nzSize === 'small'",
                    '[class.ant-radio-group-solid]': "nzButtonStyle === 'solid'"
                }
            }]
    }], function () { return [{ type: ChangeDetectorRef }, { type: NzRadioService }]; }, { nzDisabled: [{
            type: Input
        }], nzButtonStyle: [{
            type: Input
        }], nzSize: [{
            type: Input
        }], nzName: [{
            type: Input
        }] }); })();

var _c0$1 = ["inputElement"];
var _c1 = ["nz-radio", ""];
var _c2 = ["*"];
var NzRadioComponent = /** @class */ (function () {
    function NzRadioComponent(elementRef, cdr, focusMonitor, nzRadioService, nzRadioButtonDirective) {
        this.elementRef = elementRef;
        this.cdr = cdr;
        this.focusMonitor = focusMonitor;
        this.nzRadioService = nzRadioService;
        this.nzRadioButtonDirective = nzRadioButtonDirective;
        this.isNgModel = false;
        this.destroy$ = new Subject();
        this.isChecked = false;
        this.name = null;
        this.isRadioButton = !!this.nzRadioButtonDirective;
        this.onChange = function () { };
        this.onTouched = function () { };
        this.nzValue = null;
        this.nzDisabled = false;
        this.nzAutoFocus = false;
    }
    NzRadioComponent.prototype.onHostClick = function (event) {
        /** prevent label click triggered twice. **/
        event.stopPropagation();
        event.preventDefault();
        this.focus();
        if (!this.nzDisabled && !this.isChecked) {
            if (this.nzRadioService) {
                this.nzRadioService.select(this.nzValue);
            }
            if (this.isNgModel) {
                this.isChecked = true;
                this.onChange(true);
            }
        }
    };
    NzRadioComponent.prototype.focus = function () {
        this.focusMonitor.focusVia(this.inputElement, 'keyboard');
    };
    NzRadioComponent.prototype.blur = function () {
        this.inputElement.nativeElement.blur();
    };
    NzRadioComponent.prototype.setDisabledState = function (disabled) {
        this.nzDisabled = disabled;
        this.cdr.markForCheck();
    };
    NzRadioComponent.prototype.writeValue = function (value) {
        this.isChecked = value;
        this.cdr.markForCheck();
    };
    NzRadioComponent.prototype.registerOnChange = function (fn) {
        this.isNgModel = true;
        this.onChange = fn;
    };
    NzRadioComponent.prototype.registerOnTouched = function (fn) {
        this.onTouched = fn;
    };
    NzRadioComponent.prototype.ngOnInit = function () {
        var _this = this;
        if (this.nzRadioService) {
            this.nzRadioService.name$.pipe(takeUntil(this.destroy$)).subscribe(function (name) {
                _this.name = name;
                _this.cdr.markForCheck();
            });
            this.nzRadioService.disabled$.pipe(takeUntil(this.destroy$)).subscribe(function (disabled) {
                _this.nzDisabled = disabled;
                _this.cdr.markForCheck();
            });
            this.nzRadioService.selected$.pipe(takeUntil(this.destroy$)).subscribe(function (value) {
                _this.isChecked = _this.nzValue === value;
                _this.cdr.markForCheck();
            });
        }
        this.focusMonitor.monitor(this.elementRef, true).subscribe(function (focusOrigin) {
            if (!focusOrigin) {
                Promise.resolve().then(function () { return _this.onTouched(); });
                if (_this.nzRadioService) {
                    _this.nzRadioService.touch();
                }
            }
        });
    };
    NzRadioComponent.prototype.ngAfterViewInit = function () {
        if (this.nzAutoFocus) {
            this.focus();
        }
    };
    NzRadioComponent.prototype.ngOnDestroy = function () {
        this.destroy$.next();
        this.destroy$.complete();
        this.focusMonitor.stopMonitoring(this.elementRef);
    };
    /** @nocollapse */ NzRadioComponent.ɵfac = function NzRadioComponent_Factory(t) { return new (t || NzRadioComponent)(ɵɵdirectiveInject(ElementRef), ɵɵdirectiveInject(ChangeDetectorRef), ɵɵdirectiveInject(FocusMonitor), ɵɵdirectiveInject(NzRadioService, 8), ɵɵdirectiveInject(NzRadioButtonDirective, 8)); };
    /** @nocollapse */ NzRadioComponent.ɵcmp = ɵɵdefineComponent({ type: NzRadioComponent, selectors: [["", "nz-radio", ""], ["", "nz-radio-button", ""]], viewQuery: function NzRadioComponent_Query(rf, ctx) { if (rf & 1) {
            ɵɵviewQuery(_c0$1, true);
        } if (rf & 2) {
            var _t;
            ɵɵqueryRefresh(_t = ɵɵloadQuery()) && (ctx.inputElement = _t.first);
        } }, hostVars: 12, hostBindings: function NzRadioComponent_HostBindings(rf, ctx) { if (rf & 1) {
            ɵɵlistener("click", function NzRadioComponent_click_HostBindingHandler($event) { return ctx.onHostClick($event); });
        } if (rf & 2) {
            ɵɵclassProp("ant-radio-wrapper", !ctx.isRadioButton)("ant-radio-button-wrapper", ctx.isRadioButton)("ant-radio-wrapper-checked", ctx.isChecked && !ctx.isRadioButton)("ant-radio-button-wrapper-checked", ctx.isChecked && ctx.isRadioButton)("ant-radio-wrapper-disabled", ctx.nzDisabled && !ctx.isRadioButton)("ant-radio-button-wrapper-disabled", ctx.nzDisabled && ctx.isRadioButton);
        } }, inputs: { nzValue: "nzValue", nzDisabled: "nzDisabled", nzAutoFocus: "nzAutoFocus" }, exportAs: ["nzRadio"], features: [ɵɵProvidersFeature([
                {
                    provide: NG_VALUE_ACCESSOR,
                    useExisting: forwardRef((function () { return NzRadioComponent; })),
                    multi: true
                }
            ])], attrs: _c1, ngContentSelectors: _c2, decls: 6, vars: 24, consts: [["type", "radio", 3, "disabled", "checked"], ["inputElement", ""]], template: function NzRadioComponent_Template(rf, ctx) { if (rf & 1) {
            ɵɵprojectionDef();
            ɵɵelementStart(0, "span");
            ɵɵelement(1, "input", 0, 1);
            ɵɵelement(3, "span");
            ɵɵelementEnd();
            ɵɵelementStart(4, "span");
            ɵɵprojection(5);
            ɵɵelementEnd();
        } if (rf & 2) {
            ɵɵclassProp("ant-radio", !ctx.isRadioButton)("ant-radio-checked", ctx.isChecked && !ctx.isRadioButton)("ant-radio-disabled", ctx.nzDisabled && !ctx.isRadioButton)("ant-radio-button", ctx.isRadioButton)("ant-radio-button-checked", ctx.isChecked && ctx.isRadioButton)("ant-radio-button-disabled", ctx.nzDisabled && ctx.isRadioButton);
            ɵɵadvance(1);
            ɵɵclassProp("ant-radio-input", !ctx.isRadioButton)("ant-radio-button-input", ctx.isRadioButton);
            ɵɵproperty("disabled", ctx.nzDisabled)("checked", ctx.isChecked);
            ɵɵattribute("autofocus", ctx.nzAutoFocus ? "autofocus" : null)("name", ctx.name);
            ɵɵadvance(2);
            ɵɵclassProp("ant-radio-inner", !ctx.isRadioButton)("ant-radio-button-inner", ctx.isRadioButton);
        } }, encapsulation: 2, changeDetection: 0 });
    __decorate([
        InputBoolean(),
        __metadata("design:type", Object)
    ], NzRadioComponent.prototype, "nzDisabled", void 0);
    __decorate([
        InputBoolean(),
        __metadata("design:type", Object)
    ], NzRadioComponent.prototype, "nzAutoFocus", void 0);
    return NzRadioComponent;
}());
/*@__PURE__*/ (function () { ɵsetClassMetadata(NzRadioComponent, [{
        type: Component,
        args: [{
                selector: '[nz-radio],[nz-radio-button]',
                exportAs: 'nzRadio',
                preserveWhitespaces: false,
                template: "\n    <span\n      [class.ant-radio]=\"!isRadioButton\"\n      [class.ant-radio-checked]=\"isChecked && !isRadioButton\"\n      [class.ant-radio-disabled]=\"nzDisabled && !isRadioButton\"\n      [class.ant-radio-button]=\"isRadioButton\"\n      [class.ant-radio-button-checked]=\"isChecked && isRadioButton\"\n      [class.ant-radio-button-disabled]=\"nzDisabled && isRadioButton\"\n    >\n      <input\n        #inputElement\n        type=\"radio\"\n        [attr.autofocus]=\"nzAutoFocus ? 'autofocus' : null\"\n        [class.ant-radio-input]=\"!isRadioButton\"\n        [class.ant-radio-button-input]=\"isRadioButton\"\n        [disabled]=\"nzDisabled\"\n        [checked]=\"isChecked\"\n        [attr.name]=\"name\"\n      />\n      <span [class.ant-radio-inner]=\"!isRadioButton\" [class.ant-radio-button-inner]=\"isRadioButton\"></span>\n    </span>\n    <span><ng-content></ng-content></span>\n  ",
                encapsulation: ViewEncapsulation.None,
                changeDetection: ChangeDetectionStrategy.OnPush,
                providers: [
                    {
                        provide: NG_VALUE_ACCESSOR,
                        useExisting: forwardRef((function () { return NzRadioComponent; })),
                        multi: true
                    }
                ],
                host: {
                    '[class.ant-radio-wrapper]': '!isRadioButton',
                    '[class.ant-radio-button-wrapper]': 'isRadioButton',
                    '[class.ant-radio-wrapper-checked]': 'isChecked && !isRadioButton',
                    '[class.ant-radio-button-wrapper-checked]': 'isChecked && isRadioButton',
                    '[class.ant-radio-wrapper-disabled]': 'nzDisabled && !isRadioButton',
                    '[class.ant-radio-button-wrapper-disabled]': 'nzDisabled && isRadioButton',
                    '(click)': 'onHostClick($event)'
                }
            }]
    }], function () { return [{ type: ElementRef }, { type: ChangeDetectorRef }, { type: FocusMonitor }, { type: NzRadioService, decorators: [{
                type: Optional
            }] }, { type: NzRadioButtonDirective, decorators: [{
                type: Optional
            }] }]; }, { inputElement: [{
            type: ViewChild,
            args: ['inputElement', { static: false }]
        }], nzValue: [{
            type: Input
        }], nzDisabled: [{
            type: Input
        }], nzAutoFocus: [{
            type: Input
        }] }); })();

/**
 * @license
 * Copyright Alibaba.com All Rights Reserved.
 *
 * Use of this source code is governed by an MIT-style license that can be
 * found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE
 */
var NzRadioModule = /** @class */ (function () {
    function NzRadioModule() {
    }
    /** @nocollapse */ NzRadioModule.ɵmod = ɵɵdefineNgModule({ type: NzRadioModule });
    /** @nocollapse */ NzRadioModule.ɵinj = ɵɵdefineInjector({ factory: function NzRadioModule_Factory(t) { return new (t || NzRadioModule)(); }, imports: [[CommonModule, FormsModule]] });
    return NzRadioModule;
}());
(function () { (typeof ngJitMode === "undefined" || ngJitMode) && ɵɵsetNgModuleScope(NzRadioModule, { declarations: [NzRadioComponent, NzRadioButtonDirective, NzRadioGroupComponent], imports: [CommonModule, FormsModule], exports: [NzRadioComponent, NzRadioButtonDirective, NzRadioGroupComponent] }); })();
/*@__PURE__*/ (function () { ɵsetClassMetadata(NzRadioModule, [{
        type: NgModule,
        args: [{
                imports: [CommonModule, FormsModule],
                exports: [NzRadioComponent, NzRadioButtonDirective, NzRadioGroupComponent],
                declarations: [NzRadioComponent, NzRadioButtonDirective, NzRadioGroupComponent]
            }]
    }], null, null); })();

/**
 * @license
 * Copyright Alibaba.com All Rights Reserved.
 *
 * Use of this source code is governed by an MIT-style license that can be
 * found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE
 */

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

export { NzRadioButtonDirective, NzRadioComponent, NzRadioGroupComponent, NzRadioModule, NzRadioService };
//# sourceMappingURL=ng-zorro-antd-radio.js.map
