import { Transforms } from "slate";
import {
  findBreakpointOverride,
  Slate
} from "@makeswift/controls";
import { getBlocksInSelection } from "../selectors";
function setBlockKeyForDevice(editor, breakpoints, deviceId, key, value, options) {
  const at = options?.at ?? editor.selection;
  if (!at)
    return;
  const rootElements = getBlocksInSelection(editor);
  for (const [node, path] of rootElements) {
    if (Slate.isBlock(node)) {
      const deviceValues = node[key] ?? [];
      const currentDeviceValue = findBreakpointOverride(breakpoints, deviceValues, deviceId, (v) => v);
      const nextDeviceValue = {
        ...currentDeviceValue,
        deviceId,
        value
      };
      Transforms.setNodes(
        editor,
        {
          [key]: [...deviceValues.filter((v) => v.deviceId !== deviceId), nextDeviceValue]
        },
        { at: path }
      );
    }
  }
}
export {
  setBlockKeyForDevice
};
//# sourceMappingURL=setBlockKeyForDevice.js.map