import { MarkupEntity } from './MarkupEntity';
import { Color3, Color4 } from '../../loader/babylonjs-import';
import { equalsWithEpsilonVertex3 } from '../../math/index';
import { MergableObjectEventSource } from '../../MergableSet';
/**
 * Class representing a markup area in the markup API.
 */
export class MarkupArea extends MarkupEntity {
    style = { backgroundColor: new Color4(...Color3.Teal().asArray(), 1.0) };
    points;
    /**
     * Do not use. Use {@link MarkupSheet2D.add} instead.
     * @hidden
     */
    constructor({ id, sheet, properties, points, style }) {
        super(id, sheet, properties);
        this.points = points;
        this.style = style;
    }
    /**
     * Copy the area to another markup sheet.
     * @param sheet Markup sheet to copy the area to.
     * @returns The new markup area entity.
     */
    copyTo(sheet) {
        const deepCopyPoints = [];
        for (let i = 0; i < this.points.length; i++) {
            const originalVertex = this.points[i];
            deepCopyPoints.push({ x: originalVertex.x, y: originalVertex.y, z: originalVertex.z });
        }
        return sheet.add(MarkupArea, {
            points: deepCopyPoints,
            style: { backgroundColor: this.style.backgroundColor.clone() }
        }, new Map(this.properties));
    }
    onUpdate(o) {
        if (o.eventSource === MergableObjectEventSource.Remote && !o.conflictReason && o.remote) {
            this.copyFrom(o.remote);
        }
        super.onUpdate(o);
    }
    copyFrom(area) {
        this.points = this.points = area.points.map((p) => {
            return { ...p };
        });
        this.properties.clear();
        for (const [key, value] of area.properties) {
            this.properties.set(key, value);
        }
    }
    clone() {
        const deepCopyPoints = [];
        for (let i = 0; i < this.points.length; i++) {
            const originalVertex = this.points[i];
            deepCopyPoints.push({ x: originalVertex.x, y: originalVertex.y, z: originalVertex.z });
        }
        const area = new MarkupArea({
            id: this.id,
            points: deepCopyPoints,
            sheet: this.sheet,
            properties: new Map(this.properties),
            style: { backgroundColor: this.style.backgroundColor.clone() }
        });
        return area;
    }
    isEqual(o) {
        return (o.id === this.id &&
            o.sheet.isEqual(this.sheet) &&
            o.properties.size === this.properties.size &&
            [...this.properties].every(([key, value]) => value === o.properties.get(key)) &&
            this.points.length === o.points.length &&
            [...this.points].every((point, idx) => equalsWithEpsilonVertex3(point, o.points[idx])));
    }
}
//# sourceMappingURL=MarkupArea.js.map