import { FurnitureData } from "./FurnitureData";
import { RoomObject } from "../rooms/RoomObject";
import { gsap } from "gsap";
import { InteractionManager } from "../interactions/InteractionManager";
import { FurnitureView } from "./FurnitureView";
/**
 * WallFurniture class that aim to reproduce the wall furnitures on Habbo.
 *
 * @class
 * @memberof Scuti
 */
export class WallFurniture extends RoomObject {
    /**
     * @param {IFloorFurnitureConfiguration} [configuration] - The furniture configuration.
     */
    constructor(configuration) {
        var _a;
        super();
        /**
         * A boolean indicating if we have to apply the wired selection filter to the furniture.
         *
         * @member {boolean}
         * @private
         */
        this._selected = false;
        /**
         * The furniture interaction manager to handle all the clicks and taps.
         *
         * @member {InteractionManager}
         * @private
         */
        this._interactionManager = new InteractionManager();
        /**
         * Move the furniture at the given position and in time.
         *
         * @param {IWallPosition} [position] - The position where we want to move the furniture.
         * @param {number} [duration] - The time to move the furniture to the given position.
         * @return {void}
         * @public
         */
        this.move = (position, duration = 0.5) => {
            if (this._direction === 2) {
                gsap.to(this, {
                    x: 32 + 32 * this._position.x - 32 * this._position.y + this._position.offsetX * 2,
                    y: 16 * this._position.x + 16 * this._position.y - 32 + this._position.offsetY * 2 - 84,
                    duration: duration,
                    ease: "linear",
                    onComplete: () => {
                        this._position = position;
                    }
                });
            }
            else {
                gsap.to(this, {
                    x: 32 + 32 * this._position.x - 32 * this._position.y + this._position.offsetX * 2 - 32,
                    y: 16 * this._position.x + 16 * this._position.y - 32 + this._position.offsetY * 2 - 84,
                    duration: duration,
                    ease: "linear",
                    onComplete: () => {
                        this._position = position;
                    }
                });
            }
        };
        /**
         * Rotate the furniture at the given direction and in time.
         *
         * @param {Direction} [direction] - The new direction of the furniture.
         * @param {number} [duration] - The time to rotate the furniture at the given direction.
         * @return {void}
         * @public
         */
        this.rotate = (direction, duration = 0.2) => {
            gsap.to(this, {
                x: 32 + 32 * this._position.x - 32 * this._position.y + this._position.offsetX * 2 - 32,
                y: 16 * this._position.x + 16 * this._position.y - 32 + this._position.offsetY * 2 - 84 - 6.25,
                duration: duration / 2,
                ease: "easeIn",
                onComplete: () => {
                    this._direction = direction;
                    this._view.update();
                    gsap.to(this, {
                        x: 32 + 32 * this._position.x - 32 * this._position.y + this._position.offsetX * 2 - 32,
                        y: 16 * this._position.x + 16 * this._position.y - 32 + this._position.offsetY * 2 - 84,
                        duration: duration / 2,
                        ease: "easeOut"
                    });
                }
            });
        };
        /** Store the data */
        this._id = configuration.id;
        this._position = configuration.position;
        this._direction = configuration.direction;
        this._state = (_a = configuration.state) !== null && _a !== void 0 ? _a : 0;
        this._data = new FurnitureData(this);
        /** Initialise view */
        this._view = new FurnitureView(this);
        this.addChild(this._view);
        /** Set the furniture position in the canvas */
        this._updatePosition();
    }
    /**
     * Update the furniture position in the canvas.
     *
     * @return {void}
     * @private
     */
    _updatePosition() {
        this.x = 32 + 32 * this._position.x - 32 * this._position.y;
        this.y = 16 * this._position.x + 16 * this._position.y - 32;
        if (this._direction === 2) {
            this.x = this.x + this._position.offsetX * 2;
            this.y = this.y + this._position.offsetY * 2 - 84;
        }
        else {
            this.x = this.x + this._position.offsetX * 2 - 32;
            this.y = this.y + this._position.offsetY * 2 - 84;
        }
    }
    /**
     * Add the furniture to the ticker to start the animation.
     *
     * @return {void}
     * @public
     */
    start() {
        this.animationTicker.add(() => this._view.tick());
    }
    /**
     * Remove the furniture from the ticker to stop the animation.
     *
     * @return {void}
     * @public
     */
    stop() {
        this.animationTicker.remove(() => this._view.tick());
    }
    /**
     * Reference to the furniture id from the furni data.
     *
     * @member {number}
     * @readonly
     * @public
     */
    get id() {
        return this._id;
    }
    /**
     * Reference to the furniture position in the room.
     *
     * @member {IWallPosition}
     * @readonly
     * @public
     */
    get roomPosition() {
        return this._position;
    }
    /**
     * Update the furniture position.
     *
     * @param {IWallPosition} [position] - The new furniture position.
     * @public
     */
    set roomPosition(position) {
        this._position = position;
    }
    /**
     * Reference to the furniture direction.
     *
     * @member {Direction}
     * @readonly
     * @public
     */
    get direction() {
        return this._direction;
    }
    /**
     * Update the furniture direction.
     *
     * @param {Direction} [direction] - The new furniture direction.
     * @public
     */
    set direction(direction) {
        this._direction = direction;
        this._view.update();
    }
    /**
     * Reference to the furniture state.
     *
     * @member {number}
     * @readonly
     * @public
     */
    get state() {
        return this._state;
    }
    /**
     * Update the furniture state (so the animation).
     *
     * @param {number} [state] - The new furniture state.
     * @public
     */
    set state(state) {
        this._state = state;
        this._view.update();
    }
    /**
     * Reference to the furniture selection state.
     *
     * @member {boolean}
     * @readonly
     * @public
     */
    get selected() {
        return this._selected;
    }
    /**
     * Update the furniture selection state (add the wired selection filter to the furniture).
     *
     * @param {boolean} [selected] - The new furniture selection state.
     * @public
     */
    set selected(selected) {
        this._selected = selected;
        this._view.update();
    }
    /**
     * Reference to the furniture data.
     *
     * @member {FurnitureData}
     * @readonly
     * @public
     */
    get data() {
        return this._data;
    }
    /**
     * Reference to the furniture view.
     *
     * @member {FurnitureView}
     * @readonly
     * @public
     */
    get view() {
        return this._view;
    }
    /**
     * Update the furniture view.
     *
     * @param {FurnitureView} [view] - The new furniture view.
     * @public
     */
    set view(view) {
        this._view = view;
    }
    /**
     * Reference to the furniture visualization.
     *
     * @member {FurnitureVisualization}
     * @readonly
     * @public
     */
    get visualization() {
        return this._view.visualization;
    }
    /**
     * Reference to the furniture interaction manager.
     *
     * @member {InteractionManager}
     * @readonly
     * @public
     */
    get interactionManager() {
        return this._interactionManager;
    }
    /**
     * Reference to the pointer down event.
     *
     * @member {(event: IInteractionEvent) => void}
     * @readonly
     * @public
     */
    get onPointerDown() {
        return this._interactionManager.onPointerDown;
    }
    /**
     * Update the event function that will be executed.
     *
     * @param {(event: IInteractionEvent) => void} [value] - The event function that will be executed.
     * @public
     */
    set onPointerDown(value) {
        this._interactionManager.onPointerDown = value;
    }
    /**
     * Reference to the pointer up event.
     *
     * @member {(event: IInteractionEvent) => void}
     * @readonly
     * @public
     */
    get onPointerUp() {
        return this._interactionManager.onPointerUp;
    }
    /**
     * Update the event function that will be executed.
     *
     * @param {(event: IInteractionEvent) => void} [value] - The event function that will be executed.
     * @public
     */
    set onPointerUp(value) {
        this._interactionManager.onPointerUp = value;
    }
    /**
     * Reference to the pointer move event.
     *
     * @member {(event: IInteractionEvent) => void}
     * @readonly
     * @public
     */
    get onPointerMove() {
        return this._interactionManager.onPointerMove;
    }
    /**
     * Update the event function that will be executed.
     *
     * @param {(event: IInteractionEvent) => void} [value] - The event function that will be executed.
     * @public
     */
    set onPointerMove(value) {
        this._interactionManager.onPointerMove = value;
    }
    /**
     * Reference to the pointer out event.
     *
     * @member {(event: IInteractionEvent) => void}
     * @readonly
     * @public
     */
    get onPointerOut() {
        return this._interactionManager.onPointerOut;
    }
    /**
     * Update the event function that will be executed.
     *
     * @param {(event: IInteractionEvent) => void} [value] - The event function that will be executed.
     * @public
     */
    set onPointerOut(value) {
        this._interactionManager.onPointerOut = value;
    }
    /**
     * Reference to the pointer over event.
     *
     * @member {(event: IInteractionEvent) => void}
     * @readonly
     * @public
     */
    get onPointerOver() {
        return this._interactionManager.onPointerOver;
    }
    /**
     * Update the event function that will be executed.
     *
     * @param {(event: IInteractionEvent) => void} [value] - The event function that will be executed.
     * @public
     */
    set onPointerOver(value) {
        this._interactionManager.onPointerOver = value;
    }
    /**
     * Reference to the pointer double click event.
     *
     * @member {(event: IInteractionEvent) => void}
     * @readonly
     * @public
     */
    get onDoubleClick() {
        return this._interactionManager.onDoubleClick;
    }
    /**
     * Update the event function that will be executed.
     *
     * @param {(event: IInteractionEvent) => void} [value] - The event function that will be executed.
     * @public
     */
    set onDoubleClick(value) {
        this._interactionManager.onDoubleClick = value;
    }
}
//# sourceMappingURL=WallFurniture.js.map