import { Version, Injectable, Optional, SkipSelf, Component, ViewEncapsulation, ChangeDetectionStrategy, ChangeDetectorRef, Input, HostBinding, Output, EventEmitter, NgModule, Directive, Renderer2, ElementRef } from '@angular/core';
import { CommonModule } from '@angular/common';
import { Validators, ReactiveFormsModule } from '@angular/forms';
import { MatAutocompleteModule } from '@angular/material/autocomplete';
import { MatButtonModule } from '@angular/material/button';
import { MatFormFieldModule } from '@angular/material/form-field';
import { MatIconModule } from '@angular/material/icon';
import { MatInputModule } from '@angular/material/input';
import { MatProgressSpinnerModule } from '@angular/material/progress-spinner';
import { SpPipesModule } from '@uiux/cdk/pipes';
import { __extends } from 'tslib';
import { AbstractFormFactory, FormBuilderFactoryService, INITIAL_FORM_VALUE, SpFormBuilderServiceModule } from '@uiux/cdk/forms';
import { forbiddenWhitespaceValidator } from '@uiux/cdk/validators';
import _isString from 'lodash-es/isString';
import { Subscription } from 'rxjs';
import { hasValue } from '@uiux/fn/common';

/**
 * @fileoverview added by tsickle
 * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
 */
/**
 * Current version of Angular Material.
 * @type {?}
 */
var VERSION = new Version('0.0.1');

/**
 * @fileoverview added by tsickle
 * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
 */
var SpSearchAutoComplateFormGroup = /** @class */ (function (_super) {
    __extends(SpSearchAutoComplateFormGroup, _super);
    // tslint:disable
    function SpSearchAutoComplateFormGroup(formBuilderFactory, _action) {
        var _this = _super.call(this, formBuilderFactory, _action) || this;
        _this.formBuilderFactory = formBuilderFactory;
        _this._action = _action;
        return _this;
    }
    // tslint:enable
    // tslint:enable
    /**
     * @return {?}
     */
    SpSearchAutoComplateFormGroup.prototype.defaultValueConfig = 
    // tslint:enable
    /**
     * @return {?}
     */
    function () {
        return {
            search: '',
        };
    };
    /**
     * @return {?}
     */
    SpSearchAutoComplateFormGroup.prototype.validatorsConfig = /**
     * @return {?}
     */
    function () {
        return {
            search: [forbiddenWhitespaceValidator(), Validators.minLength(3)],
        };
    };
    /**
     * @return {?}
     */
    SpSearchAutoComplateFormGroup.prototype.errorsMessagesConfig = /**
     * @return {?}
     */
    function () {
        return {
            search: {
                minlength: 'Minimum of three characters.',
                forbiddenWhitespace: 'No leading or trailing whitespace.',
            },
        };
    };
    /**
     * @return {?}
     */
    SpSearchAutoComplateFormGroup.prototype.onChange = /**
     * @return {?}
     */
    function () {
        /* noop */
    };
    return SpSearchAutoComplateFormGroup;
}(AbstractFormFactory));
var SpSearchAutoComplateFormGroupFactory = /** @class */ (function () {
    function SpSearchAutoComplateFormGroupFactory(fp) {
        this.fp = fp;
        /* noop */
    }
    /**
     * @param {?=} action
     * @return {?}
     */
    SpSearchAutoComplateFormGroupFactory.prototype.create = /**
     * @param {?=} action
     * @return {?}
     */
    function (action) {
        return new SpSearchAutoComplateFormGroup(this.fp, action);
    };
    SpSearchAutoComplateFormGroupFactory.decorators = [
        { type: Injectable }
    ];
    /** @nocollapse */
    SpSearchAutoComplateFormGroupFactory.ctorParameters = function () { return [
        { type: FormBuilderFactoryService }
    ]; };
    return SpSearchAutoComplateFormGroupFactory;
}());
// tslint:disable
/**
 * @param {?} parentDispatcher
 * @param {?} fp
 * @return {?}
 */
function _searchFormGroupFactory(parentDispatcher, fp) {
    return parentDispatcher || new SpSearchAutoComplateFormGroupFactory(fp);
}
/** @type {?} */
var SP_SEARCH_AUTOCOMPLETE_FORMGROUP_PROVIDER = {
    provide: SpSearchAutoComplateFormGroupFactory,
    deps: [
        [new Optional(), new SkipSelf(), SpSearchAutoComplateFormGroupFactory],
        FormBuilderFactoryService,
    ],
    useFactory: _searchFormGroupFactory,
};

/**
 * @fileoverview added by tsickle
 * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
 */
var SpSearchAutoCompleteComponent = /** @class */ (function () {
    function SpSearchAutoCompleteComponent(_changeDetector, _formGroupFactory) {
        this._changeDetector = _changeDetector;
        this._formGroupFactory = _formGroupFactory;
        this._formSub = Subscription.EMPTY;
        this._currentSearchValue = '';
        this._optionIsSelecting = false;
        this.formValue = INITIAL_FORM_VALUE;
        this.inputBlur = true;
        this.bindStyle = true;
        this.placeholder = '';
        this.autoCompleteData = [];
        /**
         * Options
         * textOnly, iconText
         */
        this.optionTemplate = 'textOnly';
        this.delay = 300;
        this.minLength = 3;
        this.iconLeft = false;
        this.isSearching = false;
        this.disableSubmit = false;
        this.overrideMaterial = true;
        this.spinnerConfig = {
            diameter: 14,
            strokeWidth: 1,
        };
        /**
         * String emitted from input value changes.
         * Always a string value.
         */
        this.valueChanges = new EventEmitter();
        /**
         * Object or String emitted from autocomplete option select.
         * Always a string value.
         */
        this.optionSelected = new EventEmitter();
        /**
         * Object or String emitted from keyboard 'Enter' event
         * or click event on search icon.
         */
        this.submit = new EventEmitter();
        /**
         * Aggregation of optionSelected, onSubmitHandler, and valueChanges events.
         * ( You receive all events )
         */
        this.changes = new EventEmitter();
    }
    Object.defineProperty(SpSearchAutoCompleteComponent.prototype, "control", {
        get: /**
         * @return {?}
         */
        function () {
            if (!this._controller) {
                this.formGroupService = this._formGroupFactory.create();
                this.formGroup = this.formGroupService.form;
                this._controller = this.formGroup.controls['search'];
                if (this.minLength !== 3) {
                    // tslint:disable-next-line:no-string-literal
                    this.formGroup.controls['search'].setValidators([
                        forbiddenWhitespaceValidator(),
                        Validators.minLength(this.minLength),
                    ]);
                }
            }
            return this._controller;
        },
        set: /**
         * @param {?} val
         * @return {?}
         */
        function (val) {
            this._controller = val;
        },
        enumerable: true,
        configurable: true
    });
    /**
     * @return {?}
     */
    SpSearchAutoCompleteComponent.prototype.ngAfterViewInit = /**
     * @return {?}
     */
    function () {
        var _this = this;
        /**
         * valueChanges handler
         */
        this._formSub = this.control.valueChanges.subscribe((/**
         * @param {?} val
         * @return {?}
         */
        function (val) {
            if (_isString(val) && _this._currentSearchValue !== val.trim()) {
                _this._currentSearchValue = val.trim();
                if (_this._timer) {
                    clearTimeout(_this._timer);
                }
                _this._timer = setTimeout((/**
                 * @return {?}
                 */
                function () {
                    if (!_this._optionIsSelecting) {
                        _this.valueChanges.emit(_this._currentSearchValue);
                        _this.onChange(_this._currentSearchValue);
                    }
                    else {
                        _this._optionIsSelecting = false;
                    }
                }), _this.delay);
            }
        }));
    };
    /**
     * onSubmitHandler handler
     */
    /**
     * onSubmitHandler handler
     * @return {?}
     */
    SpSearchAutoCompleteComponent.prototype.onSubmitHandler = /**
     * onSubmitHandler handler
     * @return {?}
     */
    function () {
        if (!this.disableSubmit && this._controller.valid && !this._controller.pristine) {
            this.submit.emit(this._currentSearchValue);
            this.onChange(this._currentSearchValue);
        }
    };
    /**
     * optionSelected handler
     */
    /**
     * optionSelected handler
     * @param {?} e
     * @return {?}
     */
    SpSearchAutoCompleteComponent.prototype.onOptionSelected = /**
     * optionSelected handler
     * @param {?} e
     * @return {?}
     */
    function (e) {
        this.isSearching = false;
        this._optionIsSelecting = true;
        if (this._currentSearchValue !== e.option.value) {
            this._currentSearchValue = e.option.value;
            this.optionSelected.emit(this._currentSearchValue);
            this.onChange(this._currentSearchValue);
        }
    };
    /**
     * @return {?}
     */
    SpSearchAutoCompleteComponent.prototype.detectChanges = /**
     * @return {?}
     */
    function () {
        this._changeDetector.detectChanges();
    };
    /**
     * @param {?} val
     * @return {?}
     */
    SpSearchAutoCompleteComponent.prototype.onChange = /**
     * @param {?} val
     * @return {?}
     */
    function (val) {
        this.changes.emit(val);
    };
    /**
     * if optionValueMap is provided, return
     * the value mapped in option, else, return
     * the option itself.
     *
     * @param option
     * @returns string
     */
    /**
     * if optionValueMap is provided, return
     * the value mapped in option, else, return
     * the option itself.
     *
     * @param {?} option
     * @return {?} string
     */
    SpSearchAutoCompleteComponent.prototype.formatOptionText = /**
     * if optionValueMap is provided, return
     * the value mapped in option, else, return
     * the option itself.
     *
     * @param {?} option
     * @return {?} string
     */
    function (option) {
        if (this.optionFormatter) {
            return this.optionFormatter(option);
        }
        else {
            return option;
        }
    };
    SpSearchAutoCompleteComponent.decorators = [
        { type: Component, args: [{
                    selector: 'ix-search-autocomplete',
                    template: "<mat-form-field [ngClass]=\"{'mat-form-field-label-wrapper-focus': inputBlur, 'override-mat': overrideMaterial }\">\n  <input\n    class=\"search-autocomplete-input\"\n    [formControl]=\"control\"\n    [placeholder]=\"placeholder\"\n    name=\"search\"\n    matInput\n    type=\"text\"\n    [matAutocomplete]=\"auto\"\n    (focus)=\"detectChanges(); inputBlur = false;\"\n    (blur)=\"detectChanges(); inputBlur = true;\"\n    (keyup.enter)=\"onSubmitHandler()\"/>\n  <button mat-button\n          class=\"search-autocomplete-search-icon\"\n          *ngIf=\"!isSearching && iconLeft\"\n          matPrefix\n          mat-icon-button\n          aria-label=\"Search\"\n          [disabled]=\"control.invalid || control.pristine\"\n          (click)=\"$event.stopPropagation(); onSubmitHandler()\">\n    <mat-icon>search</mat-icon>\n  </button>\n  <button matPrefix\n          class=\"search-autocomplete-spinner pad-top-9\"\n          mat-icon-button\n          *ngIf=\"isSearching && iconLeft\">\n    <mat-progress-spinner\n      [diameter]=\"spinnerConfig.diameter\"\n      [strokeWidth]=\"spinnerConfig.strokeWidth\"\n      [mode]=\"'indeterminate'\">\n    </mat-progress-spinner>\n  </button>\n\n  <button mat-button\n          class=\"search-autocomplete-search-icon\"\n          *ngIf=\"!isSearching && !iconLeft\"\n          matSuffix\n          mat-icon-button\n          aria-label=\"Search\"\n          (click)=\"$event.stopPropagation(); onSubmitHandler()\"\n          [disabled]=\"control.invalid || control.pristine\">\n    <mat-icon>search</mat-icon>\n  </button>\n  <button matSuffix\n          class=\"search-autocomplete-spinner pad-top-9\"\n          mat-icon-button\n          *ngIf=\"isSearching && !iconLeft\">\n    <mat-progress-spinner\n      [diameter]=\"spinnerConfig.diameter\"\n      [strokeWidth]=\"spinnerConfig.strokeWidth\"\n      [mode]=\"'indeterminate'\">\n    </mat-progress-spinner>\n  </button>\n  <mat-error>{{control?.errors | spShowSingleError}}</mat-error>\n</mat-form-field>\n\n<mat-autocomplete #auto=\"matAutocomplete\"\n                  class=\"search-autocomplete\"\n                  (optionSelected)=\"onOptionSelected($event)\"\n                  [displayWith]=\"displayWith\">\n  <mat-option *ngFor=\"let option of autoCompleteData\" [value]=\"option\">\n    <span [innerHtml]=\"formatOptionText(option)\"></span>\n  </mat-option>\n</mat-autocomplete>\n",
                    encapsulation: ViewEncapsulation.None,
                    preserveWhitespaces: false,
                    changeDetection: ChangeDetectionStrategy.OnPush,
                    styles: [".search-autocomplete-component,.search-autocomplete-component .mat-form-field{width:100%}.search-autocomplete-component .override-mat.mat-form-field-should-float .mat-input-placeholder-wrapper,.search-autocomplete-component .override-mat.mat-input-placeholder-wrapper{left:6px}.search-autocomplete-component .override-mat.mat-form-field-should-float .mat-form-field-placeholder{-webkit-transform-origin:0 0;transform-origin:0 0;-webkit-transition:opacity 450ms ease-in-out;-moz-transition:opacity 450ms ease-in-out;-ms-transition:opacity 450ms ease-in-out;-o-transition:opacity 450ms ease-in-out;opacity:1}.search-autocomplete-component .override-mat.mat-form-field-can-float.mat-form-field-should-float .mat-form-field-placeholder{-webkit-transform:translateY(0) scale(1) perspective(100px) translateZ(.001px);transform:translateY(0) scale(1) perspective(100px) translateZ(.001px);-ms-transform:translateY(0) scale(1);-webkit-transition:opacity 450ms ease-in-out;-moz-transition:opacity 450ms ease-in-out;-ms-transition:opacity 450ms ease-in-out;-o-transition:opacity 450ms ease-in-out;opacity:0}.search-autocomplete-component .override-mat.mat-input-infix{padding-left:6px}"]
                }] }
    ];
    /** @nocollapse */
    SpSearchAutoCompleteComponent.ctorParameters = function () { return [
        { type: ChangeDetectorRef },
        { type: SpSearchAutoComplateFormGroupFactory }
    ]; };
    SpSearchAutoCompleteComponent.propDecorators = {
        control: [{ type: Input }],
        bindStyle: [{ type: HostBinding, args: ['class.search-autocomplete-component',] }],
        placeholder: [{ type: Input }],
        autoCompleteData: [{ type: Input }],
        optionTemplate: [{ type: Input }],
        delay: [{ type: Input }],
        minLength: [{ type: Input }],
        iconLeft: [{ type: Input }],
        isSearching: [{ type: Input }],
        displayWith: [{ type: Input }],
        optionFormatter: [{ type: Input }],
        disableSubmit: [{ type: Input }],
        overrideMaterial: [{ type: Input }],
        spinnerConfig: [{ type: Input }],
        valueChanges: [{ type: Output }],
        optionSelected: [{ type: Output }],
        submit: [{ type: Output }],
        changes: [{ type: Output }]
    };
    return SpSearchAutoCompleteComponent;
}());

/**
 * @fileoverview added by tsickle
 * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
 */
var SpSearchAutocompleteModule = /** @class */ (function () {
    function SpSearchAutocompleteModule() {
    }
    SpSearchAutocompleteModule.decorators = [
        { type: NgModule, args: [{
                    imports: [
                        CommonModule,
                        ReactiveFormsModule,
                        MatAutocompleteModule,
                        MatButtonModule,
                        MatFormFieldModule,
                        MatIconModule,
                        MatInputModule,
                        MatProgressSpinnerModule,
                        SpPipesModule,
                        SpFormBuilderServiceModule,
                    ],
                    declarations: [SpSearchAutoCompleteComponent],
                    providers: [SP_SEARCH_AUTOCOMPLETE_FORMGROUP_PROVIDER],
                    exports: [SpSearchAutoCompleteComponent],
                },] }
    ];
    return SpSearchAutocompleteModule;
}());

/**
 * @fileoverview added by tsickle
 * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
 */

/**
 * @fileoverview added by tsickle
 * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
 */

/**
 * @fileoverview added by tsickle
 * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
 */
// tslint:disable-next-line
var IxShowDirective = /** @class */ (function () {
    function IxShowDirective(_renderer, _el) {
        this._renderer = _renderer;
        this._el = _el;
        this._hasShown = false;
        this._renderer.addClass(this._el.nativeElement, 'ix-hide-initial');
        // this._renderer.addClass(this._el.nativeElement, 'ix-hide');
    }
    /**
     * @param {?} change
     * @return {?}
     */
    IxShowDirective.prototype.ngOnChanges = /**
     * @param {?} change
     * @return {?}
     */
    function (change) {
        // tslint:disable:no-string-literal
        if (hasValue(change['ixShow'])) {
            if (change['ixShow'].currentValue) {
                this.show();
            }
            else {
                this.hide();
            }
        }
        // tslint:enable:no-string-literal
    };
    /**
     * @return {?}
     */
    IxShowDirective.prototype.show = /**
     * @return {?}
     */
    function () {
        if (!this._hasShown) {
            this._renderer.addClass(this._el.nativeElement, 'ix-show');
            this._renderer.removeClass(this._el.nativeElement, 'ix-hide-initial');
            this._hasShown = true;
        }
        else {
            this._renderer.removeClass(this._el.nativeElement, 'ix-hide');
        }
    };
    /**
     * @return {?}
     */
    IxShowDirective.prototype.hide = /**
     * @return {?}
     */
    function () {
        if (this._hasShown) {
            this._renderer.addClass(this._el.nativeElement, 'ix-hide');
        }
    };
    IxShowDirective.decorators = [
        { type: Directive, args: [{
                    selector: '[ixShow]',
                },] }
    ];
    /** @nocollapse */
    IxShowDirective.ctorParameters = function () { return [
        { type: Renderer2 },
        { type: ElementRef }
    ]; };
    IxShowDirective.propDecorators = {
        ixShow: [{ type: Input }]
    };
    return IxShowDirective;
}());

/**
 * @fileoverview added by tsickle
 * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
 */
var IxShowModule = /** @class */ (function () {
    function IxShowModule() {
    }
    IxShowModule.decorators = [
        { type: NgModule, args: [{
                    declarations: [IxShowDirective],
                    exports: [IxShowDirective],
                },] }
    ];
    return IxShowModule;
}());

/**
 * @fileoverview added by tsickle
 * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
 */

/**
 * @fileoverview added by tsickle
 * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
 */

/**
 * @fileoverview added by tsickle
 * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
 */
var SpSpinningButtonComponent = /** @class */ (function () {
    function SpSpinningButtonComponent() {
    }
    SpSpinningButtonComponent.decorators = [
        { type: Component, args: [{
                    selector: 'ix-spinning-button',
                    template: "<button mat-raised-button color=\"{{backgroundColor}}\" class=\"ix-spinning-button\">\n  <span>{{text}}</span>\n  <span class=\"ix-spinning-outer\">\n    <mat-spinner [diameter]=\"18\" [strokeWidth]=\"1\"></mat-spinner>\n  </span>\n</button>\n",
                    encapsulation: ViewEncapsulation.None,
                    preserveWhitespaces: false,
                    changeDetection: ChangeDetectionStrategy.OnPush,
                    styles: [".ix-spinning-button{cursor:default}.ix-spinning-button .ix-spinning-outer{position:absolute;left:0;width:100%}.ix-spinning-button .ix-spinning-outer .mat-spinner{position:relative;top:10px;display:table;margin:0 auto}"]
                }] }
    ];
    SpSpinningButtonComponent.propDecorators = {
        text: [{ type: Input }],
        backgroundColor: [{ type: Input }]
    };
    return SpSpinningButtonComponent;
}());

/**
 * @fileoverview added by tsickle
 * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
 */
var SpSpinningButtonModule = /** @class */ (function () {
    function SpSpinningButtonModule() {
    }
    SpSpinningButtonModule.decorators = [
        { type: NgModule, args: [{
                    imports: [CommonModule, MatButtonModule, MatProgressSpinnerModule],
                    declarations: [SpSpinningButtonComponent],
                    exports: [SpSpinningButtonComponent],
                },] }
    ];
    return SpSpinningButtonModule;
}());

/**
 * @fileoverview added by tsickle
 * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
 */

/**
 * @fileoverview added by tsickle
 * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
 */

/**
 * @fileoverview added by tsickle
 * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
 */

/**
 * @fileoverview added by tsickle
 * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
 */

export { IxShowDirective, IxShowModule, SP_SEARCH_AUTOCOMPLETE_FORMGROUP_PROVIDER, SpSearchAutoComplateFormGroup, SpSearchAutoComplateFormGroupFactory, SpSearchAutoCompleteComponent, SpSearchAutocompleteModule, SpSpinningButtonComponent, SpSpinningButtonModule, VERSION, _searchFormGroupFactory };
//# sourceMappingURL=uiux-material.js.map
