import { ConfigType } from '../config.js';
import GridData from '../grid.js';
import { Color } from '../primitives.js';
import NumberSymbol from './numberSymbol.js';
class AreaNumberSymbol extends NumberSymbol {
    /**
     * **Area Numbers must equal region sizes**
     *
     * @param x - The x-coordinate of the symbol.
     * @param y - The y-coordinate of the symbol.
     * @param number - The area number.
     */
    constructor(x, y, number) {
        super(x, y, number);
    }
    get id() {
        return `number`;
    }
    get explanation() {
        return `*Area Numbers* must equal region sizes`;
    }
    get configs() {
        return AreaNumberSymbol.CONFIGS;
    }
    createExampleGrid() {
        return AreaNumberSymbol.EXAMPLE_GRID;
    }
    countTiles(grid) {
        const thisX = Math.floor(this.x);
        const thisY = Math.floor(this.y);
        const color = grid.getTile(thisX, thisY).color;
        if (color === Color.Gray)
            return { completed: 0, possible: Number.MAX_SAFE_INTEGER };
        let completeCount = 0;
        let grayCount = 0;
        grid.iterateArea({ x: thisX, y: thisY }, tile => tile.color === Color.Gray || tile.color === color, () => {
            grayCount++;
        });
        grid.iterateArea({ x: thisX, y: thisY }, tile => tile.color === color, () => {
            completeCount++;
        });
        return { completed: completeCount, possible: grayCount };
    }
    copyWith({ x, y, number, }) {
        return new AreaNumberSymbol(x ?? this.x, y ?? this.y, number ?? this.number);
    }
    withNumber(number) {
        return this.copyWith({ number });
    }
}
Object.defineProperty(AreaNumberSymbol, "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,
        },
    ])
});
Object.defineProperty(AreaNumberSymbol, "EXAMPLE_GRID", {
    enumerable: true,
    configurable: true,
    writable: true,
    value: Object.freeze(GridData.create(['wbbbb', 'wbbwb', 'bbwwb', 'bbbbb'])
        .addSymbol(new AreaNumberSymbol(2, 2, 3))
        .addSymbol(new AreaNumberSymbol(0, 1, 2)))
});
export default AreaNumberSymbol;
export const instance = new AreaNumberSymbol(0, 0, 1);
