var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
import { Workspace } from '@blockeditor/store';
import { keys } from '../../_common/utils/iterable.js';
import { Bound } from '../utils/bound.js';
import {} from '../utils/xywh.js';
import { ElementModel } from './base.js';
import { yfield } from './decorators.js';
export class GroupElementModel extends ElementModel {
    constructor() {
        super(...arguments);
        this.children = new Workspace.Y.Map();
        this.title = new Workspace.Y.Text();
    }
    static propsToY(props) {
        if (props.title && !(props.title instanceof Workspace.Y.Text)) {
            props.title = new Workspace.Y.Text(props.title);
        }
        if (props.children && !(props.children instanceof Workspace.Y.Map)) {
            const children = new Workspace.Y.Map();
            keys(props.children).forEach(key => {
                children.set(key, true);
            });
            props.children = children;
        }
        return props;
    }
    get xywh() {
        const childrenIds = this.childrenIds;
        if (childrenIds.length === 0)
            return '[0,0,0,0]';
        const bound = childrenIds
            .map(id => this.surfaceModel.getElementById(id) ??
            this.surfaceModel.page.getBlockById(id))
            .filter(el => el)
            .reduce((prev, ele) => {
            return prev.unite(ele.elementBound);
        }, new Bound(Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY, 0, 0));
        return bound.serialize();
    }
    set xywh(_) { }
    get rotate() {
        return 0;
    }
    set rotate(_) { }
    get type() {
        return 'group';
    }
    get childrenIds() {
        return [...this.children.keys()];
    }
    get childrenElements() {
        const elements = [];
        const keys = this.children.keys();
        for (const key of keys) {
            const element = this.surfaceModel.getElementById(key) ||
                this.surfaceModel.page.getBlockById(key);
            element && elements.push(element);
        }
        return elements;
    }
}
__decorate([
    yfield()
], GroupElementModel.prototype, "children", void 0);
__decorate([
    yfield()
], GroupElementModel.prototype, "title", void 0);
//# sourceMappingURL=group.js.map