import { n as e } from "../../fn-BbK27qJY.js";
import { useCallback as t, useEffect as n, useRef as r, useState as i } from "react";
import a from "prop-types";
import { jsx as o, jsxs as s } from "react/jsx-runtime";
import c from "lodash/identity.js";
import { useResizeDetector as l } from "react-resize-detector";
import u from "lodash/debounce.js";
//#region src/plugins/editor-textarea/components/EditorPane/EditorPane.jsx
var d = ({ getComponent: e, useElementResize: t }) => {
	let n = e("Editor", !0), r = e("EditorPaneBarTop"), i = e("EditorPaneBarRight"), a = e("EditorPaneBarBottom"), c = e("EditorPaneBarLeft"), l = t({ eventName: "editorcontainerresize" });
	return /* @__PURE__ */ s("div", {
		className: "swagger-editor__editor-pane",
		children: [/* @__PURE__ */ s("div", {
			className: "swagger-editor__editor-pane-container-col",
			children: [
				/* @__PURE__ */ o(r, {}),
				/* @__PURE__ */ s("div", {
					className: "swagger-editor__editor-pane-container-row",
					children: [/* @__PURE__ */ o(c, {}), /* @__PURE__ */ o("div", {
						className: "swagger-editor__editor-container",
						ref: l,
						children: /* @__PURE__ */ o(n, {})
					})]
				}),
				/* @__PURE__ */ o(a, {})
			]
		}), /* @__PURE__ */ o(i, {})]
	});
};
d.propTypes = {
	getComponent: a.func.isRequired,
	useElementResize: a.func.isRequired
};
//#endregion
//#region src/plugins/editor-textarea/hooks.js
var f = (e) => (t) => {
	let { editorActions: i } = e(), a = r(null);
	return n(() => {
		let { current: e } = a;
		return i.editorSetup(e, t), () => {
			i.editorTearDown(e, t);
		};
	}, []), a;
}, p = ({ eventName: e }) => {
	let { ref: n } = l({
		onResize: t((t, n) => {
			let r = new globalThis.CustomEvent(e, { detail: {
				width: t,
				height: n
			} });
			globalThis.dispatchEvent(r);
		}, [e]),
		refreshMode: "debounce",
		refreshRate: 0
	});
	return n;
}, m = () => {
	let e = Math.floor(Math.random() * 1e7), [t] = i(String(e));
	return t;
}, h = ({ isReadOnly: e = !1, editorActions: r, editorSelectors: a, useEditorLifecycle: s, EditorContentOrigin: c }) => {
	let l = a.selectContent(), u = m(), d = s("textarea"), [f, p] = i(l), h = t((e) => {
		e.preventDefault(), p(e.target.value), r.setContentDebounced(e.target.value, c.Editor);
	}, [r, c]);
	return n(() => {
		p(l);
	}, [l]), /* @__PURE__ */ o("textarea", {
		id: u,
		ref: d,
		readOnly: e,
		className: "swagger-editor__editor-textarea",
		name: "content",
		value: f,
		onChange: h
	});
};
h.propTypes = {
	isReadOnly: a.bool,
	editorActions: a.shape({ setContentDebounced: a.func.isRequired }).isRequired,
	editorSelectors: a.shape({ selectContent: a.func.isRequired }).isRequired,
	useEditorLifecycle: a.func.isRequired,
	EditorContentOrigin: a.shape({ Editor: a.string.isRequired }).isRequired
};
//#endregion
//#region src/plugins/editor-textarea/components/EditorPaneBars/EditorPaneBarTop.jsx
var g = ({ renderChildren: e = c, renderControls: t = c }) => /* @__PURE__ */ s("div", {
	className: "swagger-editor__editor-pane-bar swagger-editor__editor-pane-bar--top",
	children: [/* @__PURE__ */ o("div", {
		className: "swagger-editor__toolbar-horizontal",
		children: t(null)
	}), e(null)]
});
g.propTypes = {
	renderChildren: a.func,
	renderControls: a.func
};
//#endregion
//#region src/plugins/editor-textarea/components/EditorPaneBars/EditorPaneBarRight.jsx
var _ = ({ renderChildren: e = c, renderControls: t = c }) => /* @__PURE__ */ s("div", {
	className: "swagger-editor__editor-pane-bar swagger-editor__editor-pane-bar--right",
	children: [/* @__PURE__ */ o("div", {
		className: "swagger-editor__toolbar-vertical",
		children: t(null)
	}), e(null)]
});
_.propTypes = {
	renderChildren: a.func,
	renderControls: a.func
};
//#endregion
//#region src/plugins/editor-textarea/components/EditorPaneBars/EditorPaneBarBottom.jsx
var v = ({ renderChildren: e = c, renderControls: t = c }) => /* @__PURE__ */ s("div", {
	className: "swagger-editor__editor-pane-bar swagger-editor__editor-pane-bar--bottom",
	children: [/* @__PURE__ */ o("div", {
		className: "swagger-editor__toolbar-horizontal",
		children: t(null)
	}), e(null)]
});
v.propTypes = {
	renderChildren: a.func,
	renderControls: a.func
};
//#endregion
//#region src/plugins/editor-textarea/components/EditorPaneBars/EditorPaneBarLeft.jsx
var y = ({ renderChildren: e = c, renderControls: t = c }) => /* @__PURE__ */ s("div", {
	className: "swagger-editor__editor-pane-bar swagger-editor__editor-pane-bar--left",
	children: [/* @__PURE__ */ o("div", {
		className: "swagger-editor__toolbar-vertical",
		children: t(null)
	}), e(null)]
});
y.propTypes = {
	renderChildren: a.func,
	renderControls: a.func
};
//#endregion
//#region src/plugins/editor-textarea/actions.js
var b = "editor_setup", x = "editor_tear_down", S = "editor_set_content", C = "editor_clear_content", w = (e, t = "textarea") => ({
	type: b,
	payload: e,
	meta: ["editor", t]
}), T = (e, t = "textarea") => ({
	type: x,
	payload: e,
	meta: ["editor", t]
}), E = (e) => ({
	type: S,
	payload: e,
	meta: {}
}), D = () => ({ type: C }), O = {
	content: "",
	id: null
}, k = {
	[S]: (e, t) => e.set("content", t.payload),
	[b]: (e, t) => t.meta.includes("textarea") ? e.set("id", t.payload.id) : e,
	[x]: (e, t) => !t.meta.includes("textarea") || e.get("id") !== t.payload.id ? e : e.delete("id")
}, A = (e) => e.get("content", O.content), j = (e) => e.get("id", O.id), M = () => (e) => {
	let t = e.editorSelectors.selectId();
	return document.getElementById(t);
}, N = u((e, t, n) => {
	n.editorActions.setContent(e, t);
}, 500), P = (e) => (t, n) => (n !== "monaco" && (globalThis.editor = t, globalThis[n] = t), e(t, n)), F = (e) => (t, n) => (n !== "monaco" && (delete globalThis.editor, delete globalThis[n]), e(t, n)), I = (e, t) => (e, n) => {
	N(e, n, t);
}, L = e((e, t) => () => {
	let { EditorContentOrigin: e } = t;
	t.editorActions.setContent("", e.Clear);
}), R = (e, t) => (n, r) => {
	let { editorActions: i, editorSelectors: a, EditorContentOrigin: o } = t, s = e(n, r);
	return r !== o.Editor && a.selectContent() !== n && i.setContent(n, o.Props), s;
}, z = (e) => {
	let { editorContentFixturesSelectors: t, editorActions: n, EditorContentOrigin: r } = e, i = t.selectAsyncAPI260StreetlightsYAML();
	n.setContent(i, r.InitialFixtureLoad);
}, B = ({ getSystem: e }) => ({
	afterLoad: z,
	rootInjects: {
		useEditorLifecycle: f(e),
		useElementResize: p
	},
	components: {
		EditorPane: d,
		EditorPaneBarTop: g,
		EditorPaneBarRight: _,
		EditorPaneBarBottom: v,
		EditorPaneBarLeft: y,
		Editor: h,
		TextareaEditor: h
	},
	statePlugins: {
		editor: {
			actions: {
				editorSetup: w,
				editorTearDown: T,
				setContent: E,
				setContentDebounced: E,
				clearContent: D
			},
			wrapActions: {
				editorSetup: P,
				editorTearDown: F,
				setContentDebounced: I,
				clearContent: L
			},
			selectors: {
				selectContent: A,
				selectId: j,
				selectEditor: M
			},
			reducers: k
		},
		spec: { wrapActions: { updateSpec: R } }
	}
});
//#endregion
export { B as default };

//# sourceMappingURL=index.js.map