import { array_pick_best_element } from "../../../core/collection/array/array_pick_best_element.js";
import { CursorType } from "./CursorType.js";

export class CursorCoalescence {
    constructor() {

        /**
         *
         * @type {CursorType[]}
         */
        this.cursorPriorities = [
            CursorType.Normal,
            CursorType.Move,
            CursorType.Pointer,
            CursorType.Attack
        ];

        this.cursors = [];
    }

    /**
     *
     * @param {CursorType[]} priorities
     */
    setPriorities(priorities) {
        this.cursorPriorities = priorities;
    }

    reset() {
        this.cursors.splice(0, this.cursors.length);
    }

    /**
     *
     * @param {CursorType} cursor
     */
    add(cursor) {
        if (this.cursors.indexOf(cursor) === -1) {
            this.cursors.push(cursor);
        }
    }

    /**
     * @returns {CursorType}
     */
    get() {
        //pick best
        return array_pick_best_element(this.cursors, c => this.cursorPriorities.indexOf(c));
    }
}
