import * as i0 from '@angular/core';
import { EventEmitter, Directive, Input, Output, HostBinding } from '@angular/core';
import * as i2 from '@angular/platform-browser';
import * as i1 from '@ironsource/fusion-ui/services/unique-id';
import { isNullOrUndefined } from '@ironsource/fusion-ui/utils';

class CheckboxBaseComponent {
    get toolTip() {
        return this.tooltipContent ? this.tooltipContent : this.class && this.class.indexOf('truncate') > -1 ? this.label : '';
    }
    constructor(uniqueIdService, cd, sanitizer) {
        this.uniqueIdService = uniqueIdService;
        this.cd = cd;
        this.sanitizer = sanitizer;
        /** @internal */
        this.changed = new EventEmitter();
        /** @internal */
        this.isOnlyCheckbox = false;
        // 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 = () => { };
    }
    ngOnInit() {
        const unique = this.uniqueIdService.getUniqueId();
        this.id = this.id || 'is-checkboxes-' + unique;
        this.checked = this.checked || false;
        // this.isDisabled = this.isDisabled || false;
        this.label = this.label || '';
        this.value = this.value || '';
        this.isOnlyCheckbox = !this.label && !this.icon && !this.flag;
    }
    /** @ignore */
    change(event) {
        this.propagateTouched();
        this.checked = event.target.checked;
        this.propagateChange(this.checked);
        this.changed.emit(this.checked);
    }
    /**
     * update value from model to the component
     * @ignore
     */
    writeValue(value) {
        if (value === undefined || value === null) {
            this.checked = false;
        }
        else {
            this.checked = value;
        }
        if (!this.cd.destroyed) {
            this.cd.detectChanges();
        }
    }
    /**
     * 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(isDisabled) {
        if (isNullOrUndefined(this.isDisabled)) {
            this.isDisabledForm = isDisabled;
            this.cd.detectChanges();
        }
    }
    static { this.ɵfac = function CheckboxBaseComponent_Factory(t) { return new (t || CheckboxBaseComponent)(i0.ɵɵdirectiveInject(i1.UniqueIdService), i0.ɵɵdirectiveInject(i0.ChangeDetectorRef), i0.ɵɵdirectiveInject(i2.DomSanitizer)); }; }
    static { this.ɵdir = /*@__PURE__*/ i0.ɵɵdefineDirective({ type: CheckboxBaseComponent, hostVars: 2, hostBindings: function CheckboxBaseComponent_HostBindings(rf, ctx) { if (rf & 2) {
            i0.ɵɵclassProp("only-checkbox", ctx.isOnlyCheckbox);
        } }, inputs: { label: "label", name: "name", value: "value", icon: "icon", flag: "flag", isDisabled: "isDisabled", checked: "checked", isIndeterminate: "isIndeterminate", id: "id", class: "class", backgroundColor: "backgroundColor", tooltipContent: "tooltipContent", tooltipWidth: "tooltipWidth" }, outputs: { changed: "changed" } }); }
}
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(CheckboxBaseComponent, [{
        type: Directive
    }], () => [{ type: i1.UniqueIdService }, { type: i0.ChangeDetectorRef }, { type: i2.DomSanitizer }], { label: [{
            type: Input
        }], name: [{
            type: Input
        }], value: [{
            type: Input
        }], icon: [{
            type: Input
        }], flag: [{
            type: Input
        }], isDisabled: [{
            type: Input
        }], checked: [{
            type: Input
        }], isIndeterminate: [{
            type: Input
        }], id: [{
            type: Input
        }], class: [{
            type: Input
        }], backgroundColor: [{
            type: Input
        }], tooltipContent: [{
            type: Input
        }], tooltipWidth: [{
            type: Input
        }], changed: [{
            type: Output
        }], isOnlyCheckbox: [{
            type: HostBinding,
            args: ['class.only-checkbox']
        }] }); })();

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

export { CheckboxBaseComponent };
//# sourceMappingURL=ironsource-fusion-ui-components-checkbox-common-base.mjs.map
