import * as i0 from '@angular/core';
import { Directive, Input, HostBinding, ViewContainerRef, inject } from '@angular/core';
import { BehaviorSubject } from 'rxjs';
import * as i1 from '@ironsource/fusion-ui/components/dropdown/service';
import { DropdownTestIdModifiers } from '@ironsource/fusion-ui/entities';
import { TestIdsService } from '@ironsource/fusion-ui/services/test-ids';

class DropdownOptionBaseComponent {
    /** @internal */
    set isMultiRawDisplay(value) {
        this.isMultiRawDisplay$.next(value);
    }
    /** @internal */
    set optionCloseIcon(value) {
        this.shownCloseIcon$.next(value);
    }
    /** @internal */
    get shouldDisplayMultiRaw() {
        return this.isMultiRawDisplay$.getValue();
    }
    /** @internal */
    get hasChildren() {
        return Array.isArray(this.option?.childOptions);
    }
    /** @internal */
    get isOpen() {
        return this.option?.isOpen;
    }
    get testAttribute() {
        return this.testId;
    }
    constructor(dropdownService, injector) {
        this.dropdownService = dropdownService;
        this.injector = injector;
        this.testIdDropdownModifiers = DropdownTestIdModifiers;
        this.testIdsService = this.injector.get(TestIdsService);
        /** @internal */
        this.isMultiRawDisplay$ = new BehaviorSubject(false);
        /** @internal */
        this.shownCloseIcon$ = new BehaviorSubject(false);
        /** @internal */
        this.optionToStringFunc = this.dropdownService.optionToString.bind(this.dropdownService);
    }
    ngOnInit() {
        this.settings = {
            dropdownType: this.dropdownType,
            lastSearchValue: this.lastSearchValue
        };
    }
    static { this.ɵfac = function DropdownOptionBaseComponent_Factory(t) { return new (t || DropdownOptionBaseComponent)(i0.ɵɵdirectiveInject(i1.DropdownService), i0.ɵɵdirectiveInject(i0.Injector)); }; }
    static { this.ɵdir = /*@__PURE__*/ i0.ɵɵdefineDirective({ type: DropdownOptionBaseComponent, hostVars: 7, hostBindings: function DropdownOptionBaseComponent_HostBindings(rf, ctx) { if (rf & 2) {
            i0.ɵɵattribute("data-testid", ctx.testAttribute);
            i0.ɵɵclassProp("multi-raw-display", ctx.shouldDisplayMultiRaw)("is-has-children", ctx.hasChildren)("is-open", ctx.isOpen);
        } }, inputs: { option: "option", mappingOptions: "mappingOptions", dropdownType: "dropdownType", lastSearchValue: "lastSearchValue", optionRightHoverText: "optionRightHoverText", isMultiRawDisplay: "isMultiRawDisplay", optionCloseIcon: "optionCloseIcon", testId: "testId" } }); }
}
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(DropdownOptionBaseComponent, [{
        type: Directive
    }], () => [{ type: i1.DropdownService }, { type: i0.Injector }], { option: [{
            type: Input
        }], mappingOptions: [{
            type: Input
        }], dropdownType: [{
            type: Input
        }], lastSearchValue: [{
            type: Input
        }], optionRightHoverText: [{
            type: Input
        }], isMultiRawDisplay: [{
            type: Input
        }], optionCloseIcon: [{
            type: Input
        }], testId: [{
            type: Input
        }], shouldDisplayMultiRaw: [{
            type: HostBinding,
            args: ['class.multi-raw-display']
        }], hasChildren: [{
            type: HostBinding,
            args: ['class.is-has-children']
        }], isOpen: [{
            type: HostBinding,
            args: ['class.is-open']
        }], testAttribute: [{
            type: HostBinding,
            args: ['attr.data-testid']
        }] }); })();

class DropdownOptionBaseDirective {
    constructor(renderer) {
        this.renderer = renderer;
        this.isMultiRawDisplay = false;
        this.optionClass = true;
        this.isOptionHidden = false;
        this.viewContainerRef = inject(ViewContainerRef);
    }
    ngOnInit() {
        this.isOptionHidden = this.fusionDropdownOption.checked;
        this.viewContainerRef.clear();
        this.optionComponentRef = this.viewContainerRef.createComponent(this.dropdownOptionComponentType);
        this.updateData();
        const loaderViewRef = this.optionComponentRef.hostView;
        this.renderer.appendChild(this.viewContainerRef.element.nativeElement, loaderViewRef.rootNodes[0]);
    }
    ngOnChanges(changes) {
        this.isOptionHidden = this.fusionDropdownOption.checked;
        if (this.optionComponentRef && this.optionComponentRef.instance) {
            this.updateData();
        }
    }
    updateData() {
        this.optionComponentRef.instance.option = this.fusionDropdownOption;
        this.optionComponentRef.instance.mappingOptions = this.mappingOptions;
        this.optionComponentRef.instance.dropdownType = this.dropdownType;
        this.optionComponentRef.instance.lastSearchValue = this.lastSearchValue;
        this.optionComponentRef.instance.optionRightHoverText = this.optionRightHoverText;
        this.optionComponentRef.instance.isMultiRawDisplay = this.isMultiRawDisplay;
        this.optionComponentRef.instance.optionCloseIcon = this.optionCloseIcon;
    }
    static { this.ɵfac = function DropdownOptionBaseDirective_Factory(t) { return new (t || DropdownOptionBaseDirective)(i0.ɵɵdirectiveInject(i0.Renderer2)); }; }
    static { this.ɵdir = /*@__PURE__*/ i0.ɵɵdefineDirective({ type: DropdownOptionBaseDirective, hostVars: 4, hostBindings: function DropdownOptionBaseDirective_HostBindings(rf, ctx) { if (rf & 2) {
            i0.ɵɵclassProp("option", ctx.optionClass)("is-hidden", ctx.isOptionHidden);
        } }, inputs: { fusionDropdownOption: "fusionDropdownOption", mappingOptions: "mappingOptions", dropdownType: "dropdownType", lastSearchValue: "lastSearchValue", optionRightHoverText: "optionRightHoverText", isMultiRawDisplay: "isMultiRawDisplay", optionCloseIcon: "optionCloseIcon" }, features: [i0.ɵɵNgOnChangesFeature] }); }
}
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(DropdownOptionBaseDirective, [{
        type: Directive
    }], () => [{ type: i0.Renderer2 }], { fusionDropdownOption: [{
            type: Input
        }], mappingOptions: [{
            type: Input
        }], dropdownType: [{
            type: Input
        }], lastSearchValue: [{
            type: Input
        }], optionRightHoverText: [{
            type: Input
        }], isMultiRawDisplay: [{
            type: Input
        }], optionCloseIcon: [{
            type: Input
        }], optionClass: [{
            type: HostBinding,
            args: ['class.option']
        }], isOptionHidden: [{
            type: HostBinding,
            args: ['class.is-hidden']
        }] }); })();

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

export { DropdownOptionBaseComponent, DropdownOptionBaseDirective };
//# sourceMappingURL=ironsource-fusion-ui-components-dropdown-option-common-base.mjs.map
