import { ChangeDetectionStrategy, ChangeDetectorRef, Component, EventEmitter, forwardRef, Input, Output } from '@angular/core';
import { NG_VALUE_ACCESSOR } from '@angular/forms';
import { isNullOrUndefined } from '@ironsource/fusion-ui/utils';
import { UniqueIdService } from '@ironsource/fusion-ui/services/unique-id';
import * as i0 from "@angular/core";
import * as i1 from "@ironsource/fusion-ui/services/unique-id";
import * as i2 from "@angular/common";
const _c0 = a0 => ({ "fu-selected": a0 });
function SwitcherComponent_div_1_Template(rf, ctx) { if (rf & 1) {
    const _r3 = i0.ɵɵgetCurrentView();
    i0.ɵɵelementStart(0, "div", 1)(1, "input", 2);
    i0.ɵɵlistener("change", function SwitcherComponent_div_1_Template_input_change_1_listener() { const restoredCtx = i0.ɵɵrestoreView(_r3); const item_r1 = restoredCtx.$implicit; const ctx_r2 = i0.ɵɵnextContext(); return i0.ɵɵresetView(ctx_r2.setSelection(item_r1)); });
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(2, "label", 3);
    i0.ɵɵtext(3);
    i0.ɵɵelementEnd()();
} if (rf & 2) {
    const item_r1 = ctx.$implicit;
    const ctx_r0 = i0.ɵɵnextContext();
    i0.ɵɵclassMap("fu-size-" + ctx_r0.switcherConfiguration.size);
    i0.ɵɵproperty("ngClass", i0.ɵɵpureFunction1(11, _c0, (ctx_r0.selected == null ? null : ctx_r0.selected.id) === (item_r1 == null ? null : item_r1.id)));
    i0.ɵɵadvance();
    i0.ɵɵpropertyInterpolate2("id", "", ctx_r0.switcherConfiguration.name, "_", item_r1.id, "");
    i0.ɵɵproperty("name", ctx_r0.switcherConfiguration.name)("checked", (ctx_r0.selected == null ? null : ctx_r0.selected.id) === (item_r1 == null ? null : item_r1.id));
    i0.ɵɵadvance();
    i0.ɵɵpropertyInterpolate2("for", "", ctx_r0.switcherConfiguration.name, "_", item_r1.id, "");
    i0.ɵɵpropertyInterpolate("title", item_r1.title);
    i0.ɵɵadvance();
    i0.ɵɵtextInterpolate(item_r1.title);
} }
export class SwitcherComponent {
    /**
     * Configuration:
     * type SwitcherConfiguration = {
     *     name?: string;
     *     size?: 'large';
     * };
     */
    set configuration(value) {
        if (value) {
            this.switcherConfiguration = { ...this.switcherConfiguration, ...value };
        }
    }
    constructor(uniqueService, changeDetectorRef) {
        this.uniqueService = uniqueService;
        this.changeDetectorRef = changeDetectorRef;
        /**
         * Switcher options: interface SwitcherItem {
         *     id: number | string;
         *     title: string;
         * }
         */
        this.options = [];
        /**
         * On selection changed. But better use formControl
         * @internal
         */
        this.selectedChange = new EventEmitter();
        /** @internal */
        this.switcherConfiguration = { name: '', size: 'small' };
        /** @internal */
        this.propagateChange = (_) => { };
        /** @internal */
        this.propagateTouched = () => { };
    }
    ngOnInit() {
        const uniq = this.uniqueService.getUniqueId();
        this.switcherConfiguration.name = this.switcherConfiguration.name || `fu-switcher-${uniq}`;
        this.id = `fuSwitcher${uniq}`;
    }
    /** @internal */
    isSelected(item) {
        if (isNullOrUndefined(this.selected) || isNullOrUndefined(this.selected.id)) {
            return false;
        }
        return item.id === this.selected.id;
    }
    /** @internal */
    setSelection(selected) {
        this.propagateTouched();
        if (!isNullOrUndefined(this.selected) && !isNullOrUndefined(this.selected.id) && selected.id === this.selected.id) {
            return;
        }
        this.selected = selected;
        this.propagateChange({ ...selected });
        this.selectedChange.emit({ ...selected });
    }
    /** @internal */
    writeValue(value) {
        this.selected = isNullOrUndefined(value) ? { id: '', title: '' } : value;
        this.changeDetectorRef.markForCheck();
    }
    /** @ignore */
    registerOnChange(fn) {
        this.propagateChange = fn;
    }
    /** @ignore */
    registerOnTouched(fn) {
        this.propagateTouched = fn;
    }
    static { this.ɵfac = function SwitcherComponent_Factory(t) { return new (t || SwitcherComponent)(i0.ɵɵdirectiveInject(i1.UniqueIdService), i0.ɵɵdirectiveInject(i0.ChangeDetectorRef)); }; }
    static { this.ɵcmp = /*@__PURE__*/ i0.ɵɵdefineComponent({ type: SwitcherComponent, selectors: [["fusion-switcher"]], inputs: { configuration: "configuration", options: "options" }, outputs: { selectedChange: "selectedChange" }, features: [i0.ɵɵProvidersFeature([
                {
                    provide: NG_VALUE_ACCESSOR,
                    useExisting: forwardRef(() => SwitcherComponent),
                    multi: true
                }
            ])], decls: 2, vars: 3, consts: [["class", "fu-switcher-holder", 3, "class", "ngClass", 4, "ngFor", "ngForOf"], [1, "fu-switcher-holder", 3, "ngClass"], ["type", "radio", 3, "id", "name", "checked", "change"], [3, "for", "title"]], template: function SwitcherComponent_Template(rf, ctx) { if (rf & 1) {
            i0.ɵɵelementStart(0, "div");
            i0.ɵɵtemplate(1, SwitcherComponent_div_1_Template, 4, 13, "div", 0);
            i0.ɵɵelementEnd();
        } if (rf & 2) {
            i0.ɵɵclassMap("fu-switcher " + "fu-size-" + ctx.switcherConfiguration.size);
            i0.ɵɵadvance();
            i0.ɵɵproperty("ngForOf", ctx.options);
        } }, dependencies: [i2.NgClass, i2.NgForOf], styles: ["@font-face{font-family:NHaasGroteskDSPro;src:url(https://fusion.ironsrc.net/assets/fonts/NHaasGroteskDSPro-75Bd.eot);src:url(https://fusion.ironsrc.net/assets/fonts/NHaasGroteskDSPro-75Bd.eot?#iefix) format(\"embedded-opentype\"),url(https://fusion.ironsrc.net/assets/fonts/NHaasGroteskDSPro-75Bd.woff2) format(\"woff2\"),url(https://fusion.ironsrc.net/assets/fonts/NHaasGroteskDSPro-75Bd.woff) format(\"woff\"),url(https://fusion.ironsrc.net/assets/fonts/NHaasGroteskDSPro-75Bd.ttf) format(\"truetype\")}@font-face{font-family:NHaasGroteskDSPro-65Md;src:url(https://fusion.ironsrc.net/assets/fonts/NHaasGroteskDSPro-65Md.eot);src:url(https://fusion.ironsrc.net/assets/fonts/NHaasGroteskDSPro-65Md.eot?#iefix) format(\"embedded-opentype\"),url(https://fusion.ironsrc.net/assets/fonts/NHaasGroteskDSPro-65Md.woff2) format(\"woff2\"),url(https://fusion.ironsrc.net/assets/fonts/NHaasGroteskDSPro-65Md.woff) format(\"woff\"),url(https://fusion.ironsrc.net/assets/fonts/NHaasGroteskDSPro-65Md.ttf) format(\"truetype\")}@font-face{font-family:HelveticaNeue;src:url(https://fusion.ironsrc.net/assets/fonts/HelveticaNeue.eot);src:url(https://fusion.ironsrc.net/assets/fonts/HelveticaNeue.eot?#iefix) format(\"embedded-opentype\"),url(https://fusion.ironsrc.net/assets/fonts/HelveticaNeue.woff2) format(\"woff2\"),url(https://fusion.ironsrc.net/assets/fonts/HelveticaNeue.woff) format(\"woff\"),url(https://fusion.ironsrc.net/assets/fonts/HelveticaNeue.ttf) format(\"truetype\")}@font-face{font-family:HelveticaNeue-Medium;src:url(https://fusion.ironsrc.net/assets/fonts/HelveticaNeue-Medium.eot);src:url(https://fusion.ironsrc.net/assets/fonts/HelveticaNeue-Medium.eot?#iefix) format(\"embedded-opentype\"),url(https://fusion.ironsrc.net/assets/fonts/HelveticaNeue-Medium.woff2) format(\"woff2\"),url(https://fusion.ironsrc.net/assets/fonts/HelveticaNeue-Medium.woff) format(\"woff\"),url(https://fusion.ironsrc.net/assets/fonts/HelveticaNeue-Medium.ttf) format(\"truetype\")}.font-heading-6[_ngcontent-%COMP%], .font-heading-5[_ngcontent-%COMP%], .font-heading-4[_ngcontent-%COMP%], .font-heading-3[_ngcontent-%COMP%], .font-heading-2[_ngcontent-%COMP%], .font-heading-1[_ngcontent-%COMP%]{font-family:NHaasGroteskDSPro,sans-serif}.font-heading-1[_ngcontent-%COMP%]{font-size:60px}.font-heading-2[_ngcontent-%COMP%]{font-size:32px}.font-heading-3[_ngcontent-%COMP%]{font-size:22px}.font-heading-4[_ngcontent-%COMP%]{font-size:18px}.font-heading-5[_ngcontent-%COMP%]{font-size:15px}.font-heading-6[_ngcontent-%COMP%]{font-size:13px}.font-heading-label[_ngcontent-%COMP%]{font-size:11px;font-family:NHaasGroteskDSPro-65Md,sans-serif;letter-spacing:.25px}.font-caption[_ngcontent-%COMP%], [_nghost-%COMP%]   .fu-switcher[_ngcontent-%COMP%]   .fu-switcher-holder[_ngcontent-%COMP%]   input[type=radio][_ngcontent-%COMP%] + label[_ngcontent-%COMP%], .font-bodyXSmall[_ngcontent-%COMP%], .font-bodySmall[_ngcontent-%COMP%], .font-bodyMedium[_ngcontent-%COMP%], .font-bodyLarge[_ngcontent-%COMP%]{font-family:HelveticaNeue,helvetica,sans-serif;line-height:1.5}.font-bodyXSmallStrong[_ngcontent-%COMP%], .font-bodySmallStrong[_ngcontent-%COMP%], .font-bodyMediumStrong[_ngcontent-%COMP%], .font-bodyLargeStrong[_ngcontent-%COMP%]{font-family:HelveticaNeue-Medium,helvetica,sans-serif;line-height:1.5}.font-bodyLarge[_ngcontent-%COMP%], .font-bodyLargeStrong[_ngcontent-%COMP%]{font-size:16px}.font-bodyMedium[_ngcontent-%COMP%], .font-bodyMediumStrong[_ngcontent-%COMP%]{font-size:14px}.font-bodySmall[_ngcontent-%COMP%], .font-bodySmallStrong[_ngcontent-%COMP%]{font-size:13px;letter-spacing:.24px}[_nghost-%COMP%]   .fu-switcher[_ngcontent-%COMP%]   .fu-switcher-holder[_ngcontent-%COMP%]   input[type=radio][_ngcontent-%COMP%] + label[_ngcontent-%COMP%], .font-bodyXSmall[_ngcontent-%COMP%]{font-size:12px;letter-spacing:.24px}.font-bodyXSmallStrong[_ngcontent-%COMP%]{font-size:12px;letter-spacing:.24px}.font-caption[_ngcontent-%COMP%]{font-size:11px}[_nghost-%COMP%]{display:flex;flex-direction:row;align-items:flex-start}[_nghost-%COMP%]   *[_ngcontent-%COMP%]{box-sizing:border-box}[_nghost-%COMP%]   .fu-switcher[_ngcontent-%COMP%]{background-color:var(--fu-light-100, #F1F3F4);height:32px;min-width:96px;display:flex;flex-direction:row;align-items:flex-start;padding:4px;border-radius:8px;gap:4px}[_nghost-%COMP%]   .fu-switcher.fu-size-large[_ngcontent-%COMP%]{height:40px}[_nghost-%COMP%]   .fu-switcher[_ngcontent-%COMP%]   .fu-switcher-holder[_ngcontent-%COMP%]{display:flex;flex-direction:row;justify-content:center;align-items:center;gap:10px;border-radius:8px;height:24px;color:var(--fu-black-500, #53575B);background-color:var(--fu-light-100, #F1F3F4)}[_nghost-%COMP%]   .fu-switcher[_ngcontent-%COMP%]   .fu-switcher-holder.fu-size-large[_ngcontent-%COMP%]{height:32px}[_nghost-%COMP%]   .fu-switcher[_ngcontent-%COMP%]   .fu-switcher-holder[_ngcontent-%COMP%]   input[type=radio][_ngcontent-%COMP%]{display:none}[_nghost-%COMP%]   .fu-switcher[_ngcontent-%COMP%]   .fu-switcher-holder[_ngcontent-%COMP%]   input[type=radio][_ngcontent-%COMP%] + label[_ngcontent-%COMP%]{text-align:center;line-height:14.32px;letter-spacing:.24px;display:inherit;padding:7px 8px}[_nghost-%COMP%]   .fu-switcher[_ngcontent-%COMP%]   .fu-switcher-holder[_ngcontent-%COMP%]:hover{background-color:var(--fu-light-300, #E5E7E9)}[_nghost-%COMP%]   .fu-switcher[_ngcontent-%COMP%]   .fu-switcher-holder[_ngcontent-%COMP%]:hover   label[_ngcontent-%COMP%]{cursor:pointer}[_nghost-%COMP%]   .fu-switcher[_ngcontent-%COMP%]   .fu-switcher-holder[_ngcontent-%COMP%]:hover.fu-selected   label[_ngcontent-%COMP%]{cursor:default}[_nghost-%COMP%]   .fu-switcher[_ngcontent-%COMP%]   .fu-switcher-holder.fu-selected[_ngcontent-%COMP%]{background-color:var(--fu-white, #ffffff);color:var(--fu-black-500, #53575B);border-radius:8px;box-shadow:0 0 1px #0003}"], changeDetection: 0 }); }
}
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(SwitcherComponent, [{
        type: Component,
        args: [{ selector: 'fusion-switcher', changeDetection: ChangeDetectionStrategy.OnPush, providers: [
                    {
                        provide: NG_VALUE_ACCESSOR,
                        useExisting: forwardRef(() => SwitcherComponent),
                        multi: true
                    }
                ], template: "<div [class]=\"'fu-switcher ' + 'fu-size-' + switcherConfiguration.size\">\n    <div class=\"fu-switcher-holder\" *ngFor=\"let item of options\" [class]=\"'fu-size-' + switcherConfiguration.size\" [ngClass]=\"{'fu-selected': selected?.id === item?.id}\">\n        <input\n            type=\"radio\"\n            id=\"{{ switcherConfiguration.name }}_{{ item.id }}\"\n            [name]=\"switcherConfiguration.name\"\n            [checked]=\"selected?.id === item?.id\"\n            (change)=\"setSelection(item)\"\n        />\n        <label for=\"{{ switcherConfiguration.name }}_{{ item.id }}\" title=\"{{ item.title }}\">{{ item.title }}</label>\n    </div>\n</div>\n\n\n", styles: ["@font-face{font-family:NHaasGroteskDSPro;src:url(https://fusion.ironsrc.net/assets/fonts/NHaasGroteskDSPro-75Bd.eot);src:url(https://fusion.ironsrc.net/assets/fonts/NHaasGroteskDSPro-75Bd.eot?#iefix) format(\"embedded-opentype\"),url(https://fusion.ironsrc.net/assets/fonts/NHaasGroteskDSPro-75Bd.woff2) format(\"woff2\"),url(https://fusion.ironsrc.net/assets/fonts/NHaasGroteskDSPro-75Bd.woff) format(\"woff\"),url(https://fusion.ironsrc.net/assets/fonts/NHaasGroteskDSPro-75Bd.ttf) format(\"truetype\")}@font-face{font-family:NHaasGroteskDSPro-65Md;src:url(https://fusion.ironsrc.net/assets/fonts/NHaasGroteskDSPro-65Md.eot);src:url(https://fusion.ironsrc.net/assets/fonts/NHaasGroteskDSPro-65Md.eot?#iefix) format(\"embedded-opentype\"),url(https://fusion.ironsrc.net/assets/fonts/NHaasGroteskDSPro-65Md.woff2) format(\"woff2\"),url(https://fusion.ironsrc.net/assets/fonts/NHaasGroteskDSPro-65Md.woff) format(\"woff\"),url(https://fusion.ironsrc.net/assets/fonts/NHaasGroteskDSPro-65Md.ttf) format(\"truetype\")}@font-face{font-family:HelveticaNeue;src:url(https://fusion.ironsrc.net/assets/fonts/HelveticaNeue.eot);src:url(https://fusion.ironsrc.net/assets/fonts/HelveticaNeue.eot?#iefix) format(\"embedded-opentype\"),url(https://fusion.ironsrc.net/assets/fonts/HelveticaNeue.woff2) format(\"woff2\"),url(https://fusion.ironsrc.net/assets/fonts/HelveticaNeue.woff) format(\"woff\"),url(https://fusion.ironsrc.net/assets/fonts/HelveticaNeue.ttf) format(\"truetype\")}@font-face{font-family:HelveticaNeue-Medium;src:url(https://fusion.ironsrc.net/assets/fonts/HelveticaNeue-Medium.eot);src:url(https://fusion.ironsrc.net/assets/fonts/HelveticaNeue-Medium.eot?#iefix) format(\"embedded-opentype\"),url(https://fusion.ironsrc.net/assets/fonts/HelveticaNeue-Medium.woff2) format(\"woff2\"),url(https://fusion.ironsrc.net/assets/fonts/HelveticaNeue-Medium.woff) format(\"woff\"),url(https://fusion.ironsrc.net/assets/fonts/HelveticaNeue-Medium.ttf) format(\"truetype\")}.font-heading-6,.font-heading-5,.font-heading-4,.font-heading-3,.font-heading-2,.font-heading-1{font-family:NHaasGroteskDSPro,sans-serif}.font-heading-1{font-size:60px}.font-heading-2{font-size:32px}.font-heading-3{font-size:22px}.font-heading-4{font-size:18px}.font-heading-5{font-size:15px}.font-heading-6{font-size:13px}.font-heading-label{font-size:11px;font-family:NHaasGroteskDSPro-65Md,sans-serif;letter-spacing:.25px}.font-caption,:host .fu-switcher .fu-switcher-holder input[type=radio]+label,.font-bodyXSmall,.font-bodySmall,.font-bodyMedium,.font-bodyLarge{font-family:HelveticaNeue,helvetica,sans-serif;line-height:1.5}.font-bodyXSmallStrong,.font-bodySmallStrong,.font-bodyMediumStrong,.font-bodyLargeStrong{font-family:HelveticaNeue-Medium,helvetica,sans-serif;line-height:1.5}.font-bodyLarge,.font-bodyLargeStrong{font-size:16px}.font-bodyMedium,.font-bodyMediumStrong{font-size:14px}.font-bodySmall,.font-bodySmallStrong{font-size:13px;letter-spacing:.24px}:host .fu-switcher .fu-switcher-holder input[type=radio]+label,.font-bodyXSmall{font-size:12px;letter-spacing:.24px}.font-bodyXSmallStrong{font-size:12px;letter-spacing:.24px}.font-caption{font-size:11px}:host{display:flex;flex-direction:row;align-items:flex-start}:host *{box-sizing:border-box}:host .fu-switcher{background-color:var(--fu-light-100, #F1F3F4);height:32px;min-width:96px;display:flex;flex-direction:row;align-items:flex-start;padding:4px;border-radius:8px;gap:4px}:host .fu-switcher.fu-size-large{height:40px}:host .fu-switcher .fu-switcher-holder{display:flex;flex-direction:row;justify-content:center;align-items:center;gap:10px;border-radius:8px;height:24px;color:var(--fu-black-500, #53575B);background-color:var(--fu-light-100, #F1F3F4)}:host .fu-switcher .fu-switcher-holder.fu-size-large{height:32px}:host .fu-switcher .fu-switcher-holder input[type=radio]{display:none}:host .fu-switcher .fu-switcher-holder input[type=radio]+label{text-align:center;line-height:14.32px;letter-spacing:.24px;display:inherit;padding:7px 8px}:host .fu-switcher .fu-switcher-holder:hover{background-color:var(--fu-light-300, #E5E7E9)}:host .fu-switcher .fu-switcher-holder:hover label{cursor:pointer}:host .fu-switcher .fu-switcher-holder:hover.fu-selected label{cursor:default}:host .fu-switcher .fu-switcher-holder.fu-selected{background-color:var(--fu-white, #ffffff);color:var(--fu-black-500, #53575B);border-radius:8px;box-shadow:0 0 1px #0003}\n"] }]
    }], () => [{ type: i1.UniqueIdService }, { type: i0.ChangeDetectorRef }], { configuration: [{
            type: Input
        }], options: [{
            type: Input
        }], selectedChange: [{
            type: Output
        }] }); })();
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassDebugInfo(SwitcherComponent, { className: "SwitcherComponent", filePath: "switcher.component.ts", lineNumber: 20 }); })();
//# sourceMappingURL=data:application/json;base64, 