/*!
 * Copyright (c) 2026 Vertex Software LLC. All rights reserved.
 */
import { ArrowEndShape as ApiArrowEndShape, CircleEndShape as ApiCircleEndShape, DashEndShape as ApiDashEndShape, EndShape as ApiEndShape, FillStyle as ApiFillStyle, FreeformItem2d as ApiFreeformItem2d, LineItem2d as ApiLineItem2d, OvalItem2d as ApiOvalItem2d, StrokeStyle as ApiStrokeStyle, } from "@vertexvis/scene-view-protos/core/protos/canvas_items_2d_pb";
import { CalloutItem as ApiCalloutItem, Canvas, CanvasDocument3d, CanvasDocument3dV1, CanvasItem, Pin2d as ApiPinItem2d, } from "@vertexvis/scene-view-protos/core/protos/scene_canvas_pb";
import { GetCanvasResponse } from "@vertexvis/scene-view-protos/sceneview/protos/scene_view_api_pb";
import { Color, UUID } from "@vertexvis/utils";
import { random } from ".";
import { makeRGBAi } from "./colors";
import { makeVector2d, makeVector3f } from "./geometry";
import { makeUuid2l } from "./uuid";
export function makeGetCanvasResponse(canvas = makeCanvas()) {
    const res = new GetCanvasResponse();
    res.setCanvas(canvas);
    return res;
}
export function makeCanvas(id = UUID.create(), itemsList = [
    makeLine2d(),
    makeOval2d(),
    makeFreeform2d(),
    makePin2d(),
    makeCallout(),
]) {
    const canvas = new Canvas();
    const doc = new CanvasDocument3d();
    const v1 = new CanvasDocument3dV1();
    canvas.setId(makeUuid2l(id));
    v1.setItemsList(itemsList);
    doc.setV1(v1);
    canvas.setDocument(doc);
    return canvas;
}
export function makeLine2d(value = {}) {
    var _a, _b, _c, _d, _e, _f, _g;
    const item = new CanvasItem();
    const line2d = new ApiLineItem2d();
    line2d.setStartPosition(makeVector2d((_a = value.startPosition) === null || _a === void 0 ? void 0 : _a.x, (_b = value.startPosition) === null || _b === void 0 ? void 0 : _b.y));
    line2d.setEndPosition(makeVector2d((_c = value.endPosition) === null || _c === void 0 ? void 0 : _c.x, (_d = value.endPosition) === null || _d === void 0 ? void 0 : _d.y));
    line2d.setStrokeStyle(makeStrokeStyle((_e = value.stroke) === null || _e === void 0 ? void 0 : _e.thickness, (_f = value.stroke) === null || _f === void 0 ? void 0 : _f.color));
    line2d.setFillStyle(makeFillStyle((_g = value.fill) === null || _g === void 0 ? void 0 : _g.color));
    line2d.setStartShape(makeLineEndShape(value.startShape));
    line2d.setEndShape(makeLineEndShape(value.endShape));
    item.setLine2d(line2d);
    return item;
}
export function makeOval2d(value = {}) {
    var _a, _b, _c, _d, _e, _f, _g;
    const item = new CanvasItem();
    const oval2d = new ApiOvalItem2d();
    oval2d.setTopLeft(makeVector2d((_a = value.topLeftPosition) === null || _a === void 0 ? void 0 : _a.x, (_b = value.topLeftPosition) === null || _b === void 0 ? void 0 : _b.y));
    oval2d.setBottomRight(makeVector2d((_c = value.bottomRightPosition) === null || _c === void 0 ? void 0 : _c.x, (_d = value.bottomRightPosition) === null || _d === void 0 ? void 0 : _d.y));
    oval2d.setStrokeStyle(makeStrokeStyle((_e = value.stroke) === null || _e === void 0 ? void 0 : _e.thickness, (_f = value.stroke) === null || _f === void 0 ? void 0 : _f.color));
    oval2d.setFillStyle(makeFillStyle((_g = value.fill) === null || _g === void 0 ? void 0 : _g.color));
    item.setOval(oval2d);
    return item;
}
export function makeFreeform2d(value = {}) {
    var _a, _b, _c, _d, _e;
    const item = new CanvasItem();
    const freeform2d = new ApiFreeformItem2d();
    freeform2d.setPositionsList((_b = (_a = value.positions) === null || _a === void 0 ? void 0 : _a.map((p) => makeVector2d(p.x, p.y))) !== null && _b !== void 0 ? _b : []);
    freeform2d.setStrokeStyle(makeStrokeStyle((_c = value.stroke) === null || _c === void 0 ? void 0 : _c.thickness, (_d = value.stroke) === null || _d === void 0 ? void 0 : _d.color));
    freeform2d.setFillStyle(makeFillStyle((_e = value.fill) === null || _e === void 0 ? void 0 : _e.color));
    item.setFreeform(freeform2d);
    return item;
}
export function makePin2d(value = {}) {
    var _a, _b, _c;
    const item = new CanvasItem();
    const pin2d = new ApiPinItem2d();
    pin2d.setPosition(makeVector3f((_a = value.position) === null || _a === void 0 ? void 0 : _a.x, (_b = value.position) === null || _b === void 0 ? void 0 : _b.y, (_c = value.position) === null || _c === void 0 ? void 0 : _c.z));
    pin2d.setPrimaryColor(makeRGBAi(value.primaryColor));
    pin2d.setAccentColor(makeRGBAi(value.accentColor));
    pin2d.setSceneItemId(makeUuid2l(value.sceneItemId));
    item.setPin(pin2d);
    return item;
}
export function makeCallout(value = {}) {
    var _a, _b, _c, _d, _e, _f;
    const item = new CanvasItem();
    const callout = new ApiCalloutItem();
    callout.setAnchorPosition(makeVector3f((_a = value.anchorPosition) === null || _a === void 0 ? void 0 : _a.x, (_b = value.anchorPosition) === null || _b === void 0 ? void 0 : _b.y, (_c = value.anchorPosition) === null || _c === void 0 ? void 0 : _c.z));
    callout.setTextPosition(makeVector2d((_d = value.textPosition) === null || _d === void 0 ? void 0 : _d.x, (_e = value.textPosition) === null || _e === void 0 ? void 0 : _e.y));
    callout.setPrimaryColor(makeRGBAi(value.primaryColor));
    callout.setAccentColor(makeRGBAi(value.accentColor));
    callout.setSceneItemId(makeUuid2l(value.sceneItemId));
    callout.setText((_f = value.text) !== null && _f !== void 0 ? _f : random.string());
    item.setCallout(callout);
    return item;
}
export function makeLineEndShape(shape = {
    type: 'arrow-end',
    width: 1,
    filled: true,
}) {
    const s = new ApiEndShape();
    if (shape.type === 'arrow-end') {
        const a = new ApiArrowEndShape();
        a.setFilled(shape.filled);
        a.setWidth(shape.width);
        s.setArrow(a);
    }
    if (shape.type === 'circle-end') {
        const c = new ApiCircleEndShape();
        c.setFilled(shape.filled);
        c.setDiameter(shape.diameter);
        s.setCircle(c);
    }
    if (shape.type === 'dash-end') {
        const d = new ApiDashEndShape();
        d.setWidth(shape.width);
        s.setDash(d);
    }
    return s;
}
export function makeStrokeStyle(thickness = 4, color = Color.create(255, 255, 255)) {
    const s = new ApiStrokeStyle();
    s.setThickness(thickness);
    s.setColor(makeRGBAi(color));
    return s;
}
export function makeFillStyle(color = Color.create(255, 255, 255)) {
    const s = new ApiFillStyle();
    s.setColor(makeRGBAi(color));
    return s;
}
//# sourceMappingURL=canvases.js.map
