"use client";
import { jsx as _jsx } from "react/jsx-runtime";
import { SandpackCodeEditor, useActiveCode } from "@codesandbox/sandpack-react";
import { useSetAtom } from "jotai";
import { useEffect } from "react";
import { useTranspileDependencyMatches } from "../hooks/useCodeDependencies.js";
import { useEvaluatedCode } from "../hooks/useTranspiledCode.js";
import { setDependenciesAtom } from "../state/index.js";
export function CodeEditor() {
    const evaluatedCode = useEvaluatedCode();
    const { code } = useActiveCode();
    const dependencies = useTranspileDependencyMatches(evaluatedCode ?? "");
    const setDependenciesAtomValue = useSetAtom(setDependenciesAtom);
    useEffect(() => {
        if (dependencies && Object.keys(dependencies).length > 0) {
            setDependenciesAtomValue(dependencies, code);
        }
    }, [dependencies, code, setDependenciesAtomValue]);
    return _jsx(SandpackCodeEditor, {});
}
//# sourceMappingURL=index.js.map