/*!
 * Copyright (c) 2026 Vertex Software LLC. All rights reserved.
 */
import { Mapper as M } from "@vertexvis/utils";
import { fromPbRGBAi, fromPbUuid2l, fromPbVector2d, fromPbVector3f, } from "../mappers";
const mapStrokeStyle = M.defineMapper(M.read(M.mapRequiredProp('color', fromPbRGBAi), M.getProp('thickness')), ([color, thickness]) => ({ color, thickness }));
const mapFillStyle = M.defineMapper(M.read(M.mapRequiredProp('color', fromPbRGBAi)), ([color]) => ({ color }));
const mapEndShape = M.defineMapper(M.read(M.pickFirst(M.mapProp('arrow', M.ifDefined((a) => ({ ...a, type: 'arrow-end' }))), M.mapProp('circle', M.ifDefined((a) => ({ ...a, type: 'circle-end' }))), M.mapProp('dash', M.ifDefined((a) => ({ ...a, type: 'dash-end' }))))), ([shape]) => shape !== null && shape !== void 0 ? shape : undefined);
const mapLineItem2d = M.defineMapper(M.read(M.mapRequiredProp('startPosition', fromPbVector2d), M.mapRequiredProp('endPosition', fromPbVector2d), M.mapProp('strokeStyle', M.ifDefined(mapStrokeStyle)), M.mapProp('fillStyle', M.ifDefined(mapFillStyle)), M.mapProp('startShape', M.ifDefined(mapEndShape)), M.mapProp('endShape', M.ifDefined(mapEndShape))), ([startPosition, endPosition, strokeStyle, fillStyle, startShape, endShape,]) => ({
    type: 'line-2d',
    startPosition,
    endPosition,
    strokeStyle,
    fillStyle,
    startShape: startShape !== null && startShape !== void 0 ? startShape : undefined,
    endShape: endShape !== null && endShape !== void 0 ? endShape : undefined,
}));
const mapOvalItem2d = M.defineMapper(M.read(M.mapRequiredProp('topLeft', fromPbVector2d), M.mapRequiredProp('bottomRight', fromPbVector2d), M.mapProp('strokeStyle', M.ifDefined(mapStrokeStyle)), M.mapProp('fillStyle', M.ifDefined(mapFillStyle))), ([topLeftPosition, bottomRightPosition, strokeStyle, fillStyle]) => ({
    type: 'oval-2d',
    topLeftPosition,
    bottomRightPosition,
    strokeStyle,
    fillStyle,
}));
const mapFreeformItem2d = M.defineMapper(M.read(M.mapRequiredProp('positionsList', M.mapArray(fromPbVector2d)), M.mapProp('strokeStyle', M.ifDefined(mapStrokeStyle)), M.mapProp('fillStyle', M.ifDefined(mapFillStyle))), ([positions, strokeStyle, fillStyle]) => ({
    type: 'freeform-2d',
    positions,
    strokeStyle,
    fillStyle,
}));
const mapPinItem2d = M.defineMapper(M.read(M.mapRequiredProp('primaryColor', fromPbRGBAi), M.mapRequiredProp('accentColor', fromPbRGBAi), M.mapRequiredProp('position', fromPbVector3f), M.mapProp('sceneItemId', M.ifDefined(fromPbUuid2l))), ([primaryColor, accentColor, position, sceneItemId]) => ({
    type: 'pin-2d',
    primaryColor,
    accentColor,
    position,
    sceneItemId: sceneItemId !== null && sceneItemId !== void 0 ? sceneItemId : undefined,
}));
const mapCalloutItem = M.defineMapper(M.read(M.mapRequiredProp('primaryColor', fromPbRGBAi), M.mapRequiredProp('accentColor', fromPbRGBAi), M.mapRequiredProp('anchorPosition', fromPbVector3f), M.mapRequiredProp('textPosition', fromPbVector2d), M.getProp('text'), M.mapProp('sceneItemId', M.ifDefined(fromPbUuid2l))), ([primaryColor, accentColor, anchorPosition, textPosition, text, sceneItemId,]) => ({
    type: 'callout',
    primaryColor,
    accentColor,
    anchorPosition,
    textPosition,
    text,
    sceneItemId: sceneItemId !== null && sceneItemId !== void 0 ? sceneItemId : undefined,
}));
/**
 * @internal
 * @ignore
 *
 * Visible for testing.
 */
export const mapCanvasItem = M.defineMapper(M.read(M.pickFirst(M.mapProp('line2d', M.ifDefined(mapLineItem2d)), M.mapProp('oval', M.ifDefined(mapOvalItem2d)), M.mapProp('freeform', M.ifDefined(mapFreeformItem2d)), M.mapProp('pin', M.ifDefined(mapPinItem2d)), M.mapProp('callout', M.ifDefined(mapCalloutItem)))), ([canvasItem]) => canvasItem !== null && canvasItem !== void 0 ? canvasItem : undefined);
const mapCanvasDocument = M.defineMapper(M.read(M.mapRequiredProp('itemsList', M.mapArray(mapCanvasItem))), ([items]) => ({ items: items.filter((i) => i != null) }));
const mapGetCanvasResponse = M.defineMapper(M.read(M.mapRequiredProp('canvas', M.mapRequiredProp('document', M.mapRequiredProp('v1', mapCanvasDocument)))), ([doc]) => doc);
export const mapGetCanvasResponseOrThrow = M.ifInvalidThrow(mapGetCanvasResponse);
//# sourceMappingURL=mapper.js.map
