import { useCallback as e } from "react";
import t from "prop-types";
import { Fragment as n, jsx as r, jsxs as i } from "react/jsx-runtime";
import { createSelector as a } from "reselect";
import { fromJS as o } from "immutable";
//#region src/plugins/editor-monaco-yaml-paste/components/TransformDialog.jsx
var s = ({ getComponent: t, editorMonacoYAMLPasteActions: n, editorMonacoYAMLPasteSelectors: i }) => {
	let a = t("ConfirmDialog", !0), o = e((e) => {
		let t = i.selectClipboardData(), r = i.selectClipboardRange();
		e && n.transformClipboardData({
			text: t,
			range: r
		}), n.closeTransformDialog();
	}, [n, i]);
	return /* @__PURE__ */ r(a, {
		isOpen: i.selectIsTransformDialogOpen(),
		title: "Would you like to convert your JSON into YAML?",
		onClose: o
	});
};
s.propTypes = {
	getComponent: t.func.isRequired,
	editorMonacoYAMLPasteActions: t.shape({
		transformClipboardData: t.func.isRequired,
		closeTransformDialog: t.func.isRequired
	}).isRequired,
	editorMonacoYAMLPasteSelectors: t.shape({
		selectClipboardData: t.func.isRequired,
		selectClipboardRange: t.func.isRequired,
		selectIsTransformDialogOpen: t.func.isRequired
	}).isRequired
};
//#endregion
//#region src/plugins/editor-monaco-yaml-paste/extensions/editor-monaco/wrap-components/EditorWrapper.jsx
var c = (e, t) => {
	let a = t.getComponent("EditorMonacoYAMLTransformDialog", !0);
	return ({ ...t }) => /* @__PURE__ */ i(n, { children: [/* @__PURE__ */ r(a, {}), /* @__PURE__ */ r(e, { ...t })] });
}, l = "editor_transform_dialog_close", u = "editor_transform_dialog_open_started", d = "editor_transform_dialog_open_success", f = "editor_transform_dialog_open_failure", p = "editor_transform_clipboard_data_started", m = "editor_transform_clipboard_data_success", h = "editor_transform_clipboard_data_failure", g = () => ({ type: l }), _ = ({ text: e, range: t, requestId: n }) => ({
	type: p,
	payload: e,
	meta: {
		range: t,
		requestId: n
	}
}), v = ({ text: e, range: t, requestId: n }) => ({
	type: m,
	payload: e,
	meta: {
		range: t,
		requestId: n
	}
}), y = ({ error: e, text: t, range: n, requestId: r }) => ({
	type: h,
	payload: e,
	error: !0,
	meta: {
		text: t,
		range: n,
		requestId: r
	}
}), b = ({ text: e, range: t, requestId: n }) => ({
	type: u,
	payload: e,
	meta: {
		range: t,
		requestId: n
	}
}), x = ({ text: e, range: t, requestId: n }) => ({
	type: d,
	payload: e,
	meta: {
		range: t,
		requestId: n
	}
}), S = ({ error: e, text: t, range: n, requestId: r }) => ({
	type: f,
	payload: e,
	error: !0,
	meta: {
		text: t,
		range: n,
		requestId: r
	}
}), C = ({ text: e, range: t }) => (n) => {
	let { editorMonacoYAMLPasteActions: r, editorSelectors: i, fn: a } = n, o = a.generateRequestId();
	r.openTransformDialogStarted({
		text: e,
		range: t,
		requestId: o
	});
	try {
		let n = a.isValidJSONObject(e) || a.isValidJSONArray(e), s = i.selectEditor().getValue() === e, c = i.selectIsContentFormatYAML();
		if (n && (s || c)) r.openTransformDialogSuccess({
			text: e,
			range: t,
			requestId: o
		});
		else throw Error("Cannot convert clipboard data to YAML.");
	} catch (n) {
		r.openTransformDialogFailure({
			error: n,
			text: e,
			range: t,
			requestId: o
		});
	}
}, w = ({ text: e, range: t }) => async (n) => {
	let { editorActions: r, editorSelectors: i, editorMonacoYAMLPasteActions: a, fn: o } = n, s = o.generateRequestId();
	a.transformClipboardDataStarted({
		text: e,
		range: t,
		requestId: s
	});
	try {
		let n = await r.convertContentToYAML(e);
		if (n.error) throw n;
		let o = " ".repeat(t.startColumn - 1), c = n.payload.split("\n").map((e, t) => t === 0 ? e : o + e).join("\n").replace(/\t/g, "  ");
		return i.selectEditor().executeEdits("", [{
			range: t,
			text: c,
			forceMoveMarkers: !0
		}]), a.transformClipboardDataSuccess({
			text: n.payload,
			range: t,
			requestId: s
		});
	} catch (n) {
		return a.transformClipboardDataFailure({
			error: n,
			text: e,
			range: t,
			requestId: s
		});
	}
}, T = {
	isTransformDialogOpen: !1,
	clipboardData: null,
	clipboardRange: null
}, E = {
	[d]: (e, t) => e.merge({
		isTransformDialogOpen: !0,
		clipboardData: t.payload,
		clipboardRange: o({
			startLineNumber: t.meta.range.startLineNumber,
			startColumn: t.meta.range.startColumn,
			endLineNumber: t.meta.range.endLineNumber,
			endColumn: t.meta.range.endColumn
		})
	}),
	[l]: (e) => e.merge({
		isTransformDialogOpen: !1,
		clipboardData: T.clipboardData,
		clipboardRange: T.clipboardRange
	})
}, D = (e) => e.get("clipboardData", T.clipboardData), O = a([(e, t) => t.monaco, (e) => e.get("clipboardRange", T.clipboardRange)], (e, t) => {
	if (t && e) {
		let n = t.toJS();
		return new e.Range(n.startLineNumber, n.startColumn, n.endLineNumber, n.endColumn);
	}
	return T.clipboardRange;
}), k = (e) => e.get("isTransformDialogOpen", T.isTransformDialogOpen), A = ({ system: e }) => {
	let { editorMonacoYAMLPasteActions: t, monaco: n } = e, r = [];
	return r.push(n.editor.onDidCreateEditor((e) => {
		r.push(e.onDidPaste((n) => {
			let r = e.getModel().getValueInRange(n.range);
			t.openTransformDialog({
				text: r,
				range: n.range
			});
		}));
	})), r.push(n.editor.onDidCreateEditor((e) => {
		r.push(e.onDidDispose(() => {
			r.forEach((e) => e.dispose()), r.length = 0;
		}));
	})), r;
};
//#endregion
//#region src/plugins/editor-monaco-yaml-paste/after-load.js
function j(e) {
	let { monaco: t, fn: n } = e, r = t !== void 0, i = this.statePlugins.editorMonacoYAMLPaste;
	r && (i.disposables && i.disposables.dispose(), i.disposables = A({ system: e }), typeof n.createSystemSelector == "function" && (i.selectors.selectClipboardRange = n.createSystemSelector(O)));
}
//#endregion
//#region src/plugins/editor-monaco-yaml-paste/index.js
var M = () => ({
	afterLoad: j,
	components: { EditorMonacoYAMLTransformDialog: s },
	wrapComponents: { Editor: c },
	statePlugins: { editorMonacoYAMLPaste: {
		actions: {
			closeTransformDialog: g,
			openTransformDialog: C,
			openTransformDialogStarted: b,
			openTransformDialogSuccess: x,
			openTransformDialogFailure: S,
			transformClipboardData: w,
			transformClipboardDataStarted: _,
			transformClipboardDataSuccess: v,
			transformClipboardDataFailure: y
		},
		selectors: {
			selectClipboardData: D,
			selectIsTransformDialogOpen: k
		},
		reducers: E
	} }
});
//#endregion
export { M as default };

//# sourceMappingURL=index.js.map