import { BaseSelection } from '@blockeditor/block-std';
import { z } from 'zod';
const TableViewSelectionSchema = z.object({
    viewId: z.string(),
    type: z.literal('table'),
    rowsSelection: z
        .object({
        start: z.number(),
        end: z.number(),
    })
        .optional(),
    columnsSelection: z
        .object({
        start: z.number(),
        end: z.number(),
    })
        .optional(),
    focus: z.object({
        rowIndex: z.number(),
        columnIndex: z.number(),
    }),
    isEditing: z.boolean(),
});
const KanbanCellSelectionSchema = z.object({
    selectionType: z.literal('cell'),
    groupKey: z.string(),
    cardId: z.string(),
    columnId: z.string(),
    isEditing: z.boolean(),
});
const KanbanCardSelectionSchema = z.object({
    selectionType: z.literal('card'),
    cards: z.array(z.object({
        groupKey: z.string(),
        cardId: z.string(),
    })),
});
const KanbanGroupSelectionSchema = z.object({
    selectionType: z.literal('group'),
    groupKeys: z.array(z.string()),
});
const DatabaseSelectionSchema = z.object({
    path: z.array(z.string()),
    viewSelection: z.union([
        TableViewSelectionSchema,
        KanbanCellSelectionSchema,
        KanbanCardSelectionSchema,
        KanbanGroupSelectionSchema,
    ]),
});
export class DatabaseSelection extends BaseSelection {
    constructor({ path, viewSelection, }) {
        super({
            path,
        });
        this.viewSelection = viewSelection;
    }
    get viewId() {
        return this.viewSelection.viewId;
    }
    getSelection(type) {
        return this.viewSelection.type === type
            ? this.viewSelection
            : undefined;
    }
    equals(other) {
        if (!(other instanceof DatabaseSelection)) {
            return false;
        }
        return this.blockId === other.blockId;
    }
    toJSON() {
        return {
            type: 'database',
            path: this.path,
            viewSelection: this.viewSelection,
        };
    }
    static fromJSON(json) {
        DatabaseSelectionSchema.parse(json);
        return new DatabaseSelection({
            path: json.path,
            viewSelection: json.viewSelection,
        });
    }
}
DatabaseSelection.type = 'database';
DatabaseSelection.group = 'note';
//# sourceMappingURL=selection.js.map