//const log$8 = new Logger("effectManager");
import TimeoutError from "./error/TimeoutError.js"

export default class XverseEffect extends EventEmitter {
    constructor({id: e, jsonPath: t, type: r, room: n, scale: o=1}) {
        super();
        E(this, "_id");
        E(this, "type");
        E(this, "effect");
        E(this, "avatarEffect");
        E(this, "_room");
        E(this, "_isLoading", !0);
        E(this, "_failed", !1);
        E(this, "_scale", 1);
        this._room = n,
        this._id = e,
        this.type = r,
        this._scale = o,
        this.effect = e === "Rain" || e === "Boom" ? new XRain(this._room.scene,t,urlTransformer) : r === IEffectType.Sequence ? new XSequence(this._room.scene,t,"",urlTransformer) : new XSubSequence(this._room.scene,t,urlTransformer),
        this.avatarEffect = new XSubSequence(this._room.scene,t,urlTransformer)
    }
    get failed() {
        return this._failed
    }
    get position() {
        if (this.type !== IEffectType.Sequence)
            return this.effect.position
    }
    get rotation() {
        if (this.type !== IEffectType.Sequence)
            return this.effect.rotation
    }
    get isLoading() {
        return this._isLoading
    }
    get id() {
        return this._id
    }
    get name() {
        return this.effect.name
    }
    get isPlaying() {
        var e;
        return !!((e = this.effect) != null && e.isPlaying)
    }
    async init() {
        try {
            await this.effect.init()._timeout(1e4, new TimeoutError("effect init timeout(10s)")),
            this._isLoading = !1,
            this._failed = !1
        } catch (e) {
            throw this._isLoading = !1,
            this._failed = !0,
            log$8.error(`effect: ${this.id} init error`, e),
            e
        }
    }
    play(e=!1) {
        return new Promise((t,r)=>{
            this.effect.play(e),
            this.isPlaying ? t() : r(`play effect: ${this.name} failed`)
        }
        )
    }
    hide() {
        return this.effect.hide()
    }
    show() {
        return this.effect.show()
    }
    setRotation(e) {
        var t;
        return this.type === IEffectType.Sequence ? Promise.reject("setRotation failed, sequence unSuported") : (t = this.effect) == null ? void 0 : t.setRotation(e)
    }
    setPosition(e) {
        var t;
        return this.type === IEffectType.Sequence ? Promise.reject("setPosition failed, sequence unSuported") : (t = this.effect) == null ? void 0 : t.setPosition(e)
    }
    setScaling(e) {
        var t;
        return this.type === IEffectType.Sequence ? Promise.reject("setScaling failed, sequence unSuported") : (this._scale = e,
        (t = this.effect) == null ? void 0 : t.setScaling({
            x: e,
            y: e,
            z: e
        }))
    }
    dispose() {
        this.effect.dispose()
    }
}