import { Assets, utils } from "pixi.js";
import { HitSprite } from "../interactions/HitSprite";
import { WiredSelectionFilter } from "../filters/WiredSelectionFilter";
/** The wired selection filter */
const WIRED_SELECTION_FILTER = new WiredSelectionFilter(0xffffff, 0x999999);
/**
 * FurnitureLayer class.
 *
 * @class
 * @memberof Scuti
 */
export class FurnitureLayer extends HitSprite {
    /**
     * @param {FloorFurniture | WallFurniture} [furniture] - The furniture instance.
     * @param {IFurnitureLayerConfiguration} [configuration] - The layer configuration.
     */
    constructor(furniture, configuration) {
        super(null);
        this._furniture = furniture;
        this._layer = configuration.layer;
        this._alpha = configuration.alpha;
        this._tint = configuration.tint;
        this._z = configuration.z;
        this._blendMode = configuration.blendMode;
        this._flip = configuration.flip;
        this._frame = configuration.frame;
        this._ignoreMouse = configuration.ignoreMouse;
        this._direction = configuration.direction;
        this._tag = configuration.tag;
        this._draw();
    }
    /**
     * Draw the part.
     *
     * @return {void}
     * @private
     */
    _draw() {
        this.filters = [];
        this.texture = Assets.get("furnitures/" + this._furniture.data.baseName).textures[this._furniture.data.baseName + '_' + this._furniture.data.baseName + '_64_' + this._layer + '_' + this._direction + '_' + this._frame];
        if (this._tint !== undefined)
            this.tint = utils.premultiplyTint(this._tint, 1);
        if (this._blendMode !== undefined)
            this.blendMode = this._blendMode;
        if (this._alpha !== undefined)
            this.alpha = this._alpha;
        if (this._flip)
            this.scale.x = -1;
        if (this._furniture.room !== undefined)
            this.parentLayer = this._furniture.room.objects.layer;
        if (this._z)
            this.zOrder = this._z;
        if (this._ignoreMouse !== null && !this._ignoreMouse)
            this.interactive = true;
        if (this._furniture.selected)
            this.filters.push(WIRED_SELECTION_FILTER);
        this.on("pointerdown", (event) => this._furniture.interactionManager.handlePointerDown({ mouseEvent: event, tag: this._tag }));
        this.on("pointerup", (event) => this._furniture.interactionManager.handlePointerUp({ mouseEvent: event, tag: this._tag }));
        this.on("pointermove", (event) => this._furniture.interactionManager.handlePointerMove({ mouseEvent: event, tag: this._tag }));
        this.on("pointerout", (event) => this._furniture.interactionManager.handlePointerOut({ mouseEvent: event, tag: this._tag }));
        this.on("pointerover", (event) => this._furniture.interactionManager.handlePointerOver({ mouseEvent: event, tag: this._tag }));
    }
    /**
     * Reference to the furniture instance.
     *
     * @member {FloorFurniture | WallFurniture}
     * @readonly
     * @public
     */
    get furniture() {
        return this._furniture;
    }
}
//# sourceMappingURL=FurnitureLayer.js.map