import * as i0 from '@angular/core';
import { Directive, Input, ViewChild } from '@angular/core';
import { FormControl } from '@angular/forms';
import '@ironsource/fusion-ui/components/input/v1';
import { takeUntil } from 'rxjs/operators';
import { Subject, fromEvent } from 'rxjs';

const _c0 = ["inputComponent"];
class DropdownSearchBaseComponent {
    get searchInOptions() {
        return this.elementRef?.nativeElement.classList.contains('fu-search-in-options');
    }
    constructor(elementRef) {
        this.elementRef = elementRef;
        this.placeholder = 'Search';
        this.searchValue = new FormControl();
        this.onDestroy$ = new Subject();
        /**
         * Method to call when the component value has changes.
         */
        this.propagateChange = (_) => { };
    }
    ngOnInit() {
        this.searchValue.valueChanges.pipe(takeUntil(this.onDestroy$)).subscribe(newValue => {
            this.propagateChange(newValue);
        });
        fromEvent(this.elementRef.nativeElement, 'click')
            .pipe(takeUntil(this.onDestroy$))
            .subscribe((event) => {
            event.stopPropagation();
        });
    }
    ngOnDestroy() {
        this.onDestroy$.next();
        this.onDestroy$.complete();
    }
    /**
     * update value from model to the component
     */
    writeValue(value) {
        this.searchValue.patchValue(value);
    }
    registerOnChange(fn) {
        this.propagateChange = fn;
    }
    registerOnTouched() { }
    setDisabledState(isDisabled) {
        const state = isDisabled ? 'disable' : 'enable';
        this.searchValue[state]();
    }
    static { this.ɵfac = function DropdownSearchBaseComponent_Factory(t) { return new (t || DropdownSearchBaseComponent)(i0.ɵɵdirectiveInject(i0.ElementRef)); }; }
    static { this.ɵdir = /*@__PURE__*/ i0.ɵɵdefineDirective({ type: DropdownSearchBaseComponent, viewQuery: function DropdownSearchBaseComponent_Query(rf, ctx) { if (rf & 1) {
            i0.ɵɵviewQuery(_c0, 7);
        } if (rf & 2) {
            let _t;
            i0.ɵɵqueryRefresh(_t = i0.ɵɵloadQuery()) && (ctx.inputComponent = _t.first);
        } }, inputs: { autoComplete: "autoComplete", search: "search", placeholder: "placeholder" } }); }
}
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(DropdownSearchBaseComponent, [{
        type: Directive
    }], () => [{ type: i0.ElementRef }], { autoComplete: [{
            type: Input
        }], search: [{
            type: Input
        }], placeholder: [{
            type: Input
        }], inputComponent: [{
            type: ViewChild,
            args: ['inputComponent', { static: true }]
        }] }); })();

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

export { DropdownSearchBaseComponent };
//# sourceMappingURL=ironsource-fusion-ui-components-dropdown-search-common-base.mjs.map
