import * as i0 from '@angular/core';
import { forwardRef, Component, ChangeDetectionStrategy, Input } from '@angular/core';
import { CommonModule } from '@angular/common';
import { InputComponent } from '@ironsource/fusion-ui/components/input/v4';
import * as i1 from '@angular/forms';
import { FormControl, NG_VALUE_ACCESSOR, ReactiveFormsModule } from '@angular/forms';
import { Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
import { GenericPipe } from '@ironsource/fusion-ui/pipes/generic';
import { TestIdsService } from '@ironsource/fusion-ui/services/test-ids';

class SearchV4Component {
    // region Inputs - placeholder
    set placeholder(value) {
        this._placeholder = value;
    }
    constructor(injector) {
        this.injector = injector;
        this._size = 'medium';
        // endregion
        /** @internal */
        this.searchIcon = 'ph/magnifying-glass';
        /** @internal */
        this.searchFormControl = new FormControl();
        /** @internal */
        this.onDestroy$ = new Subject();
        // region Implement ControlValueAccessor methods
        /**
         * Method to call when value has changes.
         * @ignore
         */
        this.propagateChange = (_) => { };
        /**
         * Method to call when the component is touched (when it was is clicked).
         * @ignore
         */
        this.propagateTouched = () => { };
        this.testIdsService = this.injector.get(TestIdsService);
    }
    get placeholder() {
        return this._placeholder;
    }
    // endregion
    // region Inputs - size
    set size(value) {
        this._size = value;
    }
    get size() {
        return this._size;
    }
    ngOnInit() {
        this.searchFormControl.valueChanges.pipe(takeUntil(this.onDestroy$)).subscribe(value => {
            this.propagateTouched();
            this.propagateChange(value);
        });
    }
    ngOnDestroy() {
        this.onDestroy$.next();
        this.onDestroy$.complete();
    }
    /**
     * update value from model to the component
     * @ignore
     */
    writeValue(value) {
        this.searchFormControl.setValue(value, { emitEvent: false });
    }
    /**
     * Informs the outside world about changes.
     * see method propagateChange call - this.propagateChange(this.model);
     * @ignore
     */
    registerOnChange(fn) {
        this.propagateChange = fn;
    }
    /**
     * on click
     * @ignore
     */
    registerOnTouched(fn) {
        this.propagateTouched = fn;
    }
    /**
     * on set form controll enabled / disabled
     * also do UI Component enabled / disabled
     * @ignore
     */
    setDisabledState(disabled) {
        if (disabled) {
            this.searchFormControl.disable();
        }
        else {
            this.searchFormControl.enable();
        }
    }
    static { this.ɵfac = function SearchV4Component_Factory(t) { return new (t || SearchV4Component)(i0.ɵɵdirectiveInject(i0.Injector)); }; }
    static { this.ɵcmp = /*@__PURE__*/ i0.ɵɵdefineComponent({ type: SearchV4Component, selectors: [["fusion-search"]], hostAttrs: [1, "fusion-v4"], inputs: { placeholder: "placeholder", size: "size", testId: "testId" }, standalone: true, features: [i0.ɵɵProvidersFeature([{ provide: NG_VALUE_ACCESSOR, useExisting: forwardRef(() => SearchV4Component), multi: true }]), i0.ɵɵStandaloneFeature], decls: 1, vars: 6, consts: [[3, "formControl", "startIcon", "showClear", "placeholder", "size", "testId"]], template: function SearchV4Component_Template(rf, ctx) { if (rf & 1) {
            i0.ɵɵelement(0, "fusion-input", 0);
        } if (rf & 2) {
            i0.ɵɵproperty("formControl", ctx.searchFormControl)("startIcon", ctx.searchIcon)("showClear", true)("placeholder", ctx.placeholder)("size", ctx.size)("testId", ctx.testId);
        } }, dependencies: [CommonModule, ReactiveFormsModule, i1.NgControlStatus, i1.FormControlDirective, InputComponent], styles: ["[_nghost-%COMP%]{margin:0;padding:0;display:flex}[_nghost-%COMP%]   fusion-input[_ngcontent-%COMP%]{width:100%}"], changeDetection: 0 }); }
}
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(SearchV4Component, [{
        type: Component,
        args: [{ selector: 'fusion-search', standalone: true, imports: [CommonModule, ReactiveFormsModule, InputComponent, GenericPipe], host: { class: 'fusion-v4' }, changeDetection: ChangeDetectionStrategy.OnPush, providers: [{ provide: NG_VALUE_ACCESSOR, useExisting: forwardRef(() => SearchV4Component), multi: true }], template: "<fusion-input\n    [formControl]=\"searchFormControl\"\n    [startIcon]=\"searchIcon\"\n    [showClear]=\"true\"\n    [placeholder]=\"placeholder\"\n    [size]=\"size\"\n    [testId]=\"testId\"\n></fusion-input>\n\n", styles: [":host{margin:0;padding:0;display:flex}:host fusion-input{width:100%}\n"] }]
    }], () => [{ type: i0.Injector }], { placeholder: [{
            type: Input
        }], size: [{
            type: Input
        }], testId: [{
            type: Input
        }] }); })();
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassDebugInfo(SearchV4Component, { className: "SearchV4Component", filePath: "search-v4.component.ts", lineNumber: 20 }); })();

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

export { SearchV4Component as SearchComponent };
//# sourceMappingURL=ironsource-fusion-ui-components-search-v4.mjs.map
