// #region Imports
/**
 * Handles serialization and deserialization of tile layouts.
 *
 * @public
 */
export class TileManagerSerializer {
    // #region Fields
    // #endregion
    // #region Ctor
    // #endregion
    // #region Methods
    /**
     * Saves the current layout of tiles.
     *
     * @param tiles - The tiles to save.
     * @returns An array of serialized tile states.
     *
     * @public
     */
    save(tiles) {
        return tiles.map((tile) => {
            return {
                id: tile.id,
                position: tile.position,
                colSpan: tile.colSpan,
                rowSpan: tile.rowSpan,
                colStart: tile.colStart,
                rowStart: tile.rowStart
            };
        });
    }
    /**
     * Saves the current layout as a JSON string.
     *
     * @param tiles - The tiles to save.
     * @returns A JSON string representing the layout.
     *
     * @public
     */
    saveAsJSON(tiles) {
        return JSON.stringify(this.save(tiles));
    }
    /**
     * Loads a previously saved layout.
     *
     * @param tiles - The tiles to apply the layout to.
     * @param layout - The serialized layout to load.
     *
     * @public
     */
    load(tiles, layout) {
        const mapped = new Map();
        for (const serialized of layout) {
            mapped.set(serialized.id, serialized);
        }
        for (const tile of tiles) {
            const serialized = mapped.get(tile.id);
            if (serialized) {
                tile.position = serialized.position;
                tile.colSpan = serialized.colSpan;
                tile.rowSpan = serialized.rowSpan;
                tile.colStart = serialized.colStart;
                tile.rowStart = serialized.rowStart;
            }
        }
    }
    /**
     * Loads a layout from a JSON string.
     *
     * @param tiles - The tiles to apply the layout to.
     * @param json - The JSON string representing the layout.
     *
     * @public
     */
    loadFromJSON(tiles, json) {
        const layout = JSON.parse(json);
        this.load(tiles, layout);
    }
}
//# sourceMappingURL=TileManagerSerializer.js.map