import { getSupportedInputTypes, Platform } from '@angular/cdk/platform';
import { CommonModule } from '@angular/common';
import { Component, ViewEncapsulation, Input, Optional, Self, ElementRef, Directive, NgModule } from '@angular/core';
import { coerceBooleanProperty } from '@angular/cdk/coercion';
import { NgControl } from '@angular/forms';
import { NtFormFieldControl } from '@ng-tangram/components/forms';

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 NtInputAddonComponent = (function () {
    function NtInputAddonComponent() {
    }
    NtInputAddonComponent = __decorate([
        Component({
            selector: 'nt-input-addon, [nt-input-addon]',
            template: "<ng-content></ng-content>",
            encapsulation: ViewEncapsulation.None,
            host: {
                'class': 'nt-input-addon input-group-label'
            }
        })
    ], NtInputAddonComponent);
    return NtInputAddonComponent;
}());

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 NtInputGroupComponent = (function () {
    function NtInputGroupComponent() {
        this._transparent = false;
    }
    Object.defineProperty(NtInputGroupComponent.prototype, "transparent", {
        get: function () { return this._transparent; },
        set: function (value) { this._transparent = coerceBooleanProperty(value); },
        enumerable: true,
        configurable: true
    });
    __decorate$1([
        Input()
    ], NtInputGroupComponent.prototype, "transparent", null);
    NtInputGroupComponent = __decorate$1([
        Component({
            selector: 'nt-input-group, [nt-input-group]',
            template: "<ng-content></ng-content>",
            encapsulation: ViewEncapsulation.None,
            host: {
                'class': 'nt-input-group input-group',
                '[class.nt-input-group-transparent]': 'transparent'
            }
        })
    ], NtInputGroupComponent);
    return NtInputGroupComponent;
}());

var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var __decorate$2 = (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 NtInputDirective = (function (_super) {
    __extends(NtInputDirective, _super);
    function NtInputDirective(ngControl, _platform, _elementRef) {
        var _this = _super.call(this) || this;
        _this.ngControl = ngControl;
        _this._platform = _platform;
        _this._elementRef = _elementRef;
        _this._disabled = false;
        _this._type = 'text';
        _this._readonly = false;
        _this._required = false;
        _this._focused = false;
        _this.placeholder = '';
        return _this;
    }
    NtInputDirective_1 = NtInputDirective;
    Object.defineProperty(NtInputDirective.prototype, "disabled", {
        get: function () {
            if (this.ngControl && this.ngControl.disabled !== null) {
                return this.ngControl.disabled;
            }
            return this._disabled;
        },
        set: function (value) {
            this._disabled = coerceBooleanProperty(value);
            if (this._focused) {
                this._focused = false;
            }
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(NtInputDirective.prototype, "required", {
        get: function () { return this._required; },
        set: function (value) { this._required = coerceBooleanProperty(value); },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(NtInputDirective.prototype, "type", {
        get: function () { return this._type; },
        set: function (value) {
            this._type = value || 'text';
            if (!this._isTextarea() && getSupportedInputTypes().has(this._type)) {
                this._elementRef.nativeElement.type = this._type;
            }
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(NtInputDirective.prototype, "value", {
        get: function () { return this._elementRef.nativeElement.value; },
        set: function (value) {
            if (value !== this.value) {
                this._elementRef.nativeElement.value = value;
            }
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(NtInputDirective.prototype, "readonly", {
        get: function () { return this._readonly; },
        set: function (value) { this._readonly = coerceBooleanProperty(value); },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(NtInputDirective.prototype, "empty", {
        get: function () { return !this._elementRef.nativeElement.value && !this._isBadInput(); },
        enumerable: true,
        configurable: true
    });
    NtInputDirective.prototype.focus = function () { this._elementRef.nativeElement.focus(); };
    NtInputDirective.prototype._focusChanged = function (isFocused) {
        if (isFocused !== this._focused && !this.readonly) {
            this._focused = isFocused;
        }
    };
    NtInputDirective.prototype._isBadInput = function () {
        var validity = this._elementRef.nativeElement.validity;
        return validity && validity.badInput;
    };
    NtInputDirective.prototype._isTextarea = function () {
        var nativeElement = this._elementRef.nativeElement;
        var nodeName = this._platform.isBrowser ? nativeElement.nodeName : nativeElement.name;
        return nodeName ? nodeName.toLowerCase() === 'textarea' : false;
    };
    var NtInputDirective_1;
    NtInputDirective.ctorParameters = function () { return [
        { type: NgControl, decorators: [{ type: Optional }, { type: Self }] },
        { type: Platform },
        { type: ElementRef }
    ]; };
    __decorate$2([
        Input()
    ], NtInputDirective.prototype, "placeholder", void 0);
    __decorate$2([
        Input()
    ], NtInputDirective.prototype, "disabled", null);
    __decorate$2([
        Input()
    ], NtInputDirective.prototype, "required", null);
    __decorate$2([
        Input()
    ], NtInputDirective.prototype, "type", null);
    __decorate$2([
        Input()
    ], NtInputDirective.prototype, "value", null);
    __decorate$2([
        Input()
    ], NtInputDirective.prototype, "readonly", null);
    NtInputDirective = NtInputDirective_1 = __decorate$2([
        Directive({
            selector: 'input[ntInput], textarea[ntInput]',
            host: {
                '(blur)': '_focusChanged(false)',
                '(focus)': '_focusChanged(true)',
            },
            providers: [
                { provide: NtFormFieldControl, useExisting: NtInputDirective_1 }
            ]
        }),
        __param(0, Optional()), __param(0, Self())
    ], NtInputDirective);
    return NtInputDirective;
}(NtFormFieldControl));

var __decorate$3 = (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 NtInputModule = (function () {
    function NtInputModule() {
    }
    NtInputModule = __decorate$3([
        NgModule({
            imports: [CommonModule],
            exports: [NtInputDirective, NtInputGroupComponent, NtInputAddonComponent],
            declarations: [NtInputDirective, NtInputGroupComponent, NtInputAddonComponent],
            providers: [Platform]
        })
    ], NtInputModule);
    return NtInputModule;
}());

export { NtInputAddonComponent, NtInputDirective, NtInputGroupComponent, NtInputModule };
//# sourceMappingURL=input.js.map
