import { c as Kind } from "./parser-B0sh99Kk.js";
import { r as typeDefsDoc } from "./documents-Bpu0aSLb.js";
import { d as makeMinimalObjectForStateType, h as validateStateObject, i as StateValidationError, p as makeStateSchemaNameForScope, r as ensureValidStateSchemaName, t as cn, u as makeInitialSchemaDoc } from "./style-DYS_RFSN.js";
import { C as useControllableState, D as composeEventHandlers, E as useComposedRefs, S as Primitive, a as Content2, b as Presence, c as Root3, g as cn$1, i as Trigger$1, l as Trigger, m as Icon, n as List, o as Portal, r as Root2, s as Provider, t as Content, w as createContextScope, x as useSize } from "./dist-DOMEWT3x.js";
import { n as safeParseSdl, r as useSchemaContext } from "./schema-context-C0GpuR27.js";
import * as React$1 from "react";
import React, { Suspense, forwardRef, lazy, useCallback, useEffect, useId, useMemo, useRef, useState } from "react";
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
//#region ../design-system/dist/ui/components/tooltip/tooltip.js
const TooltipContent = /* @__PURE__ */ forwardRef(({ children, className, ...props }, ref) => {
	return /* @__PURE__ */ jsx(Content2, {
		ref,
		...props,
		className: cn$1("z-50 overflow-hidden rounded-md text-sm", "border border-gray-200 bg-white text-gray-900 dark:border-gray-900 dark:bg-slate-900 dark:text-gray-200", "px-3 py-1.5 shadow-md", "data-[state=open]:animate-zoom-in", "data-[state=closed]:animate-zoom-out", "data-[side=bottom]:animate-slide-in-from-top", "data-[side=left]:animate-slide-in-from-right", "data-[side=right]:animate-slide-in-from-left", "data-[side=top]:animate-slide-in-from-bottom", className),
		children
	});
});
const Tooltip = ({ content, children, triggerAsChild = false, delayDuration = 0, ...props }) => {
	const { open, defaultOpen, onOpenChange, ...rest } = props;
	return /* @__PURE__ */ jsxs(Root3, {
		defaultOpen,
		delayDuration,
		onOpenChange,
		open,
		children: [/* @__PURE__ */ jsx(Trigger, {
			asChild: triggerAsChild,
			type: triggerAsChild ? void 0 : "button",
			children
		}), /* @__PURE__ */ jsx(Portal, { children: /* @__PURE__ */ jsx(TooltipContent, {
			sideOffset: 3,
			...rest,
			children: content
		}) })]
	});
};
//#endregion
//#region ../design-system/dist/ui/components/form-label/form-label.js
const FormLabel = ({ children, required, disabled, description, hasError, inline, className, ...htmlLabelProps }) => {
	const classes = cn$1("inline-flex items-center text-sm font-medium", inline ? "leading-[22px]" : "leading-4", `text-gray-900 ${inline ? "dark:text-gray-400" : "dark:text-gray-50"}`, hasError && "group-hover:text-red-900! dark:group-hover:text-red-900!", hasError && inline && "text-red-800 dark:text-red-800", hasError && !inline && "text-red-900 dark:text-red-900", disabled && `cursor-not-allowed text-gray-700 ${inline ? "dark:text-gray-600" : "dark:text-gray-300"}`, inline ? !disabled && "group-hover:text-gray-900 dark:group-hover:text-slate-50" : "mb-[3px]", className);
	if (!children) return null;
	return /* @__PURE__ */ jsxs("label", {
		className: classes,
		...htmlLabelProps,
		children: [
			children,
			required && /* @__PURE__ */ jsx("span", {
				className: cn$1("ml-1 text-gray-800 group-hover:text-gray-900 dark:text-gray-400 dark:group-hover:text-slate-50", hasError && `${inline ? "text-red-800!" : "text-red-900!"} group-hover:text-red-900!`),
				children: "*"
			}),
			description && /* @__PURE__ */ jsx(Provider, { children: /* @__PURE__ */ jsx(Tooltip, {
				content: description,
				children: /* @__PURE__ */ jsx(Icon, {
					name: "CircleInfo",
					size: 16,
					className: cn$1("ml-1 cursor-pointer text-gray-600 hover:text-gray-500 dark:text-gray-500 dark:hover:text-gray-500", disabled && "text-gray-500")
				})
			}) })
		]
	});
};
//#endregion
//#region ../design-system/dist/ui/components/form-message/form-message.js
const defaultElement = "p";
const FormMessage = ({ children, type = "info", as, className, ...props }) => {
	const Component = as || defaultElement;
	const classes = cn$1("mb-0 inline-flex items-center text-xs font-medium", {
		error: "text-red-900 dark:text-red-900",
		info: "text-blue-900 dark:text-blue-900",
		warning: "text-yellow-900 dark:text-yellow-900"
	}[type], className);
	return /* @__PURE__ */ jsx(Component, {
		"data-type": type,
		className: classes,
		...props,
		children
	});
};
//#endregion
//#region ../design-system/dist/ui/components/form-message/message-list.js
const FormMessageList = ({ messages, type = "info", className, ...props }) => {
	if (messages.length === 0) return null;
	if (messages.length === 1) return /* @__PURE__ */ jsx(FormMessage, {
		type,
		...props,
		children: messages[0]
	});
	const typeClasses = {
		error: "before:bg-red-900 dark:before:bg-red-900",
		info: "before:bg-blue-900 dark:before:bg-blue-900",
		warning: "before:bg-orange-900 dark:before:bg-orange-900"
	};
	return /* @__PURE__ */ jsx("ul", {
		className: cn$1("flex flex-col gap-1", className),
		...props,
		children: messages.map((message) => /* @__PURE__ */ jsx(FormMessage, {
			as: "li",
			type,
			className: cn$1("relative pl-4", "before:absolute before:top-[0.4em] before:left-0 before:size-2 before:rounded-full", typeClasses[type]),
			children: message
		}, message))
	});
};
//#endregion
//#region ../../node_modules/.pnpm/@radix-ui+react-use-previous@1.1.1_@types+react@19.2.14_react@19.2.6/node_modules/@radix-ui/react-use-previous/dist/index.mjs
function usePrevious(value) {
	const ref = React$1.useRef({
		value,
		previous: value
	});
	return React$1.useMemo(() => {
		if (ref.current.value !== value) {
			ref.current.previous = ref.current.value;
			ref.current.value = value;
		}
		return ref.current.previous;
	}, [value]);
}
//#endregion
//#region ../../node_modules/.pnpm/@radix-ui+react-checkbox@1.3.3_@types+react-dom@19.2.3_@types+react@19.2.14__@types+rea_36946c77eec45f5a9fc04b1442c78a6c/node_modules/@radix-ui/react-checkbox/dist/index.mjs
var CHECKBOX_NAME = "Checkbox";
var [createCheckboxContext, createCheckboxScope] = createContextScope(CHECKBOX_NAME);
var [CheckboxProviderImpl, useCheckboxContext] = createCheckboxContext(CHECKBOX_NAME);
function CheckboxProvider(props) {
	const { __scopeCheckbox, checked: checkedProp, children, defaultChecked, disabled, form, name, onCheckedChange, required, value = "on", internal_do_not_use_render } = props;
	const [checked, setChecked] = useControllableState({
		prop: checkedProp,
		defaultProp: defaultChecked ?? false,
		onChange: onCheckedChange,
		caller: CHECKBOX_NAME
	});
	const [control, setControl] = React$1.useState(null);
	const [bubbleInput, setBubbleInput] = React$1.useState(null);
	const hasConsumerStoppedPropagationRef = React$1.useRef(false);
	const isFormControl = control ? !!form || !!control.closest("form") : true;
	const context = {
		checked,
		disabled,
		setChecked,
		control,
		setControl,
		name,
		form,
		value,
		hasConsumerStoppedPropagationRef,
		required,
		defaultChecked: isIndeterminate(defaultChecked) ? false : defaultChecked,
		isFormControl,
		bubbleInput,
		setBubbleInput
	};
	return /* @__PURE__ */ jsx(CheckboxProviderImpl, {
		scope: __scopeCheckbox,
		...context,
		children: isFunction(internal_do_not_use_render) ? internal_do_not_use_render(context) : children
	});
}
var TRIGGER_NAME = "CheckboxTrigger";
var CheckboxTrigger = React$1.forwardRef(({ __scopeCheckbox, onKeyDown, onClick, ...checkboxProps }, forwardedRef) => {
	const { control, value, disabled, checked, required, setControl, setChecked, hasConsumerStoppedPropagationRef, isFormControl, bubbleInput } = useCheckboxContext(TRIGGER_NAME, __scopeCheckbox);
	const composedRefs = useComposedRefs(forwardedRef, setControl);
	const initialCheckedStateRef = React$1.useRef(checked);
	React$1.useEffect(() => {
		const form = control?.form;
		if (form) {
			const reset = () => setChecked(initialCheckedStateRef.current);
			form.addEventListener("reset", reset);
			return () => form.removeEventListener("reset", reset);
		}
	}, [control, setChecked]);
	return /* @__PURE__ */ jsx(Primitive.button, {
		type: "button",
		role: "checkbox",
		"aria-checked": isIndeterminate(checked) ? "mixed" : checked,
		"aria-required": required,
		"data-state": getState(checked),
		"data-disabled": disabled ? "" : void 0,
		disabled,
		value,
		...checkboxProps,
		ref: composedRefs,
		onKeyDown: composeEventHandlers(onKeyDown, (event) => {
			if (event.key === "Enter") event.preventDefault();
		}),
		onClick: composeEventHandlers(onClick, (event) => {
			setChecked((prevChecked) => isIndeterminate(prevChecked) ? true : !prevChecked);
			if (bubbleInput && isFormControl) {
				hasConsumerStoppedPropagationRef.current = event.isPropagationStopped();
				if (!hasConsumerStoppedPropagationRef.current) event.stopPropagation();
			}
		})
	});
});
CheckboxTrigger.displayName = TRIGGER_NAME;
var Checkbox$1 = React$1.forwardRef((props, forwardedRef) => {
	const { __scopeCheckbox, name, checked, defaultChecked, required, disabled, value, onCheckedChange, form, ...checkboxProps } = props;
	return /* @__PURE__ */ jsx(CheckboxProvider, {
		__scopeCheckbox,
		checked,
		defaultChecked,
		disabled,
		required,
		onCheckedChange,
		name,
		form,
		value,
		internal_do_not_use_render: ({ isFormControl }) => /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx(CheckboxTrigger, {
			...checkboxProps,
			ref: forwardedRef,
			__scopeCheckbox
		}), isFormControl && /* @__PURE__ */ jsx(CheckboxBubbleInput, { __scopeCheckbox })] })
	});
});
Checkbox$1.displayName = CHECKBOX_NAME;
var INDICATOR_NAME = "CheckboxIndicator";
var CheckboxIndicator = React$1.forwardRef((props, forwardedRef) => {
	const { __scopeCheckbox, forceMount, ...indicatorProps } = props;
	const context = useCheckboxContext(INDICATOR_NAME, __scopeCheckbox);
	return /* @__PURE__ */ jsx(Presence, {
		present: forceMount || isIndeterminate(context.checked) || context.checked === true,
		children: /* @__PURE__ */ jsx(Primitive.span, {
			"data-state": getState(context.checked),
			"data-disabled": context.disabled ? "" : void 0,
			...indicatorProps,
			ref: forwardedRef,
			style: {
				pointerEvents: "none",
				...props.style
			}
		})
	});
});
CheckboxIndicator.displayName = INDICATOR_NAME;
var BUBBLE_INPUT_NAME = "CheckboxBubbleInput";
var CheckboxBubbleInput = React$1.forwardRef(({ __scopeCheckbox, ...props }, forwardedRef) => {
	const { control, hasConsumerStoppedPropagationRef, checked, defaultChecked, required, disabled, name, value, form, bubbleInput, setBubbleInput } = useCheckboxContext(BUBBLE_INPUT_NAME, __scopeCheckbox);
	const composedRefs = useComposedRefs(forwardedRef, setBubbleInput);
	const prevChecked = usePrevious(checked);
	const controlSize = useSize(control);
	React$1.useEffect(() => {
		const input = bubbleInput;
		if (!input) return;
		const inputProto = window.HTMLInputElement.prototype;
		const setChecked = Object.getOwnPropertyDescriptor(inputProto, "checked").set;
		const bubbles = !hasConsumerStoppedPropagationRef.current;
		if (prevChecked !== checked && setChecked) {
			const event = new Event("click", { bubbles });
			input.indeterminate = isIndeterminate(checked);
			setChecked.call(input, isIndeterminate(checked) ? false : checked);
			input.dispatchEvent(event);
		}
	}, [
		bubbleInput,
		prevChecked,
		checked,
		hasConsumerStoppedPropagationRef
	]);
	const defaultCheckedRef = React$1.useRef(isIndeterminate(checked) ? false : checked);
	return /* @__PURE__ */ jsx(Primitive.input, {
		type: "checkbox",
		"aria-hidden": true,
		defaultChecked: defaultChecked ?? defaultCheckedRef.current,
		required,
		disabled,
		name,
		value,
		form,
		...props,
		tabIndex: -1,
		ref: composedRefs,
		style: {
			...props.style,
			...controlSize,
			position: "absolute",
			pointerEvents: "none",
			opacity: 0,
			margin: 0,
			transform: "translateX(-100%)"
		}
	});
});
CheckboxBubbleInput.displayName = BUBBLE_INPUT_NAME;
function isFunction(value) {
	return typeof value === "function";
}
function isIndeterminate(checked) {
	return checked === "indeterminate";
}
function getState(checked) {
	return isIndeterminate(checked) ? "indeterminate" : checked ? "checked" : "unchecked";
}
//#endregion
//#region ../design-system/dist/ui/components/checkbox/checkbox-base.js
const CheckboxBase = /* @__PURE__ */ React$1.forwardRef(({ className, checked, invalid, ...props }, ref) => /* @__PURE__ */ jsx(Checkbox$1, {
	ref,
	className: cn$1("peer size-4 shrink-0 rounded-sm", "border shadow-sm shadow-black/4", "transition-shadow", "focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:outline-none", "disabled:cursor-not-allowed disabled:border-gray-700 disabled:data-[invalid=false]:data-[state=checked]:bg-gray-700 disabled:data-[invalid=false]:data-[state=indeterminate]:bg-gray-700 dark:disabled:data-[invalid=false]:data-[state=checked]:bg-gray-500 dark:disabled:data-[invalid=false]:data-[state=indeterminate]:bg-gray-500", "data-state:border-gray-700 dark:data-state:border-gray-500", "data-[state=checked]:bg-gray-900 data-[state=indeterminate]:bg-gray-900 dark:data-[state=checked]:bg-gray-400 dark:data-[state=indeterminate]:bg-gray-400", "data-[state=checked]:text-slate-50 data-[state=indeterminate]:text-slate-50 dark:data-[state=checked]:text-gray-900 dark:data-[state=indeterminate]:text-gray-900", !props.disabled && ["group-hover:border-gray-900 data-[state=checked]:group-hover:bg-gray-900 data-[state=indeterminate]:group-hover:bg-gray-900", "dark:group-hover:border-slate-50 dark:data-[state=checked]:group-hover:bg-slate-50 dark:data-[state=indeterminate]:group-hover:bg-slate-50"], "data-[invalid=true]:data-state:border-red-800! data-[invalid=true]:data-[state=checked]:bg-red-800! data-[invalid=true]:data-[state=indeterminate]:bg-red-800!", "dark:data-[invalid=true]:data-state:border-red-800! dark:data-[invalid=true]:data-[state=checked]:bg-red-800! dark:data-[invalid=true]:data-[state=indeterminate]:bg-red-800!", "data-[invalid=true]:group-hover:border-red-900! data-[invalid=true]:data-[state=checked]:group-hover:bg-red-900! data-[invalid=true]:data-[state=indeterminate]:group-hover:bg-red-900!", className),
	checked,
	"data-invalid": invalid,
	...props,
	children: /* @__PURE__ */ jsx(CheckboxIndicator, {
		className: "flex items-center justify-center text-current",
		children: checked === "indeterminate" ? /* @__PURE__ */ jsx("svg", {
			width: "9",
			height: "9",
			viewBox: "0 0 9 9",
			fill: "currentcolor",
			xmlns: "http://www.w3.org/2000/svg",
			children: /* @__PURE__ */ jsx("path", {
				fillRule: "evenodd",
				clipRule: "evenodd",
				d: "M0.75 4.5C0.75 4.08579 1.08579 3.75 1.5 3.75H7.5C7.91421 3.75 8.25 4.08579 8.25 4.5C8.25 4.91421 7.91421 5.25 7.5 5.25H1.5C1.08579 5.25 0.75 4.91421 0.75 4.5Z"
			})
		}) : checked ? /* @__PURE__ */ jsx("svg", {
			width: "9",
			height: "9",
			viewBox: "0 0 9 9",
			fill: "currentcolor",
			xmlns: "http://www.w3.org/2000/svg",
			children: /* @__PURE__ */ jsx("path", {
				fillRule: "evenodd",
				clipRule: "evenodd",
				d: "M8.53547 0.62293C8.88226 0.849446 8.97976 1.3142 8.75325 1.66099L4.5083 8.1599C4.38833 8.34356 4.19397 8.4655 3.9764 8.49358C3.75883 8.52167 3.53987 8.45309 3.3772 8.30591L0.616113 5.80777C0.308959 5.52987 0.285246 5.05559 0.563148 4.74844C0.84105 4.44128 1.31533 4.41757 1.62249 4.69547L3.73256 6.60459L7.49741 0.840706C7.72393 0.493916 8.18868 0.396414 8.53547 0.62293Z"
			})
		}) : null
	})
}));
CheckboxBase.displayName = "CheckboxBase";
//#endregion
//#region ../design-system/dist/ui/components/checkbox/checkbox.js
const Checkbox = /* @__PURE__ */ React.forwardRef(({ id: idProp, name, label, value, defaultValue, disabled, required, description, errors, warnings, onChange, className, ...props }, ref) => {
	const generatedId = useId();
	const id = idProp ?? generatedId;
	const hasError = !!errors?.length;
	const castValue = (value) => {
		if (value === "true") return true;
		if (value === "false") return false;
		return value;
	};
	return /* @__PURE__ */ jsxs("div", {
		className: cn$1("flex flex-col gap-2"),
		children: [
			/* @__PURE__ */ jsxs("div", {
				className: cn$1("group flex items-center space-x-2", className),
				children: [/* @__PURE__ */ jsx(CheckboxBase, {
					id,
					name,
					checked: castValue(value ?? defaultValue),
					disabled,
					onCheckedChange: onChange,
					required,
					invalid: hasError,
					"aria-invalid": hasError,
					ref,
					...props
				}), /* @__PURE__ */ jsx(FormLabel, {
					htmlFor: id,
					required,
					disabled,
					hasError,
					description,
					className: cn$1(!disabled && "group-hover:cursor-pointer"),
					inline: true,
					children: label
				})]
			}),
			warnings && /* @__PURE__ */ jsx(FormMessageList, {
				type: "warning",
				messages: warnings
			}),
			errors && /* @__PURE__ */ jsx(FormMessageList, {
				type: "error",
				messages: errors
			})
		]
	});
});
Checkbox.displayName = "Checkbox";
//#endregion
//#region editors/document-model-editor/components/button.tsx
const Button = forwardRef((props, ref) => {
	const { className, ...rest } = props;
	return /* @__PURE__ */ jsx("button", {
		ref,
		...rest,
		className: cn("h-10 rounded-md border border-gray-200 bg-gray-50 px-4 py-2 text-sm font-medium whitespace-nowrap text-gray-800 transition-colors hover:bg-gray-100 hover:text-gray-900 focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:outline-none disabled:pointer-events-none disabled:opacity-50", className)
	});
});
//#endregion
//#region editors/document-model-editor/components/state-error.tsx
function StateValidationErrorMessage({ error }) {
	const { payload } = error;
	switch (payload.kind) {
		case "MISSING": return /* @__PURE__ */ jsxs("span", { children: [
			"Field ",
			/* @__PURE__ */ jsx("strong", { children: payload.field }),
			" is missing."
		] });
		case "MISSING_OPTIONAL": return /* @__PURE__ */ jsxs("span", { children: [
			"Optional field ",
			/* @__PURE__ */ jsx("strong", { children: payload.field }),
			" is not defined."
		] });
		case "UNKNOWN_FIELD": return /* @__PURE__ */ jsxs("span", { children: [
			"Field ",
			/* @__PURE__ */ jsx("strong", { children: payload.field }),
			" is not a known field."
		] });
		case "NON_NULL": return /* @__PURE__ */ jsxs("span", { children: [
			"Field ",
			/* @__PURE__ */ jsx("strong", { children: payload.field }),
			" cannot be null."
		] });
		case "TYPE": return /* @__PURE__ */ jsxs("span", { children: [
			"Field ",
			/* @__PURE__ */ jsx("strong", { children: payload.field }),
			payload.expectedType ? /* @__PURE__ */ jsxs(Fragment$1, { children: [
				" ",
				"must be a",
				" ",
				/* @__PURE__ */ jsx("strong", { children: payload.expectedType.replace(/!/g, "") }),
				"."
			] }) : /* @__PURE__ */ jsx(Fragment$1, { children: " has an invalid value." })
		] });
		case "RECURSIVE_TYPE": return /* @__PURE__ */ jsxs("span", { children: [
			"Field ",
			/* @__PURE__ */ jsx("strong", { children: payload.typeName }),
			" has a recursive type. It must be optional."
		] });
		default: return /* @__PURE__ */ jsx("span", { children: "Invalid value." });
	}
}
//#endregion
//#region editors/document-model-editor/components/tabs.tsx
const Tabs = Root2;
const TabsList = React$1.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsx(List, {
	ref,
	className: cn("flex items-center justify-center rounded-xl bg-slate-50 p-1 shadow-inner", className),
	...props
}));
TabsList.displayName = List.displayName;
const TabsTrigger = React$1.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsx(Trigger$1, {
	ref,
	className: cn("flex w-full items-center justify-center rounded-lg p-1 text-sm whitespace-nowrap text-gray-500 transition-all disabled:pointer-events-none disabled:opacity-50 data-[state=active]:bg-gray-50 data-[state=active]:text-gray-800 data-[state=active]:shadow-tab", className),
	...props
}));
TabsTrigger.displayName = Trigger$1.displayName;
const TabsContent = React$1.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsx(Content, {
	ref,
	className: cn("", className),
	...props
}));
TabsContent.displayName = Content.displayName;
//#endregion
//#region editors/document-model-editor/components/state-schemas.tsx
const GraphqlEditor = lazy(() => import("./graphql-editor-CnaQ3XWx.js"));
const JSONEditor = lazy(() => import("./json-editor-h3cffF6X.js"));
function StateEditor({ modelName, stateSchema, initialValue, setStateSchema, setInitialState, scope }) {
	const { sharedSchema: sharedSchemaSdl, error: sharedSchemaError } = useSchemaContext();
	const [showStandardLib, setShowStandardLib] = useState(false);
	const [syncWithSchema, setSyncWithSchema] = useState(true);
	const customLinter = useCallback((doc) => ensureValidStateSchemaName(doc, modelName, scope), [modelName, scope]);
	const schemaErrors = useMemo(() => {
		const errors = ensureValidStateSchemaName(stateSchema, modelName, scope);
		if (sharedSchemaError) return [...errors, sharedSchemaError];
		return errors;
	}, [
		stateSchema,
		modelName,
		scope,
		sharedSchemaError
	]);
	const handleToggleStandardLib = useCallback(() => {
		setShowStandardLib((prev) => !prev);
	}, []);
	const handleSchemaUpdate = useCallback((newDoc) => setStateSchema(newDoc, scope), [setStateSchema, scope]);
	const handleInitialStateUpdate = useCallback((newDoc) => setInitialState(newDoc, scope), [setInitialState, scope]);
	const hasSyncedRef = useRef(false);
	const { initialValueErrors, fixedState } = useMemo(() => {
		const existingValue = initialValue || "{}";
		const sharedSchemaDocumentNode = safeParseSdl(sharedSchemaSdl);
		if (!sharedSchemaDocumentNode) return {
			initialValueErrors: [],
			fixedState: null
		};
		const stateTypeName = makeStateSchemaNameForScope(modelName, scope);
		if (!stateTypeName) return {
			initialValueErrors: [],
			fixedState: null
		};
		const stateTypeDefinitionNode = sharedSchemaDocumentNode.definitions.find((def) => def.kind === Kind.OBJECT_TYPE_DEFINITION && def.name.value === stateTypeName);
		if (!stateTypeDefinitionNode || stateTypeDefinitionNode.kind !== Kind.OBJECT_TYPE_DEFINITION) return {
			initialValueErrors: [],
			fixedState: null
		};
		const errors = validateStateObject(sharedSchemaDocumentNode, stateTypeDefinitionNode, existingValue);
		if (errors.length && syncWithSchema) {
			const computedFixedState = makeMinimalObjectForStateType({
				sharedSchemaDocumentNode,
				stateTypeDefinitionNode,
				existingValue
			});
			if (initialValue !== computedFixedState) return {
				initialValueErrors: [],
				fixedState: computedFixedState
			};
		}
		return {
			initialValueErrors: errors,
			fixedState: null
		};
	}, [
		sharedSchemaSdl,
		initialValue,
		syncWithSchema,
		scope,
		modelName
	]);
	useEffect(() => {
		if (fixedState && !hasSyncedRef.current) {
			hasSyncedRef.current = true;
			setInitialState(fixedState, scope);
		} else if (!fixedState) hasSyncedRef.current = false;
	}, [
		fixedState,
		setInitialState,
		scope
	]);
	return /* @__PURE__ */ jsxs("div", {
		className: "grid grid-cols-2 gap-4",
		children: [/* @__PURE__ */ jsxs("div", { children: [
			/* @__PURE__ */ jsxs("h3", {
				className: "mb-2 text-lg capitalize",
				children: [scope, " state schema *"]
			}),
			/* @__PURE__ */ jsxs(Button, {
				onClick: handleToggleStandardLib,
				className: "mb-2 flex w-fit items-center gap-2",
				children: [
					showStandardLib ? "Hide" : "Show",
					" standard library",
					/* @__PURE__ */ jsx("svg", {
						className: cn$1("inline-block transition-transform", showStandardLib ? "rotate-180" : "rotate-0"),
						xmlns: "http://www.w3.org/2000/svg",
						width: "24",
						height: "24",
						viewBox: "0 0 24 24",
						fill: "none",
						children: /* @__PURE__ */ jsx("path", {
							d: "M11.9883 6.01172C11.4363 6.01172 10.9883 6.45972 10.9883 7.01172V13.0117H6.98828L11.9883 18.0117L16.9883 13.0117H12.9883V7.01172C12.9883 6.45972 12.5403 6.01172 11.9883 6.01172Z",
							fill: "black"
						})
					})
				]
			}),
			/* @__PURE__ */ jsxs(Suspense, { children: [
				showStandardLib && /* @__PURE__ */ jsx(GraphqlEditor, {
					doc: typeDefsDoc,
					readonly: true
				}),
				/* @__PURE__ */ jsx(GraphqlEditor, {
					doc: stateSchema,
					updateDocumentInModel: handleSchemaUpdate,
					customLinter
				}),
				schemaErrors.length > 0 && /* @__PURE__ */ jsx("p", {
					className: "mt-2 text-sm text-red-600",
					children: schemaErrors[0].message
				})
			] })
		] }), /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsxs("div", {
			className: "flex flex-col items-end",
			children: [/* @__PURE__ */ jsxs("h3", {
				className: "mb-2 text-right text-lg capitalize",
				children: [scope, " state initial value *"]
			}), /* @__PURE__ */ jsx(Checkbox, {
				value: syncWithSchema,
				onChange: setSyncWithSchema,
				className: "mb-2 w-fit rounded-md border border-gray-200 bg-gray-50 pl-2 text-sm font-medium whitespace-nowrap text-gray-800 transition-colors hover:bg-gray-100 hover:text-gray-900 focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:outline-none",
				label: /* @__PURE__ */ jsxs("div", {
					className: "flex items-center gap-2 py-2 pr-2",
					children: [
						"Sync with schema",
						" ",
						/* @__PURE__ */ jsx("svg", {
							className: "inline-block",
							xmlns: "http://www.w3.org/2000/svg",
							width: "16",
							height: "16",
							viewBox: "0 0 16 16",
							fill: "none",
							children: /* @__PURE__ */ jsx("path", {
								d: "M8.00521 1.99219C6.63588 1.99219 5.32788 2.45152 4.27588 3.28419C3.98721 3.51219 3.94321 3.93285 4.17188 4.22151C4.40054 4.51018 4.82055 4.55418 5.10921 4.32552C5.92721 3.67819 6.93921 3.32552 8.00521 3.32552C10.5825 3.32552 12.6719 5.41485 12.6719 7.99218H11.3385L13.3385 10.6588L15.3385 7.99218H14.0052C14.0052 4.67818 11.3192 1.99219 8.00521 1.99219ZM2.67188 5.32552L0.671875 7.99218H2.00521C2.00521 11.3062 4.69121 13.9922 8.00521 13.9922C9.37521 13.9922 10.6825 13.5335 11.7345 12.7002C12.0232 12.4722 12.0672 12.0515 11.8385 11.7628C11.6099 11.4742 11.1899 11.4302 10.9012 11.6588C10.0825 12.3068 9.07188 12.6588 8.00521 12.6588C5.42788 12.6588 3.33854 10.5695 3.33854 7.99218H4.67188L2.67188 5.32552Z",
								fill: "#343839"
							})
						})
					]
				})
			})]
		}), /* @__PURE__ */ jsxs(Suspense, { children: [/* @__PURE__ */ jsx(JSONEditor, {
			doc: initialValue,
			updateDocumentInModel: handleInitialStateUpdate
		}), initialValueErrors.map((error, index) => /* @__PURE__ */ jsx("p", {
			className: "mt-2 text-sm text-red-600",
			children: error instanceof StateValidationError ? /* @__PURE__ */ jsx(StateValidationErrorMessage, { error }) : error.message
		}, index))] })] })]
	});
}
function StateSchemas({ modelName, globalStateSchema, localStateSchema, globalStateInitialValue, localStateInitialValue, setStateSchema, setInitialState, currentScope, onScopeChange }) {
	const handleAddLocalState = useCallback(() => {
		setStateSchema(makeInitialSchemaDoc(modelName, "local"), "local");
		setInitialState("", "local");
	}, [
		modelName,
		setStateSchema,
		setInitialState
	]);
	return /* @__PURE__ */ jsxs(Tabs, {
		className: "pb-8",
		activationMode: "manual",
		value: currentScope,
		onValueChange: (value) => onScopeChange(value),
		children: [
			/* @__PURE__ */ jsx("div", {
				className: "my-6",
				children: /* @__PURE__ */ jsxs(TabsList, {
					className: "mx-auto flex max-w-sm",
					children: [/* @__PURE__ */ jsx(TabsTrigger, {
						value: "global",
						children: "Global"
					}), /* @__PURE__ */ jsx(TabsTrigger, {
						value: "local",
						children: "Local"
					})]
				})
			}),
			/* @__PURE__ */ jsx(TabsContent, {
				value: "global",
				tabIndex: -1,
				children: /* @__PURE__ */ jsx(StateEditor, {
					modelName,
					stateSchema: globalStateSchema,
					initialValue: globalStateInitialValue,
					setStateSchema,
					setInitialState,
					scope: "global"
				})
			}),
			/* @__PURE__ */ jsx(TabsContent, {
				value: "local",
				tabIndex: -1,
				children: !localStateSchema ? /* @__PURE__ */ jsxs("div", {
					className: "",
					children: [/* @__PURE__ */ jsx("h3", {
						className: "mb-2 text-lg capitalize",
						children: "local state schema *"
					}), /* @__PURE__ */ jsx(Button, {
						onClick: handleAddLocalState,
						children: "Add local state"
					})]
				}) : /* @__PURE__ */ jsx(StateEditor, {
					modelName,
					stateSchema: localStateSchema,
					initialValue: localStateInitialValue,
					setStateSchema,
					setInitialState,
					scope: "local"
				})
			})
		]
	});
}
//#endregion
export { StateSchemas as default };

//# sourceMappingURL=state-schemas-C5NPeV6-.js.map