"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var handle_card_image_upload_exports = {};
__export(handle_card_image_upload_exports, {
  handleCardImageUpload: () => handleCardImageUpload
});
module.exports = __toCommonJS(handle_card_image_upload_exports);
const buildBackgroundImageAttrs = ({
  componentData,
  uploadData
}) => {
  const existingBgImage = componentData.backgroundImage ?? void 0;
  return {
    ...componentData,
    backgroundImage: {
      ...existingBgImage,
      media: {
        src: "src" in uploadData ? uploadData.src : { id: uploadData.file_name },
        width: uploadData.width,
        height: uploadData.height
      },
      opacity: existingBgImage?.opacity ?? 100,
      scaling: existingBgImage?.scaling ?? "COVER",
      position: existingBgImage?.position ?? "CENTER"
    },
    loading: void 0
  };
};
const handleCardImageUpload = async ({
  pickImage,
  publicCommands,
  nodeId
}) => {
  const result = await pickImage({ multiple: false });
  switch (result.type) {
    case "ready-media": {
      const data = result.media[0];
      const componentData = publicCommands?.getBlockComponentData(nodeId);
      const updatedData = buildBackgroundImageAttrs({ componentData, uploadData: data });
      publicCommands?.setBlock(nodeId, "CARD", updatedData);
      return;
    }
    case "cancel": {
      return;
    }
    default: {
      console.error("Unhandled media picker result:", result);
      return;
    }
  }
};
//# sourceMappingURL=handle-card-image-upload.js.map
