import { X as escape_html } from './context-zH5kvtGY.js';
import { s as stringify } from './index2-BuOY2QE4.js';
import 'js-yaml';
import { P as Panel } from './edit-workspace-context-OTOIRCI0.js';
import { o as onDestroy } from './index-server-CefdgakO.js';

function PopoverModal($$renderer, $$props) {
  let { title, onClose, children } = $$props;
  $$renderer.push(`<div class="absolute inset-0 z-20 bg-black/20"></div> <div class="absolute inset-2 z-30 flex min-w-0 flex-col overflow-hidden rounded-lg border border-rc-gray-600 bg-rc-gray-900 shadow-2xl"><div class="flex items-center justify-between border-b border-rc-gray-700 px-3 py-2"><button type="button" class="inline-flex h-7 w-7 items-center justify-center rounded-md text-rc-gray-200 hover:bg-rc-gray-700" aria-label="Close" title="Close">X</button> <div class="text-sm font-semibold text-rc-gray-200">${escape_html(title)}</div> <div class="w-7"></div></div> <div class="min-h-0 flex flex-1 flex-col overflow-hidden">`);
  children($$renderer);
  $$renderer.push(`<!----></div></div>`);
}
function ContextEditor($$renderer, $$props) {
  $$renderer.component(($$renderer2) => {
    let editor = null;
    let model = null;
    let editorDisposables = [];
    let {
      context,
      onContextChanged,
      class: className,
      suppressErrors = false,
      defaultFormat = "yaml",
      hideHeader = false
    } = $$props;
    onDestroy(() => {
      for (const d of editorDisposables) {
        try {
          d.dispose();
        } catch {
        }
      }
      editorDisposables = [];
      const toDisposeModel = model;
      model = null;
      try {
        if (editor) {
          try {
            editor.setModel(null);
          } catch {
          }
          editor.dispose();
        }
      } finally {
        editor = null;
      }
      try {
        toDisposeModel?.dispose();
      } catch {
      }
    });
    Panel($$renderer2, {
      class: `min-h-0 overflow-hidden ${stringify(
        // Keep model language in sync without recreating the editor
        // Update value only when actual text differs to avoid caret jumps
        // If the next canonical text equals the last user-emitted serialization,
        // skip setting the value to preserve caret/selection.
        className
      )}`,
      children: ($$renderer3) => {
        $$renderer3.push(`<div class="h-full min-h-0 w-full"></div>`);
      }});
  });
}

export { ContextEditor as C, PopoverModal as P };
//# sourceMappingURL=ContextEditor-CfjBPLpI.js.map
