import { ConfigType } from '../config.js';
import GridData from '../grid.js';
import { Color, Orientation } from '../primitives.js';
import NumberSymbol from './numberSymbol.js';
class DartSymbol extends NumberSymbol {
    /**
     * **Darts count opposite color cells in that direction**
     *
     * @param x - The x-coordinate of the symbol.
     * @param y - The y-coordinate of the symbol.
     * @param number - The number of cells seen by the symbol.
     * @param orientation - The orientation of the symbol.
     */
    constructor(x, y, number, orientation) {
        super(x, y, number);
        Object.defineProperty(this, "orientation", {
            enumerable: true,
            configurable: true,
            writable: true,
            value: orientation
        });
        this.orientation = orientation;
    }
    get id() {
        return `dart`;
    }
    get placementStep() {
        return 1;
    }
    get explanation() {
        return `*Darts* count opposite color cells in that direction`;
    }
    get configs() {
        return DartSymbol.CONFIGS;
    }
    createExampleGrid() {
        return DartSymbol.EXAMPLE_GRID;
    }
    countTiles(grid) {
        if (Math.floor(this.x) !== this.x || Math.floor(this.y) !== this.y)
            return { completed: 0, possible: Number.MAX_SAFE_INTEGER };
        const color = grid.getTile(this.x, this.y).color;
        if (color === Color.Gray)
            return { completed: 0, possible: Number.MAX_SAFE_INTEGER };
        let gray = 0;
        let opposite = 0;
        grid.iterateDirectionAll({ x: this.x, y: this.y }, this.orientation, () => true, tile => {
            if (!tile.exists)
                return;
            if (tile.color === Color.Gray)
                gray++;
            else if (tile.color !== color)
                opposite++;
        });
        return { completed: opposite, possible: opposite + gray };
    }
    copyWith({ x, y, number, orientation, }) {
        return new DartSymbol(x ?? this.x, y ?? this.y, number ?? this.number, orientation ?? this.orientation);
    }
    withNumber(number) {
        return this.copyWith({ number });
    }
}
Object.defineProperty(DartSymbol, "CONFIGS", {
    enumerable: true,
    configurable: true,
    writable: true,
    value: Object.freeze([
        {
            type: ConfigType.Number,
            default: 0,
            field: 'x',
            description: 'X',
            configurable: false,
        },
        {
            type: ConfigType.Number,
            default: 0,
            field: 'y',
            description: 'Y',
            configurable: false,
        },
        {
            type: ConfigType.Number,
            default: 1,
            field: 'number',
            description: 'Number',
            configurable: true,
        },
        {
            type: ConfigType.Orientation,
            default: Orientation.Right,
            field: 'orientation',
            description: 'Orientation',
            configurable: true,
        },
    ])
});
Object.defineProperty(DartSymbol, "EXAMPLE_GRID", {
    enumerable: true,
    configurable: true,
    writable: true,
    value: Object.freeze(GridData.create(['wwbbw', 'wwwww', 'wbwbb', 'wwwww'])
        .addSymbol(new DartSymbol(1, 0, 1, Orientation.Down))
        .addSymbol(new DartSymbol(4, 0, 2, Orientation.Left))
        .addSymbol(new DartSymbol(3, 1, 1, Orientation.Down))
        .addSymbol(new DartSymbol(0, 2, 3, Orientation.Right)))
});
export default DartSymbol;
export const instance = new DartSymbol(0, 0, 1, Orientation.Right);
