import { coerceBooleanProperty } from '@angular/cdk/coercion';
import { EventEmitter, ChangeDetectorRef, Attribute, Self, Optional, Input, Output, Component, ViewEncapsulation, ChangeDetectionStrategy, NgModule } from '@angular/core';
import { NgControl, NG_VALUE_ACCESSOR } from '@angular/forms';
import { CommonModule } from '@angular/common';

var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __param = (this && this.__param) || function (paramIndex, decorator) {
    return function (target, key) { decorator(target, key, paramIndex); }
};
var uniqueId = 0;
var NtSwitchChange = (function () {
    function NtSwitchChange(source, checked) {
        this.source = source;
        this.checked = checked;
    }
    return NtSwitchChange;
}());
var NtSwitchComponent = (function () {
    function NtSwitchComponent(_changeDetectorRef, tabIndex, ngControl) {
        this._changeDetectorRef = _changeDetectorRef;
        this.ngControl = ngControl;
        this.id = "nt-switch-" + uniqueId++;
        this._disabled = false;
        this._checked = false;
        this._circle = false;
        this.change = new EventEmitter();
        this._onChange = function () { };
        this._onTouched = function () { };
        if (this.ngControl) {
            this.ngControl.valueAccessor = this;
        }
        this.tabIndex = parseInt(tabIndex) || 0;
    }
    NtSwitchComponent_1 = NtSwitchComponent;
    Object.defineProperty(NtSwitchComponent.prototype, "disabled", {
        get: function () { return this._disabled; },
        set: function (value) {
            if (value !== this.disabled) {
                this._disabled = coerceBooleanProperty(value);
                this._changeDetectorRef.markForCheck();
            }
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(NtSwitchComponent.prototype, "checked", {
        get: function () { return this._checked; },
        set: function (value) {
            if (value !== this.checked) {
                this._checked = coerceBooleanProperty(value);
                this._changeDetectorRef.markForCheck();
            }
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(NtSwitchComponent.prototype, "circle", {
        get: function () { return this._circle; },
        set: function (value) {
            if (value !== this.circle) {
                this._circle = coerceBooleanProperty(value);
            }
        },
        enumerable: true,
        configurable: true
    });
    NtSwitchComponent.prototype.writeValue = function (value) {
        this._checked = !!value;
    };
    NtSwitchComponent.prototype.registerOnChange = function (fn) {
        this._onChange = fn;
    };
    NtSwitchComponent.prototype.registerOnTouched = function (fn) {
        this._onTouched = fn;
    };
    NtSwitchComponent.prototype.setDisabledState = function (isDisabled) {
        this.disabled = isDisabled;
    };
    NtSwitchComponent.prototype._onInputClick = function (event) {
        event.stopPropagation();
        if (!this.disabled) {
            this._checked = !this._checked;
            this._onTouched();
            this._emitChangeEvent();
        }
    };
    NtSwitchComponent.prototype._onInteractionEvent = function (event) {
        event.stopPropagation();
    };
    NtSwitchComponent.prototype._emitChangeEvent = function () {
        var event = new NtSwitchChange(this, this.checked);
        this._onChange(this.checked);
        this.change.emit(event);
    };
    var NtSwitchComponent_1;
    NtSwitchComponent.ctorParameters = function () { return [
        { type: ChangeDetectorRef },
        { type: String, decorators: [{ type: Attribute, args: ['tabindex',] }] },
        { type: NgControl, decorators: [{ type: Self }, { type: Optional }] }
    ]; };
    __decorate([
        Input()
    ], NtSwitchComponent.prototype, "disabled", null);
    __decorate([
        Input()
    ], NtSwitchComponent.prototype, "checked", null);
    __decorate([
        Input()
    ], NtSwitchComponent.prototype, "circle", null);
    __decorate([
        Output()
    ], NtSwitchComponent.prototype, "change", void 0);
    NtSwitchComponent = NtSwitchComponent_1 = __decorate([
        Component({
            selector: 'nt-switch',
            template: "<input class=\"switch-input\" type=\"checkbox\"\n  [attr.id]=\"id\"\n  [tabIndex]=\"tabIndex\"\n  [checked]=\"checked\"\n  [disabled]=\"disabled\"\n  (change)=\"_onInteractionEvent($event)\"\n  (click)=\"_onInputClick($event)\">\n<label class=\"switch-paddle\" [attr.for]=\"id\"></label>\n",
            encapsulation: ViewEncapsulation.None,
            changeDetection: ChangeDetectionStrategy.OnPush,
            host: {
                'class': 'switch nt-switch',
                '[class.nt-switch-checked]': 'checked',
                '[class.nt-switch-disabled]': 'disabled',
                '[class.nt-switch-circle]': 'circle'
            },
            providers: [
                { provide: NG_VALUE_ACCESSOR, useExisting: NtSwitchComponent_1, multi: true }
            ]
        }),
        __param(1, Attribute('tabindex')),
        __param(2, Self()), __param(2, Optional())
    ], NtSwitchComponent);
    return NtSwitchComponent;
}());

var __decorate$1 = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var NtSwitchModule = (function () {
    function NtSwitchModule() {
    }
    NtSwitchModule = __decorate$1([
        NgModule({
            imports: [CommonModule],
            exports: [NtSwitchComponent],
            declarations: [NtSwitchComponent]
        })
    ], NtSwitchModule);
    return NtSwitchModule;
}());

export { NtSwitchChange, NtSwitchComponent, NtSwitchModule };
//# sourceMappingURL=switch.js.map
