"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 client_message_port_serialization_visitor_exports = {};
__export(client_message_port_serialization_visitor_exports, {
  ClientMessagePortSerializationVisitor: () => ClientMessagePortSerializationVisitor
});
module.exports = __toCommonJS(client_message_port_serialization_visitor_exports);
var import_controls = require("@makeswift/controls");
var import_rich_text_v2 = require("../../rich-text-v2");
var import_function_serialization = require("./function-serialization");
class ClientMessagePortSerializationVisitor extends import_controls.ControlSerializationVisitor {
  transferables = [];
  constructor() {
    const serializeFunctionPlugin = {
      match: import_controls.isFunction,
      serialize: (val) => {
        const r = (0, import_function_serialization.serializeFunction)(val);
        this.transferables.push(r);
        return r;
      }
    };
    const serializeDefinitionPlugin = {
      match: (val) => val instanceof import_controls.ControlDefinition,
      serialize: (val) => val.accept(this)
    };
    super([serializeFunctionPlugin, serializeDefinitionPlugin]);
  }
  getTransferables() {
    return [...this.transferables];
  }
  visitRichTextV2(def) {
    const { plugins, ...config } = def.config;
    const pluginDefs = plugins.map(
      ({ control }) => control ? {
        control: {
          definition: control.definition,
          // FIXME: remove getValue/onChange stubs once we released a version of the builder
          // built against the runtime where these can be optional
          getValue: () => void 0,
          onChange: () => {
          }
        }
      } : {}
    );
    const serialized = (0, import_controls.serializeObject)(
      { config: { ...config, plugins: pluginDefs } },
      this.serializationPlugins
    );
    return { ...serialized, type: import_rich_text_v2.RichTextV2Definition.type };
  }
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  ClientMessagePortSerializationVisitor
});
//# sourceMappingURL=client-message-port-serialization-visitor.js.map