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