import { jsx as _jsx } from "react/jsx-runtime";
import { useEditContext } from "../client/editContext";
import { useFieldModification } from "../client/fieldModificationStore";
import { useSlotContext } from "../views/editorSlotContext";
import { measureBridgeFieldRect, rectEquals, } from "./overlay/geometry";
import { useOverlayMeasurement } from "./overlay/useOverlayMeasurement";
export function FieldEditedIndicator({ field, pageViewContext, }) {
    const editContext = useEditContext();
    if (!editContext)
        return null;
    const pageVersion = pageViewContext.pageItemDescriptor?.version;
    const isTargetingCurrentPageLatest = field.item.version === 0 &&
        field.item.id === pageViewContext.pageItemDescriptor?.id &&
        field.item.language === pageViewContext.pageItemDescriptor?.language;
    const descriptor = {
        fieldId: field.fieldId,
        item: {
            ...field.item,
            version: isTargetingCurrentPageLatest && typeof pageVersion === "number"
                ? pageVersion
                : field.item.version,
        },
    };
    return (_jsx(SingleBridgeFieldEditedIndicator, { field: field, fieldDescriptor: descriptor, pageViewContext: pageViewContext }));
}
function SingleBridgeFieldEditedIndicator({ field, fieldDescriptor, pageViewContext, }) {
    const slotContext = useSlotContext();
    const { isSaved } = useFieldModification(field.fieldId, field.item.id, field.item.language, field.item.version, slotContext?.fieldModificationStore);
    const indicatorRect = useOverlayMeasurement((metrics) => measureBridgeFieldRect(pageViewContext.bridgeGeometry, pageViewContext.bridgeStructure, fieldDescriptor, metrics), [
        pageViewContext.bridgeGeometry,
        pageViewContext.bridgeStructure,
        field.timestamp,
        fieldDescriptor.fieldId,
        fieldDescriptor.item.id,
        fieldDescriptor.item.language,
        fieldDescriptor.item.version,
    ], {
        initialValue: null,
        equals: rectEquals,
        interests: ["viewport", "layout", "text", "adornment-data"],
    });
    if (!indicatorRect)
        return null;
    const stateClass = isSaved ? "saved" : "saving";
    return (_jsx("div", { className: `focus-shadow edited-field ${stateClass} pointer-events-none absolute`, style: {
            left: indicatorRect.x,
            top: indicatorRect.y,
            width: indicatorRect.width,
            height: indicatorRect.height,
            zIndex: 800,
        } }));
}
//# sourceMappingURL=FieldEditedIndicator.js.map