var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
import { serializable } from "../../engine/engine_serialization_decorator.js";
import { FrameEvent } from "../../engine/engine_setup.js";
import { Behaviour, GameObject } from "../Component.js";
import { BaseUIComponent } from "./BaseUIComponent.js";
/**
 * [CanvasGroup](https://engine.needle.tools/docs/api/CanvasGroup) is a UI component that allows you to control the transparency and interactivity of a group of UI elements.
 * By adjusting the alpha property, you can fade in or out all child UI elements simultaneously.
 * The interactable and blocksRaycasts properties let you enable or disable user interaction for the entire group.
 * @summary Group UI elements to control transparency and interactivity
 * @category User Interface
 * @group Components
 */
export class CanvasGroup extends Behaviour {
    get alpha() {
        return this._alpha;
    }
    set alpha(val) {
        if (val === this._alpha)
            return;
        this._alpha = val;
        this.markDirty();
    }
    get isCanvasGroup() { return true; }
    _alpha = 1;
    interactable = true;
    blocksRaycasts = true;
    _isDirty = false;
    markDirty() {
        if (this._isDirty)
            return;
        this._isDirty = true;
        this.startCoroutine(this.applyChangesDelayed(), FrameEvent.OnBeforeRender);
    }
    *applyChangesDelayed() {
        this._isDirty = false;
        this.applyChangesNow();
    }
    _buffer = [];
    applyChangesNow() {
        this._buffer.length = 0;
        for (const ch of GameObject.getComponentsInChildren(this.gameObject, BaseUIComponent, this._buffer)) {
            const hasAlphaFactor = ch;
            if (hasAlphaFactor.setAlphaFactor)
                hasAlphaFactor.setAlphaFactor(this._alpha);
        }
    }
}
__decorate([
    serializable()
], CanvasGroup.prototype, "alpha", null);
__decorate([
    serializable()
], CanvasGroup.prototype, "interactable", void 0);
__decorate([
    serializable()
], CanvasGroup.prototype, "blocksRaycasts", void 0);
//# sourceMappingURL=CanvasGroup.js.map